Adding a file to /etc of initramfs in Debian Wheezy

8,162

You're placing your master-file in the wrong place. You want to use an initramfs hook.

Take a look beneath /usr/share/initramfs-tools/hooks there you'll see examples, but in brief you want to do something like:

  #!/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

Hope that helps.

Remember that hook script must be executable.

UPDATE: Also bear in mind that if your system is booted chances are the initramfs environment has been replaced by your root-filesystem. You should be able to verify what your initramfs image contains via cpio etc though.

Share:
8,162

Related videos on Youtube

Admin
Author by

Admin

Updated on November 25, 2022

Comments

  • Admin
    Admin over 1 year

    I have added the file /etc/initramfs-tools/etc/motd so that it would be available in /etc of the initramfs environment. However, it does not turn up. This is my second try where I gave the file all permissions available (I've also used 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
    

    After that I sudo update-initramfs -u, boot into the initramfs environment and log in through SSH via Dropbear, and the file is still not there:

    ~ # 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
    

    How should I add it? Why didn't the above way work?