===== 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 [[howto:installrescuemode|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 [[howto:perform_disk_scan#case_1perform_disk_scan_for_the_user_partition_dev_sda2_of_the_unionfs|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 [[guidebooks:basic_linux_commands#su_switch_user_and_sudo_switch_user_do|su]] to change to a root terminal or add [[guidebooks:basic_linux_commands#su_switch_user_and_sudo_switch_user_do|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:**// - //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.// - //If you have not removed [[howto:makechangespermanent#unionfs|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 [[howto:installrescuemode|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 [[howto:installrescuemode|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 [[http://eeepc.fire.prohosting.com/bootusb/puppylinux/bootusb.htm#mknod|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 **[[http://linux.about.com/library/cmd/blcmdl1_ash.htm|ash commands]]** and limited **[[http://www.busybox.net/downloads/BusyBox.html|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:removeunionfs|Remove Unionfs]] * [[http://wiki.eeeuser.com/ram_mode|Installing RAM Mode]] * [[http://wiki.eeeuser.com/xandrosbootfromusb|Boot Xandros from USB]] * [[http://forum.eeeuser.com/viewtopic.php?id=7694|Mount SD as part of the unionfs]] * [[http://forum.eeeuser.com/viewtopic.php?id=39332|Run filesystem check on /dev/sda1]] * [[howto:tweakmountparameters#method_2creating_a_new_ramfs|Tweaking user partition mount parameters]] ------ \\ **Reference:** * Linux kernel Documentation: [[http://www.mjmwired.net/kernel/Documentation/filesystems/ramfs-rootfs-initramfs.txt|ramfs-rootfs-initramfs.txt]] * [[http://lwn.net/Articles/210046/|Embedded Linux: Small Root Filesystems]] * [[http://www.tldp.org/HOWTO/Bootdisk-HOWTO/buildroot.html|The Linux Bootdisk HOWTO: Building a root filesystem]]