2 ##############################################
3 # Script for Secure Linux Project #
4 # Copyright(c) 2005, 2006 by Roland Haeder #
5 ##############################################
6 # Purpose: Create initrd-image #
7 ##############################################
8 # This software is licensed under the GNU #
9 # General Public License Version 2 or either #
10 # and comes with ABSOLUTELY NO WARRANTY #
11 # neither implied nor explicit. #
12 ##############################################
14 . ./.settings.sh || exit 3
16 if test -e $MULTI_KEY; then
17 echo "$0: Keyfile found."
19 echo "$0: Keyfile not found! Run gen.sh first."
23 if ! test -e $BOOT_MOUNT; then
24 echo "$0: Please run asset.sh first!"
28 echo "$0: Stage 1 - Unmounting old devices ..."
30 losetup -d $INITRD_LOOP
32 mount $BOOT_DEVICE $BOOT_MOUNT
33 echo "$0: Stage 2 - done."
35 if ! test -e $BOOT_MOUNT/initrd && ! test -e $BOOT_MOUNT/initrd.gz; then
36 echo "$0: Stage 2 - Setting up initrd with e2fs ..."
37 head -c 8m /dev/zero > $BOOT_MOUNT/initrd
38 mke2fs -F -m0 -b 1024 -L "SLP 0.4a" $VERBOSE $BOOT_MOUNT/initrd
39 mkdir $VERBOSE $BASEDIR/initrd
41 echo "$0: Stage 2 - done."
43 if test -e $BOOT_MOINT/initrd.gz; then
44 echo "$0: Stage 2 - Uncompressing initrd.gz ..."
46 echo "$0: Stage 2 - done."
48 echo "$0: Stage 2 - skipped (me2fs)."
52 echo "$0: Stage 3 - Setting up loop-device ..."
53 losetup $INITRD_LOOP $BOOT_MOUNT/initrd
54 echo "$0: Stage 3 - done."
56 if test "$CHK_LOOP" == "1"; then
57 echo "$0: Stage 4 - Checking fs on initrd ..."
58 e2fsck -pv $INITRD_LOOP
59 echo "$0: Stage 4 - done"
61 echo "$0: Stage 4 - skipped (e2fsck)."
64 echo "$0: Stage 5 - Initializing initrd & copy process ..."
65 mkdir $VERBOSE $BASEDIR/initrd
66 mount $INITRD_LOOP $BASEDIR/initrd
67 cp $VERBOSE $BASEDIR/.stick_seed $BASEDIR/initrd/.seed
69 echo "$0: Stage 5 - done."
71 echo "$0: Stage 6 - Creating directories ..."
72 mkdir $VERBOSE -p {bin,dev,lib,$MNT/{$KEYS_DIR,new-root,boot,stick,stick2},usr/{bin,sbin,lib},proc,sbin} || exit 2
73 echo "$0: Stage 6 - done."
75 echo "$0: Stage 7 - Copying device files ..."
76 cp $VERBOSE $UPDATE -a /dev/{console,hd{a*,b*,c*,d*},tty,null,sda,urandom,md?} dev || exit 2
77 echo "$0: Stage 7 - done."
79 echo "$0: Stage 8 - Copying programs ..."
80 cp $VERBOSE $UPDATE `which mount sh umount cat sleep sync dd uname grep sed mknod ln ls` /sbin/{modprobe*,depmod*} bin || exit 2
81 cp $VERBOSE $UPDATE `which losetup pivot_root insmod insmod.modutils mkswap swapon swapoff mdadm mdrun fsck fsck.ext2 fsck.ext2 mdrun mdadmin` sbin || exit 2
82 cp $VERBOSE $UPDATE `which chroot` usr/sbin || exit 2
83 cp $VERBOSE $UPDATE `which test md5sum cut gpg tail uuencode` usr/bin || exit 2
84 echo "$0: Stage 8 - done."
86 echo "$0: Stage 9 - Copying libraries ..."
87 cp $VERBOSE $UPDATE -a /lib/lib{usb-0.1.so.4*,readline.so.5*,bz2.so*,resolv*,uuid.so.1*,ncurses.so.2.5.4,ld-2.3.6.so,c-2.3.6.so,c.so.6,blkid.so.1*,selinux.so.1,sepol.so.1,m-2.3.2.so,m.so.6,rt*,ext2fs.so.2*,pthread*,acl.so.1*,attr.so.1*,se*} lib || exit 2
88 cp $VERBOSE $UPDATE -a /usr/lib{libz.so*} usr/lib || exit 2
89 cp $VERBOSE $UPDATE -a /lib/ lib/ || exit 2
90 echo "$0: Stage 9 - done."
93 echo "$0: Stage 10 - Copying SLP scripts and stick-secret.gpg ..."
94 cp $VERBOSE $UPDATE $BASEDIR/setup/keys/stick-secret.gpg $BASEDIR/{source/{decrypt.sh,linuxrc,swap.sh},.local.sh} $BASEDIR/initrd || exit 2
95 mkdir --parents --$VERBOSE $BASEDIR/initrd/lib/modules/$KERN_VER/ || exit 2
96 cp $VERBOSE $UPDATE $BASEDIR/source/lib/modules/$KERN_VER/loop.* $BASEDIR/initrd/lib/modules/$KERN_VER/ || exit 2
97 echo "$0: Stage 10 - done."
99 # Prepare directories for gpg
100 echo "$0: Stage 11 - Preparing .gnupg ..."
101 mkdir --parents $VERBOSE $BASEDIR/initrd/root/.gnupg
102 echo "$0: Stage 11 - done."
104 # Create lots of loop-back devices (we need loop-aes compiled with "max_loop = 8" here!)
105 echo "$0: Stage 12 - Creating loop-devices ..."
106 for idx in `seq 0 16`; do
107 if ! test -e "dev/loop$idx"; then
108 mknod --mode=660 "dev/loop$idx" b 7 $idx
111 echo "$0: Stage 12 - done."
113 echo "$0: Stage 13 - Setting symbolic links ..."
115 ln $VERBOSE -sf ld-2.3.6.so ld-linux.so.2 || exit 2
116 ln $VERBOSE -sf libdl-2.3.6 libdl.so.2 || exit 2
117 ln $VERBOSE -sf libncurses.so.2.5.4 libncurses.so.5 || exit 2
119 ln $VERBOSE -sf /linuxrc init
121 # To prevent filling up the initrd while development
122 ln $VERBOSE -sf /dev/null .bash_history || exit 2
124 ln $VERBOSE -sf sh bash || exit 2
126 echo "$0: Stage 13 - done."
128 if test -e "/boot/vmlinuz-$KERN_VER"; then
129 if test -e "/boot/System.map-$KERN_VER"; then
130 echo "$0: Stage 14 - Copying kernel/System.map ..."
132 cp $VERBOSE $UPDATE "/boot/vmlinuz-$KERN_VER" "/boot/System.map-$KERN_VER" $BOOT_MOUNT/ || exit 2
133 echo "$0: Stage 14 - done."
135 echo "$0: Stage 14 - No System.map found for version $KERN_VER."
138 echo "$0: Stage 14 -No kernel found for version $KERN_VER."
141 if test "$KERN_FOUND" == "0"; then
142 if test -e "/usr/src/linux-$KERN_VER"; then
143 cd "/usr/src/linux-$KERN_VER"
145 if test -e .config; then
146 # Build kernel and modules and install them
147 make dep bzImage modules modules_install || exit 1
148 # Copy kernel/System.map to initrd
149 echo "$0: Stage 14 - Copying compiled kernel/System.amp ..."
150 cp $VERBOSE System.map $BOOT_MOUNT/System.map-$KERN_VER || exit 2
151 cp $VERBOSE arch/i386/boot/bzImage $BOOT_MOUNT/vmlinuz-$KERN_VER || exit 2
152 echo "$0: Stage 14 - done."
154 echo "FAILED: Compilation of kernel v$KERN_VER"
158 echo "FAILED: Cannot find build-directory /usr/src/linux-$KERN_VER!"
163 # Copy RAID modules to initrd
164 echo "$0: Stage 15 - Copying kernel modules ..."
165 cp $VERBOSE --parents /lib/modules/$KERN_VER/kernel/drivers/md/{raid5,xor,md}.* $BASEDIR/initrd/ || exit 2
166 if test -e "/usr/src/modules/loop-aes/"; then
167 # Install loop-aes module
168 cd /usr/src/modules/loop-aes/
169 # Build loop-aes and install it
170 make clean all install || exit 1
171 # Generate path on initrd
172 mkdir $VERBOSE $BASEDIR/initrd/lib/modules/$KERN_BER/{kernel/block,block} || exit 2
173 if test -e "loop.ko"; then
174 # Kernel version >= 2.6.*
175 cp loop.ko $BASEDIR/initrd/lib/modules/$KERN_BER/block/ || exit 2
177 # Kernel version <= 2.4.*
178 cp loop.o $BASEDIR/initrd/lib/modules/$KERN_BER/block/ || exit 2
182 cp $VERBOSE --parents /lib/modules/$KERN_VER/kernel/driversblock/loop.o $BASEDIR/initrd || exit 2
185 echo "$0: Stage 15 - done."
187 if test "$UMOUNT_INITRD" == "1"; then
188 echo "$0: Removing initrd and loop ..."
191 losetup -d $INITRD_LOOP
197 echo "You may want to execute cpio.sh to copy all your data to the encrypted"
198 echo "disk in $BASEDIR/root."