]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/makeinitrd
Update
[bacula/rescue] / rescue / linux / cdrom / makeinitrd
1 #!/bin/sh
2
3 TOPDIR=`pwd`
4
5 mkdir -p /mnt/loop1 /mnt/loop2
6
7 #
8 # we need to set aside a few loop devices. I chose (in reverse order of their appearance)
9 # -- loop1 for the boot image
10 # -- loop2 for the RAM disk image
11 # since the loop1 choice is reflected in the lilo.loopfix file, 
12 # you should not change that (or you need to change the file).
13 # I had used loop0 first, but I found that this is used by the Samba daemon.
14 # Also, I assume that the mount points are /mnt/loop{1,2}.
15 # In principle we could do with one, but it comes in handy to be able to
16 # leave one mounted, so I took two different ones. 
17
18 # Assume that everything to be loaded into memory with the
19 # RAM disk image (initrd) is is in the roottree directory. 
20
21 echo "Creating the Initial RAM disk image.... "
22
23 # first find out how much space we need. 
24 ISIZE=`du -s -k  roottree/ | awk '{print $1}'`
25
26 # add 2 Meg for extra   
27 ISIZE=`expr $ISIZE + 2048`
28 echo "Initial RAM disk contents will be $ISIZE KB"
29
30 # delete the existing RAM disk image, if there is one
31 rm -f root
32
33 dd if=/dev/zero of=$TOPDIR/root bs=1k count=$ISIZE
34
35 umount /mnt/loop2  2>/dev/null >/dev/null
36 losetup -d /dev/loop2 2>/dev/null >/dev/null
37
38 # associate it with /dev/loop2
39 losetup /dev/loop2 $TOPDIR/root
40
41 # make an ext2 filesystem on it. Set reserve to 0
42 mke2fs -q -m 0 /dev/loop2 $ISIZE
43 if [ $? != 0 ] ; then
44   echo "Build failed."
45   exit 1
46 fi
47
48 # we mount it...
49 mount /dev/loop2 /mnt/loop2 
50
51 # ... and delete the lost+found directory 
52 rm -rf /mnt/loop2/lost+found 
53
54 # then we copy the contents of our roottree to this filesystem
55 cp -dpR roottree/* /mnt/loop2/
56 if [ $? != 0 ] ; then
57   echo "RAM disk build failed."
58   exit 1
59 fi
60
61 # and unmount and divorce /dev/loop2
62 umount /mnt/loop2
63 losetup -d /dev/loop2 
64
65 # (cd roottree; find . | cpio --quiet -c -o) >root
66
67 echo "Building initial RAM disk done"
68
69 # Now we have the image of the RAM disk in $TOPDIR/loopfiles/root. We
70 # compress this one and write the compressed image to the boot tree:
71
72 echo "Compressing the RAM disk image.... "
73
74 # delete any existing one
75 rm -f cdtree/boot/isolinux/initrd.img
76
77 # and gzip our RAM disk image and put it in the right place.
78 gzip -9 -c root >cdtree/boot/isolinux/initrd.img
79 if [ $? != 0 ] ; then
80   echo "Build failed"
81   exit 1
82 fi
83
84 rdsize=`expr $ISIZE \* 1024`
85 echo "Ramdisk size is $rdsize"
86
87 echo "Making isolinux.cfg"
88 cat >cdtree/boot/isolinux/isolinux.cfg <<END_OF_DATA
89 default linux
90 prompt 1
91 display boot.msg
92 timeout 300
93 F1 boot.msg
94 F2 options.msg
95 F3 general.msg
96 F4 kernel.msg
97 label linux
98   kernel vmlinuz
99   append ramdisk_size=$rdsize initrd=initrd.img
100 label memtest86
101   kernel memtest
102   append -
103 END_OF_DATA
104
105 # we are done with the RAM disk image, delete it
106 rm -f root
107
108 echo "Initial RAM disk initrd.img is built."