]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/makeinitrd
Create /dev/loop2 if it doesn't exist
[bacula/rescue] / rescue / linux / cdrom / makeinitrd
1 #!/bin/sh
2
3 TOPDIR=`pwd`
4
5 LOOP2=/tmp/bacula_rescue_loop2
6 rm -rf $LOOP2
7 mkdir -p $LOOP2
8
9 # Assume that everything to be loaded into memory with the
10 # RAM disk image (initrd) is is in the roottree directory. 
11
12 echo "Creating the Initial RAM disk image.... "
13 if test ! -b /dev/loop2; then
14   mknod /dev/loop2 b 7 2
15   if [ $? != 0 ] ; then
16      echo "Cannot create /dev/loop2"
17      exit 1
18   fi
19 fi
20
21 # first find out how much space we need. 
22 ISIZE=`du -s -k  roottree/ | awk '{print $1}'`
23
24 # add 5 Meg for extra   
25 ISIZE=`expr $ISIZE + 5120`
26 echo "Initial RAM disk contents will be $ISIZE KB"
27
28 # delete the existing RAM disk image, if there is one
29 rm -f root
30
31 dd if=/dev/zero of=$TOPDIR/root bs=1k count=$ISIZE
32
33 # cleanup any prior left over stuff
34 umount $LOOP2  2>/dev/null >/dev/null
35 losetup -d /dev/loop2 2>/dev/null >/dev/null
36
37 # associate it with /dev/loop2
38 losetup /dev/loop2 $TOPDIR/root
39
40 # make an ext2 filesystem on it. Set reserve to 0
41 mke2fs -q -m 0 /dev/loop2 $ISIZE
42 if [ $? != 0 ] ; then
43   echo "Build failed."
44   exit 1
45 fi
46
47 # we mount it...
48 mount /dev/loop2 $LOOP2
49 # ... and delete the lost+found directory 
50 rm -rf $LOOP2/lost+found 
51
52 # then we copy the contents of our roottree to this filesystem
53 cp -dpR roottree/* $LOOP2/
54 cprtn=$?
55
56 # and unmount and divorce /dev/loop2
57 umount $LOOP2
58 losetup -d /dev/loop2 
59 rm -rf $LOOP2
60
61 # If above copy failed, bail out
62 if [ $cprtn != 0 ] ; then
63   echo "RAM disk build failed."
64   exit 1
65 fi
66
67 #
68 # This is a newer way of creating a ramfs.  Note, it
69 #  overwrites the previous root ramdisk that we built.
70 #  If you have an older kernel, you may want to comment
71 #  this out.
72 #
73 (cd roottree; find . | cpio --quiet -H newc -o) >root
74
75 echo "Building initial RAM disk done"
76
77 # Now we have the image of the RAM disk in $TOPDIR/loopfiles/root. We
78 # compress this one and write the compressed image to the boot tree:
79
80 echo "Compressing the RAM disk image.... "
81
82 # delete any existing one
83 rm -f cdtree/boot/isolinux/initrd.img
84
85 # and gzip our RAM disk image and put it in the right place.
86 gzip -9 -c root >cdtree/boot/isolinux/initrd.img
87 if [ $? != 0 ] ; then
88   echo "Build failed"
89   exit 1
90 fi
91
92 rdsize=`expr $ISIZE \* 1024`
93 echo "Ramdisk size is $rdsize"
94
95 echo "Making isolinux.cfg"
96 cat >cdtree/boot/isolinux/isolinux.cfg <<END_OF_DATA
97 default linux
98 prompt 1
99 display boot.msg
100 timeout 300
101 F1 boot.msg
102 F2 options.msg
103 F3 general.msg
104 F4 kernel.msg
105 label linux
106   kernel vmlinuz
107   append ramdisk_size=$rdsize initrd=initrd.img
108 label memtest86
109   kernel memtest
110   append -
111 END_OF_DATA
112
113 # we are done with the RAM disk image, delete it
114 rm -f root
115
116 echo "Initial RAM disk initrd.img is built."