我怎样才能找到linux机器第一次启动的时间?

yan*_*yan 12 linux uptime

当我们使用uptime 时,它只显示我们机器的正常运行时间,因为它从上次打开/关闭/重启开始。

但是,如果我想从机器安装的第一次开始获取机器的启动时间怎么办?

Linux 拥有这些工具吗?或者关于我如何找到答案的任何线索?

Mic*_*ton 21

我最喜欢的与分发无关的技巧之一是检查文件或目录的inode 更改时间,这些文件或目录在服务器的生命周期中极不可能被更改。这些通常是根目录中的目录,例如/lost+found.

比如这个Ubuntu 10.04 LTS系统确实是在2011年2月1日晚上9点40分左右安装的。

# ls -lctr / | head -n 5
total 88
drwxr-xr-x   2 root root  4096 2011-02-01 21:40 selinux
drwxr-xr-x   2 root root  4096 2011-02-01 21:40 opt
drwxr-xr-x   2 root root  4096 2011-02-01 21:40 mnt
drwxr-xr-x   2 root root  4096 2011-02-01 21:40 media
Run Code Online (Sandbox Code Playgroud)

最后,如果您有一个 ext* 根文件系统,那么肯定是正确的答案。查看文件系统元数据,其中包含文件系统的创建时间。例如,此命令显示挂载于 的文件系统的创建时间/

tune2fs -l $(grep " / " /proc/mounts | grep -v rootfs | cut -f 1 -d " ") | grep created
Run Code Online (Sandbox Code Playgroud)


MDM*_*rra 11

如果您使用的是使用 Anaconda 的发行版,则可以查看/root/install.log.


编辑:看来您正在使用 Debian。Debian 将其安装日志放在 /var/log/installer 中。