]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/makeinitrd
e5e87dc1bab4f9f7878fba500f466eecc8b8c2fe
[bacula/rescue] / rescue / linux / cdrom / makeinitrd
1 #!/bin/sh
2
3 TOPDIR=`pwd`
4
5 # mkdir -p /mnt/loop1 /mnt/loop2
6
7 # we need to set aside a few loop devices. I chose (in reverse order of their appearance)
8 # -- loop1 for the boot image
9 # -- loop2 for the RAM disk image
10 # since the loop1 choice is reflected in the lilo.loopfix file, 
11 # you should not change that (or you need to change the file).
12 # I had used loop0 first, but I found that this is used by the Samba daemon.
13 # Also, I assume that the mount points are /mnt/loop{1,2}.
14 # In principle we could do with one, but it comes in handy to be able to
15 # leave one mounted, so I took two different ones. 
16
17 # Assume that everything to be loaded into memory with the
18 # RAM disk image (initrd) is is in the roottree directory. 
19
20 echo "Creating the Initial RAM disk image.... "
21
22 # first find out how much space we need. 
23 ISIZE=`du -s -k  roottree/ | awk '{print $1}'`
24
25 # add 2 Meg for extra   
26 ISIZE=`expr $ISIZE + 2048`
27 echo "Initial RAM disk contents will be $ISIZE KB"
28
29 # delete the existing RAM disk image, if there is one
30 rm -f root
31
32 dd if=/dev/zero of=$TOPDIR/root bs=1k count=$ISIZE
33
34 umount /mnt/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 /mnt/loop2 
49
50 # ... and delete the lost+found directory 
51 rm -rf /mnt/loop2/lost+found 
52
53 # then we copy the contents of our roottree to this filesystem
54 cp -dpR roottree/* /mnt/loop2/
55 if [ $? != 0 ] ; then
56   echo "RAM disk build failed."
57   exit 1
58 fi
59
60 # and unmount and divorce /dev/loop2
61 umount /mnt/loop2
62 losetup -d /dev/loop2 
63
64 # (cd roottree; find . | cpio --quiet -c -o) >root
65
66 echo "Building initial RAM disk done"
67
68 # Now we have the image of the RAM disk in $TOPDIR/loopfiles/root. We
69 # compress this one and write the compressed image to the boot tree:
70
71 echo "Compressing the RAM disk image.... "
72
73 # delete any existing one
74 rm -f cdtree/boot/isolinux/initrd.img
75
76 # and gzip our RAM disk image and put it in the right place.
77 # gzip -9 -c root >cdtree/boot/isolinux/initrd.img
78 gzip -9 < 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."