How to customize your initrd

The initrd contains all the programs and utilities the kernel needs in order to find the root partition. The initrd is "given" to the kernel by the boot loader (often isolinux on cds, or grub on hard drives).

Installed systems

The initrd used by an installed system is maintained by the mkinitramfs script, which is run automatically when for instance upgrading the kernel or any tool used inside the initrd. The correct and recommended way of modifying this initrd is to make hooks and scripts in the /etc/mkinitramfs directory tree. See /usr/share/initramfs for the scripts and hooks that are included by the system.

Live systems

You might find this information useful if you want to:

  • run the "Desktop" installer from a usb drive instead of from the cd
  • run the "Desktop" live system without using the cd player
  • debug and modify the live installer system
  • avoid burning all these cds
  • avoid using your slow and noisy cd player

The initrd used when booting a live cd ("Desktop CD") can be found in the casper directory of the cd. Below we will suppose you have downloaded an iso-file and mounted it with:  sudo mount -o loop edgy-desktop-i386.iso /mnt . If you otherwise have the burnt the cd inserted it, replace /mnt by /media/cdrom0

Modify the initrd

  1. Extract the contents of the initrd:
    •   mkdir initrd-tmp
        cd initrd-tmp
        gzip -dc /mnt/casper/initrd.gz | cpio -id
      or for Ubuntu 9.10 and later:
        lzma -dc -S .lz /mnt/casper/initrd.lz | cpio -id
  2. Modify the files
  3. Repack them into a new initrd:
    •   find . | cpio --quiet --dereference -o -H newc | gzip -9 > ~/new-initrd.gz
      or, if you want an initrd.lz (for Ubuntu 9.10 and later):
        find . | cpio --quiet --dereference -o -H newc | lzma -7 > ~/new-initrd.lz

You can now remaster a cd with this new initrd.gz replacing the old /casper/initrd.gz.

However, it is easier to put the initrd on one of your drives, and let a bootloader find it. The bootloader used by the Desktop/live cd, isolinux, is not able to look anywhere else than on the cd it is started from, so we will therefore use another boot loader, grub.

Boot using the HD grub loader

Since many of us already have grub installed on the hard drive, this is the easiest solution. You can also boot from a grub cd or grub usb drive, and manually enter the boot parameters.

As an example, we will put the kernel and modified initrd onto your normal linux partition on your hard drive. This can also be a vfat partition or anything else that grub is able to read from.

sudo mkdir /boot-live
sudo cp /mnt/casper/vmlinuz /boot-live
sudo cp ~/new-initrd.gz /boot-live/initrd.gz

You'll also have to modify your grub configuration. Whether you're using Grub 1.x or 2.x, make sure to replace (hd0,1) or (hd0,msdos2) text with the location of your partition where you put the kernel and initrd. Also, for both 1.x and 2.x, the boot parameters are taken from the append line of the isolinux.cfg file from the cd.

For Grub 1.x

Add this to your /boot/grub/menu.lst:

# Live from hard drive
title           Edgy live snapshot
root            (hd0,1)
kernel          /boot-live/vmlinuz boot=casper initrd=initrd.gz ramdisk_size=1048576 root=/dev/ram rw --
initrd          /boot-live/initrd.gz

For Grub 2.x

Add this to your /etc/grub.d/40_custom:

menuentry "Ubuntu LiveCD-on-HD" {
    set root=(hd0,msdos2)
    linux /boot-live/vmlinuz boot=casper initrd=initrd.gz noprompt textonly --
    initrd /boot-live/initrd.gz

You also must run grub-mkconfig -o /boot/grub/grub.cfg after you make your changes.

The live filesystem

Once the kernel has booted, it will continue running the same way as if it had been running from the cd. During the "Mount root file system" step, it will search for the cd contents, or more precisely, the /casper/filesystem.squashfs file. Normally it will search through all cd/dvd drives and usb disks to find the /casper directory.

Live from hard drive

The patch below is not needed in Feisty, since is_usb_device has been replaced by is_nice_device.

If you apply this little patch (casper.all-disks.diff) to scripts/casper in your initrd, it will also look through your hard drives. Note that it any case, it will only look at iso9660, vfat and udf partitions, so your filesystem.squashfs can not reside on your ext2/ext3 partition (unless you hack scripts/casper a little, of course). To apply the patch, include the following in step 2 above.

patch scripts/casper ~/Desktop/casper.all-disks.diff

Now copy the casper directory from the cd over to the root directory of a vfat partition, e.g.

cp -r /mnt/casper /media/my_fat_disk

Note: Don't try to run the live installer program and to install to the same hard drive as you are booting from. Since casper has that disk mounted, the disk detection and partitioning utilities in the normal installation sequence might get upset.

That should be it. Happy booting!

Just remember, when there is a new cd out, to update the new /casper tree as well as the new vmlinuz and your new initrd.gz, and check for any new boot parameters in isolinux.cfg.


This page is basically about getting the Edgy Eft desktop/live installer to run from a USB device. The information here should probably be split and merged with some other Howtos.

CustomizeLiveInitrd (last edited 2012-03-28 22:12:29 by mrled)