]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/mkcdrec_rd
Add new mkcdrec code
[bacula/rescue] / rescue / linux / cdrom / mkcdrec_rd
1 #!/bin/sh
2 #
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.
7 #
8
9 TOPDIR=`pwd`
10 MKCDREC=../../mkcdrec
11
12 LOOP2=/tmp/bacula_rescue_loop2
13 rm -rf $LOOP2
14 mkdir -p $LOOP2
15
16 # Assume that everything to be loaded into memory with the
17 # RAM disk image (initrd) is is in the roottree directory. 
18
19 echo "Creating the Initial RAM disk image.... "
20
21 # first find out how much space we need. 
22 ISIZE=`du -s -k  roottree/ | awk '{print $1}'`
23
24 # Make a copy for mkcdrec
25 rm -rf mkcdrectree
26 cp -dpR roottree/ mkcdrectree
27
28 #
29 # Now copy in the mkcdrec files
30 #   Note, we use a number of the mkcdrec scripts
31 #
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
42   cd /
43   if [ -d /mnt/cdrom/recovery.tgz ] ; then
44      tar xfz /mnt/cdrom/recovery.tgz
45   fi
46 fi
47 EOF
48
49 # add 2 Meg for extra   
50 ISIZE=`expr $ISIZE + 2048`
51 echo "Initial RAM disk contents will be $ISIZE KB"
52
53 # delete the existing RAM disk image, if there is one
54 rm -f root
55
56 dd if=/dev/zero of=$TOPDIR/root bs=1k count=$ISIZE
57
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
61
62 # associate it with /dev/loop2
63 losetup /dev/loop2 $TOPDIR/root
64
65 # make an ext2 filesystem on it. Set reserve to 0
66 mke2fs -q -m 0 /dev/loop2 $ISIZE
67 if [ $? != 0 ] ; then
68   echo "Build failed."
69   exit 1
70 fi
71
72 # we mount it...
73 mount /dev/loop2 $LOOP2
74 # ... and delete the lost+found directory 
75 rm -rf $LOOP2/lost+found 
76
77 # then we copy the contents of our roottree to this filesystem
78 cp -dpR mkcdrectree/* $LOOP2/
79 cprtn=$?
80
81 # and unmount and divorce /dev/loop2
82 umount $LOOP2
83 losetup -d /dev/loop2 
84 rm -rf $LOOP2
85
86 # If above copy failed, bail out
87 if [ $cprtn != 0 ] ; then
88   echo "RAM disk build failed."
89   exit 1
90 fi
91
92 # This is a newer way of creating a ramfs, which we don't use
93 # (cd roottree; find . | cpio --quiet -c -o) >root
94
95 echo "Building initial RAM disk done"
96
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:
99
100 echo "Compressing the RAM disk image.... "
101
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
106   echo "Build failed"
107   exit 1
108 fi
109
110
111 # we are done with the RAM disk image, delete it
112 rm -f root
113 rm -rf mkcdrectree
114
115 echo "Initial RAM disk custom-rd.img.bz2 is built."