3 # Create bootstrap information files -- prelude to creating a
6 # Kern Sibbald, December MMII
7 # This source distributed under the GPL
17 FreeBSD | SunOS | IRIX)
19 echo "This code is not yet adapted to this OS"
24 echo "Unknown operating system type: $host"
28 if [ ! `whoami` = "root" ] ; then
30 echo "You need to be root to run this, otherwise"
31 echo "sfdisk produces no output. Continuing anyway ..."
36 # First collect information
38 rm -rf format.* partition.* $di
39 echo "Begin collecting system info ..."
43 mount -l -t ext2 >mount.ext2.bsi
44 mount -l -t ext3 >mount.ext3.bsi
45 cp /etc/fstab fstab.bsi
48 sfdisk -s >sfdisk.disks.bsi
49 grep "^/dev/" sfdisk.disks.bsi | sed -n 's%\(^/dev/[A-Za-z]*\):.*$%\1%p' >disks.bsi
50 for i in `cat disks.bsi`; do
51 j=`echo $i | cut -c6-`
52 sfdisk -l $i >sfdisk.$j.bsi
53 sfdisk -d $i >sfdisk.make.$j.bsi
56 ifconfig >ifconfig.bsi
57 echo "Done collecting info."
60 # Done collecting information
64 echo "Begin creating scripts ..."
66 # First create partitioning script(s)
68 for i in `cat disks.bsi`; do
69 j=`echo $i | cut -c6-`
70 cat >$cwd/partition.$j <<END_OF_DATA
73 # Partition disk $i -- created by getdiskinfo
75 echo "This script will repartition disk $i."
77 echo "IT WILL DESTROY ALL DATA ON DISK $i !!!!"
79 echo -n "Are you sure you want to continue? yes/no: "
81 if [ x\$a != xyes ] ; then
84 echo "Partitioning disk $i"
86 dd if=/dev/zero of=$i bs=512 count=2
88 sfdisk $i <$di/sfdisk.make.$j.bsi | less
90 echo "The previous partitioning was:"
94 echo "The new partitioning is:"
97 echo "If the disk is correctly partitioned, you should"
98 echo "now run the \"format.$j\" script."
102 chmod 755 $cwd/partition.$j
104 echo "Done making partitioning scripts"
107 # Create formatting script(s)
109 echo "Begin making formatting script(s) ..."
110 for i in `cat disks.bsi`; do
111 j=`echo $i | cut -c6-`
112 cat >$cwd/format.$j <<END_OF_DATA
115 # Format all partitions on disk $i -- created by getdiskinfo
118 echo "This script will format all partitions on disk $i."
120 echo "IT WILL DESTROY ALL DATA ON DISK $i !!!!"
122 echo -n "Are you sure you want to continue? yes/no: "
124 if [ x\$a != xyes ] ; then
127 echo "Do you want to do a disk check for bad blocks?"
128 echo -n "It is recommended, but takes time. yes/no: "
130 if [ x\$a = xyes ] ; then
137 # Find swap partitions in output from sfdisk
138 k=`grep "^$i.*82 Linux swap" sfdisk.$j.bsi | cut -d ' ' -f 1`
140 echo "echo \"Formatting $disk -- swap partition\"" >>$cwd/format.$j
141 echo "mkswap $check $disk" >>$cwd/format.$j
142 echo "echo \"\"" >>$cwd/format.$j
144 # Find ext2 partitions in mount output
145 k=`grep "^$i" mount.ext2.bsi | cut -d ' ' -f 1`
147 echo "echo \"Formating $disk -- ext2 partition\"" >>$cwd/format.$j
148 label=`grep "^$disk" mount.ext2.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
149 if [ x$label = x ] ; then
150 echo "mke2fs -v \$check $disk" >>$cwd/format.$j
152 echo "mke2fs -v \$check -L $label $disk" >>$cwd/format.$j
154 echo "echo \"\"" >>$cwd/format.$j
156 # Find ext3 partitions in mount output
157 k=`grep "^$i" mount.ext3.bsi | cut -d ' ' -f 1`
159 echo "echo \"Formating $disk -- ext3 partition\"" >>$cwd/format.$j
160 label=`grep "^$disk" mount.ext3.bsi | cut -d ' ' -f 7 | cut -c2- | cut -d ] -f 1`
161 if [ x$label = x ] ; then
162 echo "mke2fs -v -j \$check $disk" >>$cwd/format.$j
164 echo "mke2fs -v -j \$check -L $label $disk" >>$cwd/format.$j
166 echo "echo \"\"" >>$cwd/format.$j
168 chmod 755 $cwd/format.$j
174 # Create network start script
177 ip=`host $host | cut -d ' ' -f 4`
178 if [ $ip = "out;" ] ; then
179 ip=`ifconfig | grep inet | head -1 | sed -n 's/\ \+inet addr:\([0-9]\+\(\.[0-9]\+\)\{3\}\).*/\1/p'`
181 cat >start_network <<END_OF_DATA
184 # Start network -- created by getdiskinfo
189 ifconfig \$dev up \$ip
190 route add default gw \$ip dev \$dev
193 chmod 755 start_network
195 cat >mount_drives <<END_OF_DATA
198 # Mount disk drives -- created by getdiskinfo
201 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/mnt\/disk\2/p' $di/mount.ext2.bsi >/tmp/1$$
202 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/mnt\/disk\2/p' $di/mount.ext3.bsi >>/tmp/1$$
203 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/mnt\/disk\2/p' $di/mount.rei.bsi >>/tmp/1$$
204 # sort so that / is first
205 sort -k 2 </tmp/1$$ >/tmp/2$$
206 # output mkdir followed by its mount
207 sed -n 's/\(^.*\)\ \(.*$\)/mkdir -p \2\nmount \1 \2/p' /tmp/2$$ >>mount_drives
208 rm -f /tmp/1$$ /tmp/2$$
211 chmod 755 mount_drives
213 # copy sfdisk so we will have it
215 echo "Done building scripts."
217 echo "You might want to do a:"
219 echo "chown -R uuuu:gggg *"
221 echo "where uuuu is your userid and gggg is your group"
222 echo "so that you can access all the files as non-root"