参考 http://www.centoscn.com/CentOS/config/2014/0829/3595.html
重启,grub界面按“e”临时修改grub
- 在grub第一个菜单的最下面有一行是关于kernel的,在最后加上“single init=/bin/bash”,然后ctrl+x启动
- mount可以查看当前是ro的,所以我们需要rw, mount -o remount,rw /
- echo pass | passwd root –stdin, 注意,这个地方不能直接重启,需要touch /.autorelabel, 因为这个是7,不是6,所以需要touch一下这个文件,至于为啥,我暂时不知道
- 可以重启了,不过重启exec /sbin/init或者 exec /sbin/reboot之后,我的虚机都是在有几个键闪动,只得从宿主机直接重置。
重点是 autorelabel。
扩展:
啥叫centos7的autorelabel,
Next time when you will reboot the system, it will relabel the filesystem for SElinux automatically.
This usually occurs when labeling a file system for SELinux for the first time, or when switching between different types of policy, such as changing from the targeted to the strict policy.
参考:
http://serverfault.com/questions/432531/what-does-the-autorelabel-file-do-in-linux
扩展:
centos6 修改密码,无需touch /.autorelabel。
centos 7 如果touch还是不行,可以加上下面的第一行
# genhomedircon
# touch /.autorelabel
# reboot
- 另外,一些资料显示,关闭selinux之后就无需touch那个文件了,据我观察,不行哦。