將檔案新增至 Debian Wheezy 中 initramfs 的 /etc

將檔案新增至 Debian Wheezy 中 initramfs 的 /etc

我已新增該文件/etc/initramfs-tools/etc/motd,以便它可以在 initramfs 環境的 /etc 中使用。然而,它並沒有出現。這是我第二次嘗試,我向文件授予了所有可用權限(我也使用了 600):

root@cow:~# ls -l /etc/initramfs-tools/etc/
total 8
drwx------ 2 root root 4096 Sep 19 00:57 dropbear
-rwxrwxrwx 1 root root  117 Sep 29 15:32 motd

之後,我sudo update-initramfs -u啟動進入 initramfs 環境並透過 Dropbear 透過 SSH 登錄,但該檔案仍然不存在:

~ # ls -l /etc
total 20
-rw-------    1 root     0             4077 Sep 29 13:44 boottime.kmap.gz
drwx------    2 root     0                0 Sep 29 13:44 dropbear
-rw-r--r--    1 root     0             1991 Sep 29 13:44 ld.so.cache
-rw-r--r--    1 root     0               34 Sep 18 17:24 ld.so.conf
drwxr-xr-x    2 root     0                0 Sep 18 17:25 ld.so.conf.d
drwx------    2 root     0                0 Sep 29 13:44 lvm
drwx------    2 root     0                0 Sep 29 13:44 mdadm
drwx------    2 root     0                0 Sep 29 13:44 modprobe.d
-rw-------    1 root     0               15 Sep 29 13:44 nsswitch.conf
-rw-------    1 root     0               30 Sep 29 13:44 passwd
drwx------    2 root     0                0 Sep 29 13:44 udev

我該如何添加呢?為什麼上​​面的方法不行呢?

答案1

您將主文件放在錯誤的位置。您想使用 initramfs 掛鉤。

看一下下面的/usr/share/initramfs-tools/hooks內容,您會看到範例,但簡而言之,您想要執行以下操作:

  #!/bin/sh

  PREREQ=""

  prereqs()
  {
          echo "$PREREQ"
  }

  case $1 in
  # get pre-requisites
  prereqs)
          prereqs
          exit 0
          ;;
  esac

  . /usr/share/initramfs-tools/hook-functions
  mkdir -p ${DESTDIR}/etc/motd || true
  cp -pnL /etc/motd ${DESTDIR}/etc/motd
  chmod 644 ${DESTDIR}/etc/motd

希望有幫助。

請記住,掛鉤腳本必須是可執行的。

更新:還要記住,如果您的系統啟動,initramfs 環境很可能已被您的根檔案系統取代。不過,您應該能夠透過cpio等方式驗證 initramfs 映像包含的內容。

相關內容