Dissecting and amending an Ubuntu initrd

March 2009


The LWP is going to run Ubuntu, so when we need a special purpose initial RAMdisk (i.c. for a partitioning script), it makes sense to work from the Ubuntu installer initrd.

  1. Fetch the original ramdisk and unpack it

    Look in the PXELinux configuration file used by the LWP unattended installer for the location of the initrd, and fetch it into a new directory. Take a look at the file, then unzip and unpack it:

    file initrd.gz
    initrd.gz: gzip compressed data, was "initrd", from Unix, last modified: Thu Jun 19 21:28:22 2008, max compression
    gzip -d initrd.gz
    file initrd
    initrd: ASCII cpio archive (SVR4 with no CRC)
    mkdir ramdisk && cd ramdisk
    sudo cpio -idm < ../initrd 
    1
    36329 blocks
    $ ls -trl
    total 20
    drwxr-xr-x  2 root root    6 2008-02-06 17:51 sys
    drwxr-xr-x  2 root root    6 2008-02-06 17:51 proc
    drwxr-xr-x  2 root root    6 2008-02-06 17:51 mnt
    drwxr-xr-x  2 root root    6 2008-02-06 17:51 initrd
    -rwxr-xr-x  1 root root  472 2008-02-06 17:51 init
    drwxr-xr-x  2 root root    6 2008-02-06 17:51 floppy
    drwxr-xr-x  2 root root    6 2008-06-19 21:27 tmp
    drwxr-xr-x  8 root root   71 2009-03-06 10:19 var
    drwxr-xr-x  2 root root 4096 2009-03-06 10:19 sbin
    drwxr-xr-x 12 root root 4096 2009-03-06 10:19 lib
    drwxr-xr-x  2 root root 4096 2009-03-06 10:19 bin
    drwxr-xr-x  6 root root   49 2009-03-06 10:19 usr
    drwxr-xr-x 14 root root 4096 2009-03-06 10:19 etc
    drwxr-xr-x  2 root root   31 2009-03-06 10:19 dev

    1

    sudo is needed here to create the device files that are inside the usual initrd. Their presence also makes it dangerous to open all files inside the ramdisk...

  2. Amend the RAMdisk

    Copy whatever you need in the RAMdisk into the unpacked directory tree:

    cp /tmp/mkdosfs ./sbin
    cd sbin
    ln -s mkdosfs mkfs.msdos

    [Warning]Warning

    If you copy binaries, either bring along the libraries they need, or make sure they are statically linked! As for how to do that, see e.g. .

    To run a script, I created a parasite script in lib/debian-installer.d/S57repartition:

    #/bin/sh
    anna-install parted-udeb
    wget -P /tmp http://osis.service.rug.nl/pub/jb/partitioner.sh
    sh /tmp/partitioner.sh -x
    reboot
    	

  3. Re-archive and recompress the ramdisk:

    find ./ |sudo cpio -H newc -ov > ../initrd
    <snip>
    gzip -9 ../initrd