initramfs
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| initramfs [2013/06/04 10:08] – paulsmith | initramfs [2013/06/04 10:13] (current) – paulsmith | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== initramfs ====== | ||
| + | |||
| + | ===== 1. Create structure ===== | ||
| + | < | ||
| + | mkdir / | ||
| + | cd / | ||
| + | mkdir -p bin lib dev etc mnt/root proc root sbin sys | ||
| + | </ | ||
| + | |||
| + | ===== 2. Build busybox ===== | ||
| + | < | ||
| + | USE=" | ||
| + | </ | ||
| + | |||
| + | ===== 3. Copy minimal device nodes ===== | ||
| + | < | ||
| + | cp -a / | ||
| + | </ | ||
| + | |||
| + | ===== 4. Create / | ||
| + | < | ||
| + | # | ||
| + | |||
| + | # Mount the /proc and /sys filesystems. | ||
| + | mount -t proc none /proc | ||
| + | mount -t sysfs none /sys | ||
| + | |||
| + | #setup mdev | ||
| + | echo /sbin/mdev > / | ||
| + | /sbin/mdev -s | ||
| + | |||
| + | # Do your stuff here. | ||
| + | echo "This script mounts rootfs and boots it up, nothing more!" | ||
| + | |||
| + | rescue_shell() { | ||
| + | echo " | ||
| + | busybox --install -s | ||
| + | exec /bin/sh | ||
| + | } | ||
| + | |||
| + | uuidlabel_root() { | ||
| + | for cmd in $(cat / | ||
| + | case $cmd in | ||
| + | root=*) | ||
| + | dev=${cmd# | ||
| + | type=${dev%%=*} | ||
| + | if [ $type = " | ||
| + | mount -o ro $(findfs " | ||
| + | else | ||
| + | mount -o ro ${dev} /mnt/root | ||
| + | fi | ||
| + | ;; | ||
| + | esac | ||
| + | done | ||
| + | } | ||
| + | |||
| + | # Mount the root filesystem. | ||
| + | uuidlabel_root || rescue_shell | ||
| + | |||
| + | # Clean up. | ||
| + | umount /proc | ||
| + | umount /sys | ||
| + | |||
| + | # Boot the real thing. | ||
| + | exec switch_root /mnt/root /sbin/init | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | chmod +x / | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== 5. Installing options ===== | ||
| + | ====== 5.1. Built into kernel (my prefered way) ====== | ||
| + | < | ||
| + | cd / | ||
| + | make menuconfig | ||
| + | General setup ---> | ||
| + | [*] Initial RAM filesystem and RAM disk (initramfs/ | ||
| + | (/ | ||
| + | |||
| + | |||
| + | make -j4 && make modules_install | ||
| + | </ | ||
| + | |||
| + | ====== 5.2. Build a initrd for grub ====== | ||
| + | cd / | ||
| + | find . -print0 | cpio --null -ov --format=newc | gzip -9 > / | ||
| + | |||
| + | edit grub < 1.0(add the initrd line): | ||
| + | < | ||
| + | title Gentoo | ||
| + | root (hd0,0) | ||
| + | kernel /kernel64 | ||
| + | initrd / | ||
| + | </ | ||
| + | |||
| + | edit grub > 2 | ||
| + | < | ||
| + | menuentry ' | ||
| + | root=hd0,1 | ||
| + | linux / | ||
| + | initrd | ||
| + | } | ||
| + | |||
| + | </ | ||
