3 # Create bootstrap information files -- prelude to creating a
6 # Kern Sibbald, December MMII
7 # This source distributed under the GPL
15 FreeBSD | SunOS | IRIX)
17 echo "This code is not yet adapted to this OS"
22 echo "Unknown operating system type: $host"
26 if [ ! `whoami` = "root" ] ; then
28 echo "You need to be root to run this, otherwise"
29 echo "sfdisk produces no output. Continuing anyway ..."
34 # First collect information
36 echo "Begin collecting system info"
40 mount -l -t ext2 >mount.ext2.bsi
41 mount -l -t ext3 >mount.ext3.bsi
42 cp /etc/fstab fstab.bsi
45 sfdisk -s >sfdisk.disks.bsi
46 grep "^/dev/" sfdisk.disks.bsi | sed -n 's/\(^.*\):.*$/\1/p' >disks.bsi
47 for i in `cat disks.bsi`; do
48 j=`echo $i | cut -c6-`
49 sfdisk -l $i >sfdisk.$j.bsi
50 sfdisk -d $i >sfdisk.make.$j.bsi
53 ifconfig >ifconfig.bsi
54 echo "Done collecting info. Building scripts ..."
57 # Done collecting information
62 # First create partitioning script(s)
64 for i in `cat disks.bsi`; do
65 j=`echo $i | cut -c6-`
66 cat >$cwd/partition.$j <<END_OF_DATA
69 # Partition disk $i -- created by getdiskinfo
71 echo "This script will repartition disk $i."
73 echo "IT WILL DESTROY ALL DATA ON DISK $i !!!!"
75 echo -n "Are you sure you want to continue? (yes/no): "
77 if [ x\$a != xyes ] ; then
80 echo "Partitioning disk $i"
82 dd if=/dev/zero of=$i bs=512 count=2
84 sfdisk $i <$di/sfdisk.make.$j.bsi | less
86 echo "The previous partitioning was:"
90 echo "The new partitioning is:"
93 echo "If the disk is correctly partitioned, you should"
94 echo "now run the \"format.$j\" script."
98 chmod 755 $cwd/partition.$j
102 # Create formatting script(s)
104 for i in `cat disks.bsi`; do
105 j=`echo $i | cut -c6-`
106 cat >$cwd/format.$j <<END_OF_DATA
109 # Format all partitions on disk $i -- created by getdiskinfo
112 echo "This script will format all partitions on disk $i."
114 echo "IT WILL DESTROY ALL DATA ON DISK $i !!!!"
116 echo -n "Are you sure you want to continue? (yes/no): "
118 if [ x\$a != xyes ] ; then
121 echo "Do you want to do a disk check for bad blocks?"
122 echo -n "It is recommended, but takes time. (yes/no): "
124 if [ x\$a = xyes ] ; then
131 # Find swap partitions in output from sfdisk
132 k=`grep "^$i.*82 Linux swap" sfdisk.$j.bsi | cut -d ' ' -f 1`
134 echo "echo \"Formatting $disk -- swap partition\"" >>$cwd/format.$j
135 echo "mkswap $check $disk" >>$cwd/format.$j
136 echo "echo \"\"" >>$cwd/format.$j
138 # Find ext2 partitions in mount output
139 k=`grep "^$i" mount.ext2.bsi | cut -d ' ' -f 1`
141 echo "echo \"Formating $disk -- ext2 partition\"" >>$cwd/format.$j
142 label=`grep "^$disk" mount.ext2.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
143 if [ x$label = x ] ; then
144 echo "mke2fs -v \$check $disk" >>$cwd/format.$j
146 echo "mke2fs -v \$check -L $label $disk" >>$cwd/format.$j
148 echo "echo \"\"" >>$cwd/format.$j
150 # Find ext3 partitions in mount output
151 k=`grep "^$i" mount.ext3.bsi | cut -d ' ' -f 1`
153 echo "echo \"Formating $disk -- ext3 partition\"" >>$cwd/format.$j
154 label=`grep "^$disk" mount.ext3.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
155 if [ x$label = x ] ; then
156 echo "mke2fs -v -j \$check $disk" >>$cwd/format.$j
158 echo "mke2fs -v -j \$check -L $label $disk" >>$cwd/format.$j
160 echo "echo \"\"" >>$cwd/format.$j
162 chmod 755 $cwd/format.$j
168 # Create network start script
171 ip=`host $host | cut -d ' ' -f 4`
172 cat >start_network <<END_OF_DATA
175 # Start network -- created by getdiskinfo
180 ifconfig \$dev up \$ip
181 route add default gw \$ip dev \$dev
184 chmod 755 start_network
186 cat >mount_drives <<END_OF_DATA
189 # Mount disk drives -- created by getdiskinfo
192 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/mkdir -p \/mnt\/disk\2/p' $di/mount.ext2.bsi >>mount_drives
193 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/mkdir -p \/mnt\/disk\2/p' $di/mount.ext3.bsi >>mount_drives
194 echo "#" >>mount_drives
195 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/mount \1 \/mnt\/disk\2/p' $di/mount.ext2.bsi >/tmp/1$$
196 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/mount \1 \/mnt\/disk\2/p' $di/mount.ext3.bsi >>/tmp/1$$
197 # sort so that root is mounted first
198 sort -k 3 </tmp/1$$ >>mount_drives
201 chmod 755 mount_drives
203 # copy sfdisk so we will have it