3 # This script is used to build a "custom" initrd for mkcdrec
4 # It essentially builds a full Bacula environment, but then
5 # when mkcdrec boots, it will load our initrd instead of the
6 # trimmed down mkcdrec version.
12 LOOP2=/tmp/bacula_rescue_loop2
16 # Assume that everything to be loaded into memory with the
17 # RAM disk image (initrd) is is in the roottree directory.
19 echo "Creating the Initial RAM disk image.... "
21 # first find out how much space we need.
22 ISIZE=`du -s -k roottree/ | awk '{print $1}'`
24 # Make a copy for mkcdrec
26 cp -dpR roottree/ mkcdrectree
29 # Now copy in the mkcdrec files
30 # Note, we use a number of the mkcdrec scripts
32 cp -fp ${MKCDREC}/etc/fstab mkcdrectree/etc
33 # cp -fp ${MKCDREC}/etc/inittab mkcdrectree/etc
34 cp -fp ${MKCDREC}/linuxrc mkcdrectree/
35 mkdir -p mkcdrectree/etc/rc.d
36 cp -fdpR ${MKCDREC}/etc/rc.d/* mkcdrectree/etc/rc.d/
37 touch mkcdrectree/etc/rc.d/rc.inits
38 chmod +x mkcdrectree/etc/rc.d/rc.inits
39 cat >>mkcdrectree/etc/rc.d/rc.local <<EOF
40 # This file is sourced
41 if [ ! -d /etc/recovery ] ; then
43 if [ -d /mnt/cdrom/recovery.tgz ] ; then
44 tar xfz /mnt/cdrom/recovery.tgz
50 ISIZE=`expr $ISIZE + 2048`
51 echo "Initial RAM disk contents will be $ISIZE KB"
53 # delete the existing RAM disk image, if there is one
56 dd if=/dev/zero of=$TOPDIR/root bs=1k count=$ISIZE
58 # cleanup any prior left over stuff
59 umount $LOOP2 2>/dev/null >/dev/null
60 losetup -d /dev/loop2 2>/dev/null >/dev/null
62 # associate it with /dev/loop2
63 losetup /dev/loop2 $TOPDIR/root
65 # make an ext2 filesystem on it. Set reserve to 0
66 mke2fs -q -m 0 /dev/loop2 $ISIZE
73 mount /dev/loop2 $LOOP2
74 # ... and delete the lost+found directory
75 rm -rf $LOOP2/lost+found
77 # then we copy the contents of our roottree to this filesystem
78 cp -dpR mkcdrectree/* $LOOP2/
81 # and unmount and divorce /dev/loop2
86 # If above copy failed, bail out
87 if [ $cprtn != 0 ] ; then
88 echo "RAM disk build failed."
92 # This is a newer way of creating a ramfs, which we don't use
93 # (cd roottree; find . | cpio --quiet -c -o) >root
95 echo "Building initial RAM disk done"
97 # Now we have the image of the RAM disk in $TOPDIR/loopfiles/root. We
98 # compress this one and write the compressed image to the boot tree:
100 echo "Compressing the RAM disk image.... "
102 # and gzip our RAM disk image and put it in the right place.
103 # Bacula gzip -9 -c root >cdtree/boot/isolinux/initrd.img
104 dd if=root bs=1k | bzip2 -v9 > custom-rd.img.bz2
105 if [ $? != 0 ] ; then
111 # we are done with the RAM disk image, delete it
115 echo "Initial RAM disk custom-rd.img.bz2 is built."