Initrd for Raid-Boot

From NAS-Central Buffalo - The Linkstation Wiki
Revision as of 12:20, 6 May 2011 by Lsuser1985 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

If you are going to have Debian and a RAID on your Linkstation, you'll need a initrd for setting up the root filesystem.

This page is work in progress. While all relevant information is already present, the description is not yet complete. Please have a look here again in a few days.

Basic steps are:

  1. Create an empty file and mount it as a filesystem to be able to copy data into
  2. Into this mounted filesystem
    1. copy the linuxrc script
    2. copy all binaries required by linuxrc plus the libraries required by the binaries
    3. create all required directories and device nodes required
  3. unmount the filesystem-file
  4. compress the file and make an initrd out of

For that you will

  1. Create a text-file/script linuxrc.txt
  2. Create a text-file/script make-initrd.txt
  3. Copy both files to your LS
  4. Fix the line endings
  5. Run the script on your LS


  • Opened Linkstation
  • chroted Debian installation (debbotstrap on the linkstation)

Required linuxrc.txt

Put this into a textfile called linuxrc.txt:

#!/bin/busybox sh
# linuxrc - to be put into the inted

# Mount the /proc and /sys filesystems.
mount -t proc none /proc
mount -t sysfs none /sys

echo 'DEVICE /dev/sd??*' > /etc/mdadm/mdadm.conf
mdadm -Eb /dev/sd??* >> /etc/mdadm/mdadm.conf
mdadm -As --force

# use /dev/md1 as root
echo "0x901" > /proc/sys/kernel/real-root-dev
# use /dev/md2 as root
#echo "0x902" > /proc/sys/kernel/real-root-dev
# use /dev/sda6 as root
# echo "0x806" > /proc/sys/kernel/real-root-dev
# use /dev/sdb6 as root
# echo "0x822" > /proc/sys/kernel/real-root-dev

# Clean up.
umount /proc
umount /sys

File make-initrd.txt

Put this into a textfile called make-initrd.txt:

# chroot debian-squeeze
apt-get install --no-install-recommends busybox uboot-mkimage makedev

cd /tmp
rm initrd.gz

dd if=/dev/zero of=initrd bs=1k count=0 seek=3K
mke2fs -F -m 0 -b 1024 initrd
tune2fs -c0 -i0 initrd
mkdir INITRD
mount -o loop initrd INITRD

mkdir -p INITRD/{bin,lib,dev,etc/mdadm,proc,sbin}
cp -a /dev/{null,console,tty,sd{a,b,c,d}?,md*} INITRD/dev/
# ensure sd? and md exits, even if chrooted installation doe not have them
cd INITRD/dev/
MAKEDEV sda sdb sdc sdd md
cd -

cp -aL /bin/busybox INITRD/bin/
cp -aL /sbin/mdadm /sbin/pivot_root INITRD/sbin
# todo: find required libs automatically
cp -aL /lib/{,,,} INITRD/lib

ln -s INITRD/bin/busybox INITRD/bin/sh

cp ../linuxrx.txt INITRD/linuxrc
chmod +x INITRD/linuxrc

umount INITRD
gzip initrd
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x0 -e 0x0 -n initrd -d initrd.gz initrd.buffalo