码迷,mamicode.com
首页 > 系统相关 > 详细

Linux系统常用的关机或重启命令shutdown、reboot、halt、poweroff、init 0及init 6的联系与区别

时间:2020-05-28 12:59:22      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:调用   pos   控制台   关机   令行   gui   color   shu   状态   

Linux下常用的关机/重启命令一般包括:

shutdown、reboot、halt、poweroff等,当然了我们可以使用init 运行等级runlevel 0即halt来关机,或使用init 运行等级runlevel 6即reboot来执行重启。

当然了这些关机或重启的方式也有一些细微差别。

首先明确一下linux/redhat系的runlevel运行级别和debian系的runlevel是有所不同的。

redhat系的runlevel定义如下:

runlevel 0: halt 系统停机状态,系统默认运行级别不能设为0,否则不能正常启动

runlevel 1: single user 单用户工作状态,root权限,用于系统维护,禁止远程登陆

runlevel 2: multiuser without network 多用户状态(没有NFS)

runlevel3: multiuser 完全的多用户状态(有NFS),登陆后进入控制台命令行模式

runlevel4: unuse 系统未使用,保留

runlevel5: x11 X11控制台,登陆后进入图形GUI模式

runlevel6: reboot 系统正常关闭并重启,默认运行级别不能设为6,否则不能正常启动

在debian/ubuntu中,runlevel的定义为:

0 - Halt 

1 - Single 

2 - Full multi-user with display manager (GUI) 

3 - Full multi-user with display manager (GUI) 

4 - Full multi-user with display manager (GUI) 

5 - Full multi-user with display manager (GUI) 

6 - Reboot 

可以发现2~5级是没有任何区别的。 

Ubuntu系统默认的运行级别为2。

因此,我们可以使用init 0来执行halt关机,使用init 6来执行reboot。

其实shutdown命令也是在执行完一系列操作后,比如说逐个关闭进程/服务,调用sync将数据写入磁盘等,然后调用init0或init6来执行关机或重启的。

而halt实际上是调用shutdown -h now,可以不理会系统当前状态而直接关机,但在有的系统中,halt不会关闭电源,而只关闭了os。

Linux系统常用的关机或重启命令shutdown、reboot、halt、poweroff、init 0及init 6的联系与区别

标签:调用   pos   控制台   关机   令行   gui   color   shu   状态   

原文地址:https://www.cnblogs.com/timlong/p/12979707.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!