Difference between revisions of "Initrd for Raid-Boot"

From NAS-Central Buffalo - The Linkstation Wiki
Jump to: navigation, search
(Created page with "If you are going to have Debian and a RAID on your Linkstation, you'll need a initrd for setting up the root filesystem. <span style="color: red">'''This page is work in progres…")
 
m (no longer "work in progress")
 
(3 intermediate revisions by one user not shown)
Line 1: Line 1:
 
If you are going to have Debian and a RAID on your Linkstation, you'll need a initrd for setting up the root filesystem.
 
If you are going to have Debian and a RAID on your Linkstation, you'll need a initrd for setting up the root filesystem.
  
<span style="color: red">'''This page is work in progress'''.</span> While all relevant information is already present, the description is not yet complete. Please have a look here again in a few days.
+
'''Note:''' An ''initrd'' is only required of you have to set up some things to make the system boot, like starting the RAID, loading special modules or starting dm-crypt. If you do not have any of these needs, there is simply no need for an ''initrd'', since the kernel will happily boot from hard disk.
 +
 
 +
== Credits ==
 +
 
 +
Some ideas are taken from [[Debian Lenny on LS-WXL#Create an initrd]].
 +
 
 +
== What you need beforehand ==
 +
 
 +
This guide assumes you already [[Open Stock Firmware LS-VL|opened your box]] and bootstrapped Debian as described in [[Debian Squeeze on 'V' and 'X' Series#Debootstrap]]. You may easily adapt this guide to other directory names or Debian versions. Or you may build the ''initrd'' on another device.
 +
 
 +
== The Guide ==
  
 
Basic steps are:
 
Basic steps are:
 
# Create an empty file and mount it as a filesystem to be able to copy data into
 
# Create an empty file and mount it as a filesystem to be able to copy data into
 
# Into this mounted filesystem
 
# Into this mounted filesystem
## copy the ''linuxrc'' script
+
## copy a prepared ''linuxrc'' script
 
## copy all binaries required by ''linuxrc'' plus the libraries required by the binaries
 
## copy all binaries required by ''linuxrc'' plus the libraries required by the binaries
 
## create all required directories and device nodes required
 
## create all required directories and device nodes required
Line 13: Line 23:
  
 
For that you will
 
For that you will
# Create a text-file/script ''linuxrc.txt''
+
# Create and edit a text-file/script ''linuxrc.txt''
 
# Create a text-file/script ''make-initrd.txt''
 
# Create a text-file/script ''make-initrd.txt''
 
# Copy both files to your LS
 
# Copy both files to your LS
Line 19: Line 29:
 
# Run the script on your LS
 
# Run the script on your LS
  
Requirements:
+
'''Note:''' This Guide will install additional software into your debootstraped environment. Thus you may really want to create ''hddrootfs.buffalo.updated'' (as described in [[Debian_Squeeze_on_'V'_and_'X'_Series#Personalize the deboostrap]]) prior to building the ''initrd''.
* Opened Linkstation
+
 
* chroted Debian installation (debbotstrap on the linkstation)
+
== Detailed description ==
 +
 
 +
# Create a text-file/script ''linuxrc.txt'' with the content shown below
 +
# Uncomment the line ''echo "0x..." > ...'' which matched the device to be used as root
 +
# Create a text-file/script ''make-initrd.txt'' with the content shown below
 +
# Change the ''DEBOOTSTRAP=...'' line at the top to match your debootstraped environment.
 +
# Copy both files to your LS.
 +
# Now log into your LS and continue there.
 +
# Find the place on your LS where you copied the files to:
 +
#: If you used the share "share", this should be either ''/mnt/disk1/share'' or ''/mnt/array1/share''
 +
#: If you used scp, winscp or so, you'll know where :-)
 +
# Run the script on your LS. Assuming you copied the file to ''/mnt/disk1/share'', the command will be
 +
sh /mnt/disk1/share/make-initrd.txt
 +
# The initrd file will be ''initrd.buffalo'' in your debootstraped environment.
  
  
 
=== Required linuxrc.txt ===
 
=== Required linuxrc.txt ===
  
Put this into a textfile called ''linuxrc.txt'':
+
Put this into a text-file called ''linuxrc.txt''. You'll need to uncomment the line matching you root device.
  
 
  #!/bin/busybox sh
 
  #!/bin/busybox sh
  # linuxrc - to be put into the inted
+
  # linuxrc - to be put into the initrd
 
   
 
   
 
  # Mount the /proc and /sys filesystems.
 
  # Mount the /proc and /sys filesystems.
Line 51: Line 74:
 
  umount /proc
 
  umount /proc
 
  umount /sys
 
  umount /sys
 +
  
 
=== File make-initrd.txt ===
 
=== File make-initrd.txt ===
  
Put this into a textfile called ''make-initrd.txt'':
+
Put this into a textfile called ''make-initrd.txt''.
  
  # chroot debian-squeeze
+
  #!/bin/bash
  apt-get install --no-install-recommends busybox uboot-mkimage makedev
+
# Licensed under GPL v3 or later
 +
# make-initrd.txt -- This script will be executed on the LS
 +
 +
# edit this line as needed
 +
DEBOOTSTRAP=/root/debian-squeeze
 +
 +
if [ "$1" != chrooted ] ; then
 +
  if [ ! -d $DEBOOTSTRAP ] ; then
 +
    echo "debootstrap directory not found, please edit DEBOOTSTRAP in $0"
 +
    exit 1
 +
  fi
 +
                 
 +
  DIR=$( cd $(dirname $0) ; pwd)
 +
                       
 +
  cp "$0" "$DIR/linuxrc.txt" $DEBOOTSTRAP
 +
  scriptname=$( basename "$0" )
 +
  # rerun script in chrooted environment
 +
  chroot $DEBOOTSTRAP bash -x "$scriptname" chrooted
 +
  exit $?
 +
fi
 +
                                   
 +
# install some required stuff
 +
  apt-get install --no-install-recommends busybox uboot-mkimage makedev dos2unix
 
   
 
   
 
  cd /tmp
 
  cd /tmp
  rm initrd.gz
+
  [ -f initrd.gz ] && rm initrd.gz
 
   
 
   
 
  dd if=/dev/zero of=initrd bs=1k count=0 seek=3K
 
  dd if=/dev/zero of=initrd bs=1k count=0 seek=3K
Line 70: Line 116:
 
  mkdir -p INITRD/{bin,lib,dev,etc/mdadm,proc,sbin}
 
  mkdir -p INITRD/{bin,lib,dev,etc/mdadm,proc,sbin}
 
  cp -a /dev/{null,console,tty,sd{a,b,c,d}?,md*} INITRD/dev/
 
  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
+
  # ensure sd? and md exits, even if chrooted installation does not have them
 
  cd INITRD/dev/
 
  cd INITRD/dev/
 
  MAKEDEV sda sdb sdc sdd md
 
  MAKEDEV sda sdb sdc sdd md
Line 77: Line 123:
 
  cp -aL /bin/busybox INITRD/bin/
 
  cp -aL /bin/busybox INITRD/bin/
 
  cp -aL /sbin/mdadm /sbin/pivot_root INITRD/sbin
 
  cp -aL /sbin/mdadm /sbin/pivot_root INITRD/sbin
  # todo: find required libs automatically
+
  cp -aL /lib/{libm.so.6,libc.so.6,libgcc_s.so.1,ld-linux.so.3} INITRD/lib
+
  # find required libs and install into INITRD/lib
 +
  libs2install=$( ldd INITRD/*bin/* | grep -v "^INITRD/" | sed -e 's/.*=> *//'  -e 's/ *(.*//' | sort -u )
 +
cp -aL $libs2install INITRD/lib
 
   
 
   
 
  ln -s INITRD/bin/busybox INITRD/bin/sh
 
  ln -s INITRD/bin/busybox INITRD/bin/sh
 
   
 
   
  cp ../linuxrx.txt INITRD/linuxrc
+
  cp ../linuxrc.txt INITRD/linuxrc
 +
dos2unix INITRD/linuxrc
 
  chmod +x INITRD/linuxrc
 
  chmod +x INITRD/linuxrc
 
   
 
   
 
  umount INITRD
 
  umount INITRD
 
  gzip initrd
 
  gzip initrd
  mkimage -A arm -O linux -T ramdisk -C gzip -a 0x0 -e 0x0 -n initrd -d initrd.gz initrd.buffalo
+
  mkimage -A arm -O linux -T ramdisk -C gzip -a 0x0 -e 0x0 -n initrd -d initrd.gz ../initrd.buffalo

Latest revision as of 18:55, 10 May 2011

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

Note: An initrd is only required of you have to set up some things to make the system boot, like starting the RAID, loading special modules or starting dm-crypt. If you do not have any of these needs, there is simply no need for an initrd, since the kernel will happily boot from hard disk.

Contents

Credits

Some ideas are taken from Debian Lenny on LS-WXL#Create an initrd.

What you need beforehand

This guide assumes you already opened your box and bootstrapped Debian as described in Debian Squeeze on 'V' and 'X' Series#Debootstrap. You may easily adapt this guide to other directory names or Debian versions. Or you may build the initrd on another device.

The Guide

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 a prepared 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 and edit 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

Note: This Guide will install additional software into your debootstraped environment. Thus you may really want to create hddrootfs.buffalo.updated (as described in Debian_Squeeze_on_'V'_and_'X'_Series#Personalize the deboostrap) prior to building the initrd.

Detailed description

  1. Create a text-file/script linuxrc.txt with the content shown below
  2. Uncomment the line echo "0x..." > ... which matched the device to be used as root
  3. Create a text-file/script make-initrd.txt with the content shown below
  4. Change the DEBOOTSTRAP=... line at the top to match your debootstraped environment.
  5. Copy both files to your LS.
  6. Now log into your LS and continue there.
  7. Find the place on your LS where you copied the files to:
    If you used the share "share", this should be either /mnt/disk1/share or /mnt/array1/share
    If you used scp, winscp or so, you'll know where :-)
  8. Run the script on your LS. Assuming you copied the file to /mnt/disk1/share, the command will be
sh /mnt/disk1/share/make-initrd.txt
  1. The initrd file will be initrd.buffalo in your debootstraped environment.


Required linuxrc.txt

Put this into a text-file called linuxrc.txt. You'll need to uncomment the line matching you root device.

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

# 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.

#!/bin/bash
# Licensed under GPL v3 or later
# make-initrd.txt -- This script will be executed on the LS

# edit this line as needed
DEBOOTSTRAP=/root/debian-squeeze

if [ "$1" != chrooted ] ; then
  if [ ! -d $DEBOOTSTRAP ] ; then
    echo "debootstrap directory not found, please edit DEBOOTSTRAP in $0"
    exit 1
  fi
                 
  DIR=$( cd $(dirname $0) ; pwd)
                        
  cp "$0" "$DIR/linuxrc.txt" $DEBOOTSTRAP
  scriptname=$( basename "$0" )
  # rerun script in chrooted environment
  chroot $DEBOOTSTRAP bash -x "$scriptname" chrooted
  exit $?
fi
                                   
# install some required stuff
apt-get install --no-install-recommends busybox uboot-mkimage makedev dos2unix

cd /tmp
[ -f initrd.gz ] && 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 does 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

# find required libs and install into INITRD/lib
libs2install=$( ldd INITRD/*bin/* | grep -v "^INITRD/" | sed -e 's/.*=> *//'  -e 's/ *(.*//' | sort -u )
cp -aL $libs2install INITRD/lib

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

cp ../linuxrc.txt INITRD/linuxrc
dos2unix 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