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