PXE系列文章(16) - Linux /run 和 /var/run 目录介绍
维基百科 Filesystem Hierarchy Standard 有一段介绍 /run 和 /var/run 目录的说明
Modern Linux distributions include a /run directory as a temporary filesystem (tmpfs) which stores volatile runtime data, following the FHS version 3.0. According to the FHS version 2.3, such data were stored in /var/run but this was a problem in some cases because this directory is not always available at early boot. As a result, these programs have had to resort to trickery, such as using /dev/.udev, /dev/.mdadm, /dev/.systemd or /dev/.mount directories, even though the device directory isn't intended for such data.[23] Among other advantages, this makes the system easier to use normally with the root filesystem mounted read-only. For example, below are the changes Debian made in its 2013 Wheezy release:[24]
/run 目录是一个临时文件系统, 存储是启动以来的信息.当系统重启时,这个目录下的文件应该被删掉或清除.如果你的系统上有/var/run目录,应该让它指向run.
看看我们测试Ubuntu虚拟机的挂载信息:
root@client:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 981M 0 981M 0% /dev
tmpfs 200M 5.3M 195M 3% /run
/dev/sda1 4.3G 1.8G 2.4G 43% /
tmpfs 1000M 0 1000M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1000M 0 1000M 0% /sys/fs/cgroup
/dev/sdb 30G 2.7G 26G 10% /home
tmpfs 200M 0 200M 0% /run/user/0
root@client:~# ll /var/
total 44
drwxr-xr-x 11 root root 4096 Jul 18 19:50 ./
drwxr-xr-x 22 root root 4096 Jul 18 19:52 ../
drwxr-xr-x 2 root root 4096 Jul 22 09:01 backups/
drwxr-xr-x 9 root root 4096 Jul 18 20:13 cache/
drwxr-xr-x 44 root root 4096 Jul 18 20:13 lib/
drwxrwsr-x 2 root staff 4096 Apr 13 2016 local/
lrwxrwxrwx 1 root root 9 Jul 18 19:50 lock -> /run/lock/
drwxrwxr-x 6 root syslog 4096 Jul 19 15:20 log/
drwxrwsr-x 2 root mail 4096 Jul 18 19:50 mail/
drwxr-xr-x 2 root root 4096 Jul 18 19:50 opt/
lrwxrwxrwx 1 root root 4 Jul 18 19:50 run -> /run/
drwxr-xr-x 4 root root 4096 Jul 18 19:51 spool/
drwxrwxrwt 4 root root 4096 Jul 22 09:01 tmp/
维基百科 Filesystem Hierarchy Standard 对我们构建内存镜像非常有用,Debian/Ubuntu系列服务器这部分逻辑, 被 debootstrap
自动完成了,而 Centos
是基于 yum --installroot
命令一步一步的来配置, 所以需要在Centos 内存根文件中手动配置对应目录.
内存镜像按FHS目录布局构建后,需要删除掉临时目录, 比如/proc、/sys、/dev、/run,在 initramfs 需要根据挂载的层次在重新创建, 后续在完整的写一篇内存镜像优化文章。