On Wed, 26 Dec 2012 07:58:34 -0800, Mark Knecht wrote: > OK, it's the day after Christmas and this little kid wants to play > with the new toys Uncle Neil gave us yesterday - a copy of his well > worn setup file for building an initramfs into the kernel - a copy of > which I place here: > > [QUOTE] > > This is the file I use on a system that has / on a LUKS filesystem on > top of LVM. The format is documented in the kernel docs at > Documentation/filesystems/ramfs-rootfs-initramfs.txt > > > dir /bin 755 0 0 > file /bin/busybox /bin/busybox 755 0 0 > slink /bin/sh busybox 777 0 0 > > dir /realroot 755 0 0 > dir /etc 755 0 0 > dir /proc 755 0 0 > dir /sys 755 0 0 > > dir /sbin 755 0 0 > file /sbin/lvm.static /sbin/lvm.static 755 0 0 > #file /sbin/mdadm /sbin/mdadm 755 0 0 > file /sbin/cryptsetup /sbin/cryptsetup 755 0 0 > > file /sbin/e2fsck /sbin/e2fsck 755 0 0 > dir /lib 755 0 0 > file /lib/libext2fs.so /usr/lib64/libext2fs.so 755 0 0 > > dir /dev 755 0 0 > nod /dev/console 600 0 0 c 5 1 > nod /dev/null 666 0 0 c 1 3 > nod /dev/tty 666 0 0 c 5 0 > nod /dev/urandom 666 0 0 c 1 9 > > file /init /usr/src/init.sh 755 0 0 > > [/QUOTE] > > > OK, so reading through this it seems moderately straight forward. My > reading: > > a) Create some directories > b) Populate them with some executables > c) Make some nodes > d) Execute a script > > > I do have a few questions: > > 1) dir /realroot 755 0 0 > > Is this something required to make the machine boot? Or is it possibly > a mount point in case of problems and just used inside the initramfs > if trouble arises? Something else? Google didn't point me toward > anything meaningful.
It's where init.sh mounts the real root filesystem before running switchroot. > 2) Contained executables, as I understand them, either need to be > built with the static flag or you have to include all the libraries. > Static seems simpler so (in my case) should I rebuild mdadm & > e2fsprogs with +static? (I don't currently use lvm or any crypt stuff) Yes. > 3) My system uses RAID today. Is there any significant risk in > rebuilding mdadm with static support, rebooting the existing kernel > without an initramfs and then mdadm having trouble? Static mdadm has given me no problems whatsoever, I guarantee that you will have no fewer problems than me :) > 4) What's in /usr/src/init.sh ? From the Gentoo initramfs wiki I find > this as an example: I use one based on the wiki example #!/bin/busybox sh rescue_shell() { busybox --install -s echo $1 exec /bin/sh } ### Mount the /proc and /sys filesystems. mount -t proc none /proc grep -q initdebug </proc/cmdline && set -x && DEBUG=1 mount -t sysfs none /sys mount -t devtmpfs none /dev ### Get root and init parameters from cmdline REAL_ROOT="$(sed 's/.*root=\(\S*\).*/\1/' <proc/cmdline)" if grep -q init= </proc/cmdline; then REAL_INIT="$(sed 's/.*init=\(\S*\).*/\1/' <proc/cmdline)" else REAL_INIT="/sbin/init" fi ### Assemble RAID [[ -f /sbin/mdadm ]] && mdadm --assemble --scan ### Initialise LVM if [[ -f /sbin/lvm.static ]]; then lvm.static vgchange -a y lvm.static vgscan --mknodes [[ -n "$DEBUG" ]] && sleep 10 fi ### Mount the root filesystem. if [[ -f /sbin/cryptsetup ]] && cryptsetup isLuks $REAL_ROOT; then busybox echo -e "\e[0;32m\n=====================\nEncrypted root device\n=====================\n\e[m" cryptsetup luksOpen $REAL_ROOT cryptroot REAL_ROOT="/dev/mapper/cryptroot" [[ -n "$DEBUG" ]] && echo $REAL_ROOT && sleep 10 fi mount -o ro $REAL_ROOT /realroot || rescue_shell "Could not mount REAL_ROOT" [[ -n "$DEBUG" ]] && df -h /realroot && sleep 10 ### Mount /usr if separate if grep -qE '^[^#].*\s\/usr\s' /realroot/etc/fstab; then #mount $(awk '/\s\/usr\s/ {print $1, "/realroot"$2, "-t", $3, "-o", $4 ",ro"}' /realroot/etc/fstab) mount $(awk '/^[^#].*\s\/usr\s/ {print $1, "/realroot"$2, "-t", $3, "-o", $4 ",ro"}' /realroot/etc/fstab) [[ -n "$DEBUG" ]] && df -h /realroot//usr && sleep 10 fi grep -q waitforkey </proc/cmdline && WAITFORKEY=1 grep -q rescue </proc/cmdline && rescue_shell "...because you asked for it." ### Clean up. umount /dev umount /sys umount /proc ### Boot the real thing [[ -n "$DEBUG" ]] && echo "Ready to switch" && sleep 10 [[ -n "$WAITFORKEY" ]] && busybox showkey -a exec busybox switch_root /realroot $REAL_INIT || rescue_shell "Failed to switch_root" Most of it is debug stuff that I haven't used since I first started using it. -- Neil Bothwick For security reasons, all text in this mail is double-rot13 encrypted.
signature.asc
Description: PGP signature