解释上次重启输出

neu*_*ert 9 linux reboot

根据标题为“Linux 找出上次系统重启时间和日期命令”的网页,我可以last reboot | head -1查看系统上次重启的时间。我得到的输出看起来类似于他们提供的输出:

reboot   system boot  3.13.0-116-gener Thu Apr 13 14:12 - 20:09  (05:56)
Run Code Online (Sandbox Code Playgroud)

我的问题是这14:12 - 20:09部分是什么意思?这是否意味着系统在下午 2:12 开始重新启动过程并在晚上 8:09 结束?因为这对我来说似乎不太可能。

Gia*_*968 6

运行last reboot -F,输出应该更清晰。该-F选项意味着:

打印完整的登录和注销时间和日期。

所以这些值显示了重新启动之间的时间跨度。


Chi*_*aba 5

这意味着系统在 启动14:12并在 关闭20:09,总正常运行时间为5:56


长话短说

在它是最新条目的情况下,如问题中所示| head -1,关闭时间是当前系统时间,而正常运行时间反映了系统当前运行的时间。日志中的所有剩余行,显示您是否不使用head限制输出,显示系统从给定日期和时间开始的实际关闭时间和正常运行时间。

例如,在我的系统上last reboot | head -6给出:

reboot   system boot  4.4.46-11-defaul Mon Apr 10 19:58 - 04:00 (5+08:00)
reboot   system boot  4.4.46-11-defaul Sat Apr  8 17:22 - 08:19 (1+14:56)
reboot   system boot  4.4.46-11-defaul Sat Apr  8 00:15 - 11:06  (10:51)
reboot   system boot  4.4.46-11-defaul Thu Apr  6 18:46 - 00:04 (1+05:18)
reboot   system boot  4.4.46-11-defaul Wed Apr  5 17:43 - 11:30  (17:46)
reboot   system boot  4.4.46-11-defaul Tue Apr  4 21:36 - 09:36  (12:00)
Run Code Online (Sandbox Code Playgroud)

这转化为以下序列,颠倒顺序:

    Booted     Shut Down    System up for 
------------  ------------  -------------
Apr  4 21:36  Apr  5 09:36          12:00
Apr  5 17:43  Apr  6 11:30          17:46
Apr  6 18:46  Apr  8 00:04    1 day 05:18
Apr  8 00:15  Apr  8 11:06          10:51
Apr  8 17:22  Apr 10 08:19    1 day 14:56
Apr 10 19:58  Still running  5 days 08:00 (so far)
Run Code Online (Sandbox Code Playgroud)

第一行是最近一次启动,直到系统实际关闭时才会确定其关闭时间。相反,每次运行命令时它都会显示当前时间last reboot

所以你是正确的,重启过程不可能在下午 2:12 开始并在晚上 8:09 结束。如果这是真的,那么是时候对您的系统进行一些认真的工作了!重新启动过程花费的时间并未反映在该输出中,而是反映了系统自启动以来已运行的时间。该last命令不直接提供该信息。不过,它确实提供了一些条目,可以帮助您大致了解该过程需要多长时间。

为此,您需要包含-x将系统runlevelshutdown条目添加到输出的选项。要过滤输出,请查找reboot伪用户和runlevel伪用户。要向last报告的时间添加秒数,请使用该-F选项,该选项将时间条目扩展为完整的日期和时间,包括秒数。此外,每个引导过程将有两个条目,而不是一个,因此您需要将传递给命令的数字加倍head;如果我想要最后 6 次重新启动,如上所述,我需要使用-12这一次。

执行last -xF reboot runlevel | head -12给出:

runlevel (to lvl 5)   4.4.46-11-defaul Mon Apr 10 19:59:57 2017 - Sun Apr 16 04:00:28 2017 (5+08:00)   
reboot   system boot  4.4.46-11-defaul Mon Apr 10 19:58:40 2017 - Sun Apr 16 04:00:28 2017 (5+08:01)   
runlevel (to lvl 5)   4.4.46-11-defaul Sat Apr  8 17:23:57 2017 - Mon Apr 10 08:19:12 2017 (1+14:55)   
reboot   system boot  4.4.46-11-defaul Sat Apr  8 17:22:39 2017 - Mon Apr 10 08:19:12 2017 (1+14:56)   
runlevel (to lvl 5)   4.4.46-11-defaul Sat Apr  8 00:16:16 2017 - Sat Apr  8 11:06:55 2017  (10:50)    
reboot   system boot  4.4.46-11-defaul Sat Apr  8 00:15:02 2017 - Sat Apr  8 11:06:55 2017  (10:51)    
runlevel (to lvl 5)   4.4.46-11-defaul Thu Apr  6 18:47:55 2017 - Sat Apr  8 00:04:46 2017 (1+05:16)   
reboot   system boot  4.4.46-11-defaul Thu Apr  6 18:46:43 2017 - Sat Apr  8 00:04:46 2017 (1+05:18)   
runlevel (to lvl 5)   4.4.46-11-defaul Wed Apr  5 17:44:46 2017 - Thu Apr  6 11:30:26 2017  (17:45)    
reboot   system boot  4.4.46-11-defaul Wed Apr  5 17:43:40 2017 - Thu Apr  6 11:30:26 2017  (17:46)    
runlevel (to lvl 5)   4.4.46-11-defaul Tue Apr  4 21:37:25 2017 - Wed Apr  5 09:36:34 2017  (11:59)    
reboot   system boot  4.4.46-11-defaul Tue Apr  4 21:36:13 2017 - Wed Apr  5 09:36:34 2017  (12:00)    
Run Code Online (Sandbox Code Playgroud)

通过从每次重新启动过程中系统达到运行级别 5 的时间减去重新启动时间,我得到的平均时间接近 1 分 15 秒。请记住,这不是开机到运行级别 5 重新启动所需的时间。而是 Linux 在获得系统控制权后达到运行级别 5 所需的时间。其中不包括 POST 和 BIOS 检查的时间。要找到时间,您需要一个与系统时间完全匹配的时钟,并记录按下电源按钮的时间,并将其与 中报告的启动过程开始时间进行比较last。区别在于计算机需要多长时间才能将控制权传递给 Linux。


我承认我不知道启动过程中的哪个点对应于记录的时间。我可能是在引导加载程序(可能是 GRUB)启动时,或者可能是在 GRUB 调用加载内核时,甚至是在加载内核并开始加载其他所有内容时。我的猜测表明这是 GRUB 被调用的时候。我的 GRUB 菜单有一个短暂的延迟,因为我几乎总是启动到同一个系统,并且如果我启动到其他任何系统,我会等待它。尽管如此,我仍然经常等待 GRUB 加载,并且通常会Enter在延迟到期之前按下。这可以解释从启动到运行级别 5 的最短时间和最长时间之间有 6 秒的变化。当然,这只是的猜测。