Linux Programmer | RHCE | RHCSA

Search This Blog

Wednesday, 28 December 2016

customize initrd in ubuntu

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

2 comments:

SSH not working with password after upgrade ubuntu 22.04 or above

In recent upgrade of ubuntu 22.04 and above we are not able to login server with SSH password. but when we try to login with key then it all...