User Tools

Site Tools


howto:rebuildinitramfs

Rebuilding initramfs (Initial RAM filesystem) of EeePC

What is Initramfs?

The EeePC Linux use a two-stage boot process: The GRUB bootloader first loads the kernel (built with the most common drivers), then extracts the initramfs archive and mounts it as an initial RAM-based root filesystem. This allows loading of additional modules, e.g. USB drivers, and other initialization steps like F9 restore and Perform Disk Scan.

The loading of the kernel and initramfs image are specified in the following lines in /boot/grub/menu.lst:

kernel /boot/vmlinuz-2.6.21.4-eeepc quiet rw vga=785 irqpoll root=/dev/sda1
initrd /boot/initramfs-eeepc.img

If an initramfs is built into the kernel or passed to it, the kernel will try to execute the init script in the initramfs. Usually /init is a shell script that will find and mount the root partition, then switch_root onto the root partiton and execute /sbin/init.

What does initramfs do in EeePC?

In EeePC Linux, the default initramfs image as specified in /boot/grub/menu.lst is /boot/initramfs-eeepc.img. The init script of the default initramfs does the followings:

  • Get kernel parameters from GRUB bootloader
  • If kernel parameter XANDROSBOOTDEBUG is specified, run rescue mode
  • Mount /dev/sda1 as the SYSTEM partition in /mnt-system
  • If kernel parameter XANDROSSCAN is specified, switch_root to the SYSTEM partition and perform disk scan
  • If kernel parameter XANDROSRESTORE is specified, switch_root to the SYSTEM partition and format the USER partition (Restore Factory Settings)
  • If kernel parameter “nosplash” is specified, boot the system without the splash screen
  • Mount /dev/sda2 as the USER partition in /mnt-user
  • Mount the union of the SYSTEM and USER partition in /mnt as the root filesystem (unionfs)
  • If kernel parameter INIT=xxx is specified, switch_root to the root filesystem and execute xxx, e.g. INIT=/sbin/init, then run /sbin/init
  • Else, switch_root to the root filesystem and execute /sbin/fastinit

Steps to Modify initramfs

[NB. All these operations have to be done with “root” privilege. You can either su to change to a root terminal or add sudo before every command]

  • The initramfs is a gzipped “cpio” format archive. To modify it, first extract it back into its component files into a temporary folder. For example, we can create a folder “temp” in /boot:
mkdir /boot/temp      # make temp directory to unpack the initramfs
cd /boot/temp         # enter temp directory
gunzip < ../initramfs-eeepc.img | cpio -i      # unpack the image
  • MAKE THE CHANGES
  • Repack it with this command:
find | cpio -H newc -o | gzip -9 > ../initramfs-[new name]-eeepc.img

Note:

  1. If you pack the initramfs image to a new name, you will also need to edit /boot/grub/menu.lst to tell the GRUB bootloader to use the new image instead of the old one.
  2. If you have not removed unionfs, GRUB menu.lst and initramfs-eeepc.img are in the SYSTEM partition which is mounted READ ONLY. The files you have modified reside in the USER partition which is not loaded at bootup. You will have to boot into rescue mode to move the files from the USER partition to the SYSTEM partition to implement the change. Run these commands after you have booted into rescue mode:
#mount SYSTEM and USER partitions
mount /dev/sda1 /mnt-system
mount /dev/sda2 /mnt-user
#backup original initramfs image and copy new one to /boot in SYSTEM partition
cd /mnt-system/boot
mv initramfs-eeepc.img initramfs-eeepc.img.orig
cp /mnt-user/boot/initramfs-[new name]-eeepc.img .
#backup original GRUB menu.lst and copy new one to /boot/grub in SYSTEM partition
cd grub
mv menu.lst menu.lst.orig
cp /mnt-user/boot/grub/menu.lst .
#umount all partitions
cd /
umount -a
#then wait at least 8 sec before you reboot

Example: Load USB Modules at bootup

To support USB storage devices at bootup, the following changes need to be made to initramfs:

  • Copy USB kernel modules usbcore.ko, ehci-hcd.ko, uhci-hcd.ko, libusual.ko and usb-storage.ko from /lib/modules/2.6.21.4-eeepc/kernel/drivers/usb to /modules of initramfs
  • Creating additional devices with the mknod command, e.g. /dev/sdb1 and /dev/sdc1 for internal SD in 701 series and 90x/1000 series respectively
mknod -m 644 sdb1 b 8 17
mknod -m 644 sdc1 b 8 33
  • Edit /init, add command lines to load USB modules in this order:
insmod -f /modules/usbcore.ko
insmod -f /modules/ehci-hcd.ko
insmod -f /modules/uhci-hcd.ko
insmod -f /modules/libusual.ko
insmod -f /modules/usb-storage.ko

[NB. Please note that the initramfs of EeePC only support ash commands and limited BusyBox commands including: [ cat cp cut dd dmesg echo env expr false grep insmod ln losetup ls mdev mkdir mknod mount mv pivot_root realpath rm rmmod sed sh sleep switch_root test true umount vi ]

Common Hacks of initramfs for EeePC

howto/rebuildinitramfs.txt · Last modified: 2012/01/27 19:59 by hello