3 # Create bootstrap information files -- prelude to creating a
4 # Bacula Rescue data for USB key
6 # Kern Sibbald, December MMII
7 # This source distributed under the GPLv2
9 #find out on which device is the usb key
11 if [ -f ../../../scripts/nozen ]; then
21 usbdev=`blkid|grep bs-rescue|awk '{print $1}'|cut -d: -f1`
30 if [ ! "x$1" = "x" ] ; then
33 host=clients/`hostname`
36 if [ -f scripts/differenthostname ]; then
37 host=clients/`cat scripts/differenthostname`
38 rm scripts/differenthostname
41 echo "Host specific data will be saved in the directory: ${host}"
44 if [ -f $host.bak/scripts/mount_drives ] ;then
48 if [ -f $host/scripts/mount_drives ] ;then
53 di=${cwd}/$host/diskinfo
54 scr=${cwd}/$host/scripts
55 dirusb=/media/bs-rescue/bacula-rescue/$host
59 FreeBSD | SunOS | IRIX)
61 echo "This code is not yet adapted to this OS"
66 echo "Unknown operating system type: $os"
70 if [ ! `whoami` = "root" ] ; then
72 echo "You need to be root to run this script ..."
78 # First collect information
80 rm -rf format.* partition.* $di create-* $scr
81 echo "Begin collecting system info ..."
85 fdisk -l|grep :|grep -v identifier|grep -v $usbdev|awk '{print $2}'|cut -d: -f1 >devtmp
86 cat devtmp|while read line;do
87 li=`echo $line|cut -d/ -f3`
88 fdisk -l $line > fdisk.$li
89 parted $line print > parted.$li
93 mount -l -t jfs >mount.jfs.bsi
94 blkid |grep jfs >blkid.jfs.bsi
95 mount -l -t vfat >mount.vfat.bsi
96 blkid |grep vfat >blkid.vfat.bsi
97 mount -l -t xfs >mount.xfs.bsi
98 blkid |grep xfs >blkid.xfs.bsi
99 mount -l -t hfs >mount.hfs.bsi
100 blkid |grep hfs >blkid.hfs.bsi
101 mount -l -t hfsplus >mount.hfsplus.bsi
102 blkid |grep hfsplus >blkid.hfsplus.bsi
103 mount -l -t fuseblk >mount.fuseblk.bsi
104 mount -l -t ext2 >mount.ext2.bsi
105 blkid |grep ext2 >blkid.ext2.bsi
106 mount -l -t ext3 >mount.ext3.bsi
107 blkid |grep ext3 >blkid.ext3.bsi
108 mount -l -t ext4 >mount.ext4.bsi
109 blkid |grep ext4 >blkid.ext4.bsi
111 ########################################## problem
112 #blkid |grep ntfs >mount.ntfs.bsi
114 blkid |grep ntfs >blkid.ntfs.bsi
116 cat mount.fuseblk.bsi |awk '{print $1}'|while read line; do
117 blkid|grep $line|grep ntfs>/dev/null 2>&1
119 a=`cat mount.fuseblk.bsi|grep $line|sed 's/fuseblk/ntfs/g'`
120 echo $a >>mount.ntfs.bsi
124 ###########################################3
126 mount -l -t reiserfs >mount.reiser.bsi
127 blkid |grep reiserfs >blkid.reiserfs.bsi
128 cp /etc/fstab fstab.bsi
129 cp /etc/mtab mtab.bsi
134 # Pickup all disks except USB_DEV
135 sfdisk -s | grep -v ${usbdev} >sfdisk.disks.bsi
136 #sfdisk -s >sfdisk.disks.bsi
137 grep "^/dev/" sfdisk.disks.bsi | sed -n 's%\(^/dev/[A-Za-z]*\):.*$%\1%p' >disks.bsi
138 for i in `cat disks.bsi`; do
139 j=`echo $i | cut -c6-`
140 sfdisk -l $i >sfdisk.$j.bsi
141 sfdisk -d $i >sfdisk.make.$j.bsi
143 cat /proc/swaps > swaps.bsi
145 ifconfig >ifconfig.bsi
147 # Gather LVM information
148 # Only tested on LVM2
150 if which lvm > /dev/null 2>/dev/null ; then
151 echo "Gathering LVM information"
154 lvm pvs --noheadings --nosuffix -o pv_name,vg_name | cat > lvm-pv.bsi
155 lvm vgs --noheadings --nosuffix -o vg_name,vg_extent_size --units=k | cat > lvm-vg.bsi
156 lvm lvs --noheadings --nosuffix -o lv_name,vg_name,lv_size --units=k | cat > lvm-lv.bsi
159 echo "Done collecting info."
162 # Done collecting information
166 echo "Begin creating scripts ..."
168 # First create partitioning script(s)
171 for i in `cat disks.bsi`; do
172 j=`echo $i | cut -c6-`
173 cat >$scr/partition.$j <<END_OF_DATA
177 # Partition disk $i -- created by getdiskinfo
179 echo "This script will repartition disk $i."
181 echo "IT WILL DESTROY ALL DATA ON DISK $i !!!!"
183 if [ ! -f noprompt ];then
184 echo -n "Are you sure you want to continue? yes/no: "
186 if [ x\$a != xyes ] ; then
190 echo "Partitioning disk $i"
192 dd if=/dev/zero of=$i bs=512 count=1
194 sfdisk --force $i <$dirusb/diskinfo/sfdisk.make.$j.bsi | less
196 echo "The previous partitioning was:"
197 cat $dirusb/diskinfo/sfdisk.$j.bsi
200 echo "The new partitioning is:"
203 echo "If the disk is correctly partitioned, you should"
204 echo "now run the \"format.$j\" script."
206 partprobe >>/dev/null 2>&1
210 chmod 755 $scr/partition.$j
212 echo "Done making partitioning scripts"
214 if [ $dolvm -eq 1 ] ; then
216 # LVM phase 1: create the Physical Volumess
218 cat > $scr/create-pv <<EOF
221 # Create PVs for LVM -- created by getdiskinfo
223 echo "This script will format all partitions listed in diskinfo/lvm-pv.bsi"
225 echo "IT WILL DESTROY ALL DATA ON THESE PARTITIONS!!!!"
228 for pv in `cat lvm-pv.bsi | awk '{print $1}'`; do
229 echo "echo \" $pv\"" >> $scr/create-pv
232 cat >> $scr/create-pv <<EOF
234 if [ ! -f noprompt ];then
235 echo -n "Are you sure you want to continue? yes/no: "
237 if [ x\$a != xyes ] ; then
242 for pv in `cat lvm-pv.bsi | awk '{print $1}'`; do
243 echo "echo \"Creating PV on $pv\"" >> $scr/create-pv
244 echo "lvm pvcreate -ff -y -v $pv" >> $scr/create-pv
246 echo "echo \"Done.\"" >> $scr/create-pv
247 echo "echo \"If there were no errors, run create-vg to create the volume groups.\"" >> $scr/create-pv
248 chmod +x $scr/create-pv
251 # LVM phase 2: create Volume Groups
253 cat > $scr/create-vg <<EOF
256 echo "This script will create all volume groups listed in diskinfo/lvm-vg.bsi"
257 echo "You must have sucesfully run create-pv to create the requesite PVs first"
259 if [ ! -f noprompt ];then
260 echo -n "Are you sure you want to continue? yes/no: "
262 if [ x\$a != xyes ] ; then
267 cat lvm-vg.bsi | awk '{print $1, $2}' | while read vg pesize ; do
268 echo "echo \"Creating VG $vg PE extent size $pesize kbytes"\" >> $scr/create-vg
270 for pv in `cat lvm-pv.bsi | awk "\\\$2 == \"$vg\" { print \\\$1 }"` ; do
273 echo "lvm vgcreate $vg -v -s ${pesize}k $pelist" >> $scr/create-vg
275 echo "echo \"Done.\"" >> $scr/create-vg
276 echo "echo \"If there were no errors, run create-lv to create the logical volumes.\"" >> $scr/create-vg
277 chmod +x $scr/create-vg
281 # LVM phase 3: create Logical Volumes
283 # One quick sidenote: this script creates LVs with a size based on the
284 # physical extent count, rather than the size in bytes. This is because
285 # at the time of writing this script, lvdisplay erroneously prints out
286 # the size in 512 byte sector count rather than 1024 byte blocks.
287 # Using the extent count should allow this script to continue to work
288 # even after the bug is fixed.
290 cat > $scr/create-lv <<EOF
293 echo "This script will create all logical volumes listed in diskinfo/lvm-lv.bsi"
294 echo "You must have sucesfully run create-vg to create the requesite VGs first"
296 if [ ! -f noprompt ];then
297 echo -n "Are you sure you want to continue? yes/no: "
299 if [ x\$a != xyes ] ; then
304 cat lvm-lv.bsi | awk '{print $1, $2, $3}' | while read lv vg lvsize ; do
305 # lv=`echo $lv | sed -e 's/.*\///'`
306 echo "echo \"Creating LV $lv\"" >> $scr/create-lv
307 echo "lvm lvcreate -L ${lvsize}k $vg -n $lv" >> $scr/create-lv
309 chmod +x $scr/create-lv
313 # Create formatting script(s)
315 echo "Begin making formatting script(s) ..."
316 for i in `cat disks.bsi`; do
317 j=`echo $i | cut -c6-`
318 cat >$scr/format.$j <<END_OF_DATA
321 # Format all partitions on disk $i -- created by getdiskinfo
324 echo "This script will format all partitions on disk $i."
326 echo "IT WILL DESTROY ALL DATA ON DISK $i !!!!"
328 if [ ! -f noprompt ];then
329 echo -n "Are you sure you want to continue? yes/no: "
331 if [ x\$a != xyes ] ; then
335 if [ ! -f badblocksnoprompt ];then
336 echo "Do you want to do a disk check for bad blocks?"
337 echo -n "It is recommended, but takes time. yes/no: "
339 if [ x\$a = xyes ] ; then
349 # Find swap partitions in output from sfdisk
350 k=`grep "^$i.*82 Linux swap" sfdisk.$j.bsi | cut -d ' ' -f 1`
352 fields=`blkid |grep $disk|wc -w`
353 kid=`blkid |grep $disk`
354 while [ $fields -ne 0 ];do
355 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
357 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
359 fields=$(( fields - 1 ))
361 echo "echo \"Formatting $disk -- swap partition\"" >>$scr/format.$j
362 echo "mkswap $check -U $u $disk" >>$scr/format.$j
363 echo "echo \"\"" >>$scr/format.$j
366 # Find ext2 partitions in mount output
367 k=`grep "^$i" mount.ext2.bsi | cut -d ' ' -f 1`
369 fields=`blkid |grep $disk|wc -w`
370 kid=`blkid |grep $disk`
371 while [ $fields -ne 0 ];do
372 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
374 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
376 fields=$(( fields - 1 ))
378 echo "echo \"Formating $disk -- ext2 partition\"" >>$scr/format.$j
379 label=`grep "^$disk" mount.ext2.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
380 if [ x$label = x ] ; then
381 echo "mkfs.ext2 -v \$check $disk" >>$scr/format.$j
383 echo "mkfs.ext2 -v \$check -L $label -U $u $disk" >>$scr/format.$j
385 echo "echo \"\"" >>$scr/format.$j
387 # Find ext3 partitions in mount output
388 k=`grep "^$i" mount.ext3.bsi | cut -d ' ' -f 1`
390 fields=`blkid |grep $disk|wc -w`
391 kid=`blkid |grep $disk`
392 while [ $fields -ne 0 ];do
393 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
395 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
397 fields=$(( fields - 1 ))
399 echo "echo \"Formating $disk -- ext3 partition\"" >>$scr/format.$j
400 label=`grep "^$disk" mount.ext3.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
401 if [ x$label = x ] ; then
402 echo "mkfs.ext3 -v -j \$check -U $u $disk" >>$scr/format.$j
404 echo "mkfs.ext3 -v -j \$check -L $label -U $u $disk" >>$scr/format.$j
406 echo "echo \"\"" >>$scr/format.$j
410 # Find ext4 partitions in mount output
411 k=`grep "^$i" mount.ext4.bsi | cut -d ' ' -f 1`
413 fields=`blkid |grep $disk|wc -w`
414 kid=`blkid |grep $disk`
415 while [ $fields -ne 0 ];do
416 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
418 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
420 fields=$(( fields - 1 ))
422 echo "echo \"Formating $disk -- ext4 partition\"" >>$scr/format.$j
423 label=`grep "^$disk" mount.ext4.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
424 if [ x$label = x ] ; then
425 echo "mkfs.ext4 -v -j \$check -U $u $disk" >>$scr/format.$j
427 echo "mkfs.ext4 -v -j \$check -L $label -U $u $disk" >>$scr/format.$j
429 echo "echo \"\"" >>$scr/format.$j
432 # Find xfs partitions in mount output
433 k=`grep "^$i" mount.xfs.bsi | cut -d ' ' -f 1`
435 fields=`blkid |grep $disk|wc -w`
436 kid=`blkid |grep $disk`
437 while [ $fields -ne 0 ];do
438 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
442 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
444 fields=$(( fields - 1 ))
449 echo "echo \"Formating $disk -- xfs partition\"" >>$scr/format.$j
450 label=`grep "^$disk" mount.xfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
451 if [ x$label = x ] ; then
452 echo "mkfs.xfs -f \$check $disk" >>$scr/format.$j
454 echo "mkfs.xfs -f \$check -L $label $disk" >>$scr/format.$j
456 echo "xfs_admin -U $u $disk">>$scr/format.$j
457 echo "echo \"\"" >>$scr/format.$j
461 # Find jfs partitions in mount output
462 k=`grep "^$i" mount.jfs.bsi | cut -d ' ' -f 1`
464 fields=`blkid |grep $disk|wc -w`
465 kid=`blkid |grep $disk`
466 while [ $fields -ne 0 ];do
467 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
470 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
472 fields=$(( fields - 1 ))
474 echo "echo \"Formating $disk -- jfs partition\"" >>$scr/format.$j
475 label=`grep "^$disk" mount.jfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
476 if [ x$label = x ] ; then
477 echo "mkfs.jfs -f \$check $disk" >>$scr/format.$j
479 echo "mkfs.jfs -f \$check -L $label $disk" >>$scr/format.$j
481 echo "jfs_tune -U $u $disk " >>$scr/format.$j
482 echo "echo \"\"" >>$scr/format.$j
484 # Find vfat partitions in mount output
485 k=`grep "^$i" mount.vfat.bsi | cut -d ' ' -f 1`
487 fields=`blkid |grep $disk|wc -w`
488 kid=`blkid |grep $disk`
489 while [ $fields -ne 0 ];do
490 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
492 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
493 u=`echo $u|sed 's/-//g'`
495 fields=$(( fields - 1 ))
497 echo "echo \"Formating $disk -- vfat partition\"" >>$scr/format.$j
498 label=`grep "^$disk" mount.vfat.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
499 if [ x$label = x ] ; then
500 echo "mkfs.vfat \$check -i $u $disk" >>$scr/format.$j
502 echo "mkfs.vfat \$check -n $label -i $u $disk" >>$scr/format.$j
504 echo "echo \"\"" >>$scr/format.$j
506 # Find reiserfs partitions in mount output
507 k=`grep "^$i" mount.reiser.bsi | cut -d ' ' -f 1`
509 fields=`blkid |grep $disk|wc -w`
510 kid=`blkid |grep $disk`
511 while [ $fields -ne 0 ];do
512 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
514 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
516 fields=$(( fields - 1 ))
518 echo "echo \"Formating $disk -- reiser partition\"" >>$scr/format.$j
519 label=`grep "^$disk" mount.reiser.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
520 if [ x$label = x ] ; then
521 echo "mkreiserfs -u $u $disk" >>$scr/format.$j
523 echo "mkreiserfs -l $label -u $u $disk" >>$scr/format.$j
525 echo "echo \"\"" >>$scr/format.$j
529 # Find hfs partitions in mount output
531 k=`grep "^$i" mount.hfs.bsi | cut -d ' ' -f 1`
534 echo "echo \"Formating $disk -- hfs partition\"" >>$scr/format.$j
535 label=`grep "^$disk" mount.hfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
536 if [ x$label = x ] ; then
537 echo "mkfs.hfs \$check $disk" >>$scr/format.$j
539 echo "mkfs.hfs \$check -v $label $disk" >>$scr/format.$j
541 echo "echo \"\"" >>$scr/format.$j
545 # Find hfsplus partitions in mount output
547 k=`grep "^$i" mount.hfsplus.bsi | cut -d ' ' -f 1`
550 echo "echo \"Formating $disk -- hfsplus partition\"" >>$scr/format.$j
551 label=`grep "^$disk" mount.hfsplus.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
552 if [ x$label = x ] ; then
553 echo "mkfs.hfsplus \$check $disk" >>$scr/format.$j
555 echo "mkfs.hfsplus \$check -v $label $disk" >>$scr/format.$j
557 echo "echo \"\"" >>$scr/format.$j
561 # Find ntfs partitions in mount output
562 k=`grep "^$i" mount.ntfs.bsi | cut -d ' ' -f 1`
565 echo "echo \"Formating $disk -- ntfs partition\"" >>$scr/format.$j
566 label=`grep "^$disk" mount.ntfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
567 if [ x$label = x ] ; then
568 echo "mkfs.ntfs \$check $disk" >>$scr/format.$j
570 echo "mkfs.ntfs \$check -L $label $disk" >>$scr/format.$j
572 echo "echo \"\"" >>$scr/format.$j
574 chmod 755 $scr/format.$j
577 # Create LVM formatting scripts(s)
579 # Somebody more clever than I with bash scripting
580 # could probably factor a lot of this code out.
582 if [ $dolvm -eq 1 ] ; then
583 echo "Begin making LVM formatting script(s) ..."
584 for i in `cat lvm-vg.bsi | awk '{print $1}'`; do
585 cat >$scr/format.$i <<END_OF_DATA
588 # Format all partitions on VG $i -- created by getdiskinfo
591 echo "This script will format all LVs on VG $i."
593 echo "IT WILL DESTROY ALL DATA ON DISK $i !!!!"
595 if [ ! -f noprompt ];then
596 echo -n "Are you sure you want to continue? yes/no: "
598 if [ x\$a != xyes ] ; then
602 if [ ! -f badblocksnoprompt ];then
603 echo "Do you want to do a disk check for bad blocks?"
604 echo -n "It is recommended, but takes time. yes/no: "
606 if [ x\$a = xyes ] ; then
616 # Find swap partitions in output from sfdisk
618 mapper="/dev/mapper/${i}"
619 k=`grep "^$mapper" swaps.bsi | awk '{print $1}'`
621 fields=`blkid |grep $disk|wc -w`
622 kid=`blkid |grep $disk`
623 while [ $fields -ne 0 ];do
624 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
626 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
628 fields=$(( fields - 1 ))
630 echo "echo \"Formatting $disk -- swap partition\"" >>$scr/format.$i
631 echo "mkswap $check -U $u $disk" >>$scr/format.$i
632 echo "echo \"\"" >>$scr/format.$i
635 # Find ext2 partitions in mount output
636 k=`grep "^$mapper" mount.ext2.bsi | cut -d ' ' -f 1`
638 fields=`blkid |grep $disk|wc -w`
639 kid=`blkid |grep $disk`
640 while [ $fields -ne 0 ];do
641 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
643 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
645 fields=$(( fields - 1 ))
647 echo "echo \"Formating $disk -- ext2 partition\"" >>$scr/format.$i
648 label=`grep "^$disk" mount.ext2.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
649 if [ x$label = x ] ; then
650 echo "mkfs.ext2 -v \$check $disk" >>$scr/format.$i
652 echo "mkfs.ext2 -v \$check -L $label -U $u $disk" >>$scr/format.$i
654 echo "echo \"\"" >>$scr/format.$i
656 # Find ext3 partitions in mount output
657 k=`grep "^$mapper" mount.ext3.bsi | cut -d ' ' -f 1`
659 fields=`blkid |grep $disk|wc -w`
660 kid=`blkid |grep $disk`
661 while [ $fields -ne 0 ];do
662 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
664 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
666 fields=$(( fields - 1 ))
668 echo "echo \"Formating $disk -- ext3 partition\"" >>$scr/format.$i
669 label=`grep "^$disk" mount.ext3.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
670 if [ x$label = x ] ; then
671 echo "mkfs.ext3 -v -j \$check -U $u $disk" >>$scr/format.$i
673 echo "mkfs.ext3 -v -j \$check -L $label -U $u $disk" >>$scr/format.$i
675 echo "echo \"\"" >>$scr/format.$i
679 # Find ext4 partitions in mount output
680 k=`grep "^$mapper" mount.ext4.bsi | cut -d ' ' -f 1`
682 fields=`blkid |grep $disk|wc -w`
683 kid=`blkid |grep $disk`
684 while [ $fields -ne 0 ];do
685 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
687 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
689 fields=$(( fields - 1 ))
691 echo "echo \"Formating $disk -- ext4 partition\"" >>$scr/format.$i
692 label=`grep "^$disk" mount.ext4.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
693 if [ x$label = x ] ; then
694 echo "mkfs.ext4 -v -j \$check -U $u $disk" >>$scr/format.$i
696 echo "mkfs.ext4 -v -j \$check -L $label -U $u $disk" >>$scr/format.$i
698 echo "echo \"\"" >>$scr/format.$i
701 # Find xfs partitions in mount output
702 k=`grep "^$mapper" mount.xfs.bsi | cut -d ' ' -f 1`
704 fields=`blkid |grep $disk|wc -w`
705 kid=`blkid |grep $disk`
706 while [ $fields -ne 0 ];do
707 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
711 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
713 fields=$(( fields - 1 ))
718 echo "echo \"Formating $disk -- xfs partition\"" >>$scr/format.$i
719 label=`grep "^$disk" mount.xfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
720 if [ x$label = x ] ; then
721 echo "mkfs.xfs -f \$check $disk" >>$scr/format.$i
723 echo "mkfs.xfs -f \$check -L $label $disk" >>$scr/format.$i
725 echo "xfs_admin -U $u $disk">>$scr/format.$i
726 echo "echo \"\"" >>$scr/format.$i
730 # Find jfs partitions in mount output
731 k=`grep "^$mapper" mount.jfs.bsi | cut -d ' ' -f 1`
733 fields=`blkid |grep $disk|wc -w`
734 kid=`blkid |grep $disk`
735 while [ $fields -ne 0 ];do
736 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
739 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
741 fields=$(( fields - 1 ))
743 echo "echo \"Formating $disk -- jfs partition\"" >>$scr/format.$i
744 label=`grep "^$disk" mount.jfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
745 if [ x$label = x ] ; then
746 echo "mkfs.jfs -f \$check $disk" >>$scr/format.$i
748 echo "mkfs.jfs -f \$check -L $label $disk" >>$scr/format.$i
750 echo "jfs_tune -U $u $disk " >>$scr/format.$i
751 echo "echo \"\"" >>$scr/format.$i
753 # Find vfat partitions in mount output
754 k=`grep "^$mapper" mount.vfat.bsi | cut -d ' ' -f 1`
756 fields=`blkid |grep $disk|wc -w`
757 kid=`blkid |grep $disk`
758 while [ $fields -ne 0 ];do
759 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
761 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
762 u=`echo $u|sed 's/-//g'`
764 fields=$(( fields - 1 ))
766 echo "echo \"Formating $disk -- vfat partition\"" >>$scr/format.$i
767 label=`grep "^$disk" mount.vfat.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
768 if [ x$label = x ] ; then
769 echo "mkfs.vfat \$check -i $u $disk" >>$scr/format.$i
771 echo "mkfs.vfat \$check -n $label -i $u $disk" >>$scr/format.$i
773 echo "echo \"\"" >>$scr/format.$i
775 # Find reiserfs partitions in mount output
776 k=`grep "^$mapper" mount.reiser.bsi | cut -d ' ' -f 1`
778 fields=`blkid |grep $disk|wc -w`
779 kid=`blkid |grep $disk`
780 while [ $fields -ne 0 ];do
781 echo $kid|awk "{print \$ $fields}"|grep UUID>/dev/null 2>&1
783 u=`echo $kid|awk "{print \$ $fields}"|cut -d'"' -f2`
785 fields=$(( fields - 1 ))
787 echo "echo \"Formating $disk -- reiser partition\"" >>$scr/format.$i
788 label=`grep "^$disk" mount.reiser.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
789 if [ x$label = x ] ; then
790 echo "mkreiserfs -u $u $disk" >>$scr/format.$i
792 echo "mkreiserfs -l $label -u $u $disk" >>$scr/format.$i
794 echo "echo \"\"" >>$scr/format.$i
798 # Find hfs partitions in mount output
800 k=`grep "^$mapper" mount.hfs.bsi | cut -d ' ' -f 1`
803 echo "echo \"Formating $disk -- hfs partition\"" >>$scr/format.$i
804 label=`grep "^$disk" mount.hfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
805 if [ x$label = x ] ; then
806 echo "mkfs.hfs \$check $disk" >>$scr/format.$i
808 echo "mkfs.hfs \$check -v $label $disk" >>$scr/format.$i
810 echo "echo \"\"" >>$scr/format.$i
814 # Find hfsplus partitions in mount output
816 k=`grep "^$mapper" mount.hfsplus.bsi | cut -d ' ' -f 1`
819 echo "echo \"Formating $disk -- hfsplus partition\"" >>$scr/format.$i
820 label=`grep "^$disk" mount.hfsplus.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
821 if [ x$label = x ] ; then
822 echo "mkfs.hfsplus \$check $disk" >>$scr/format.$i
824 echo "mkfs.hfsplus \$check -v $label $disk" >>$scr/format.$i
826 echo "echo \"\"" >>$scr/format.$i
830 # Find ntfs partitions in mount output
831 k=`grep "^$mapper" mount.ntfs.bsi | cut -d ' ' -f 1`
834 echo "echo \"Formating $disk -- ntfs partition\"" >>$scr/format.$i
835 label=`grep "^$disk" mount.ntfs.bsi |awk '{print $7}'|cut -d "]" -f1|cut -d "[" -f2`
836 if [ x$label = x ] ; then
837 echo "mkfs.ntfs \$check $disk" >>$scr/format.$i
839 echo "mkfs.ntfs \$check -L $label $disk" >>$scr/format.$i
841 echo "echo \"\"" >>$scr/format.$i
847 chmod 755 $scr/format.$i
854 # Create network start script
859 if [ -f ../../../scripts/nozen ]; then
865 howmanyether=`ifconfig |cut -d" " -f1 |grep -v '^$' |grep -v lo|wc -l`
866 if [ $howmanyether -gt 1 ] ; then
868 cp ../../../scripts/dialognetworkorig dialognetwork
869 sed -i 's/howmany/'$howmanyether'/g' dialognetwork
870 sed -i 's/DIAL/'$DIALOG'/g' dialognetwork
871 ifconfig |cut -d" " -f1 |grep -v '^$' |grep -v lo | while read LINE ; do
873 netline=$(( netline + 1 ))
874 if [ $netline -ne $howmanyether ];then
875 echo $netline $LINE ' off ' >> dialognetwork
877 echo $netline $LINE ' off 2>ans ' >> dialognetwork
880 dial=`cat dialognetwork`
882 echo $dial > dialognetwork
883 chmod +x dialognetwork
891 ifconfig |cut -d" " -f1 |grep -v '^$' |grep -v lo > net
893 netdevice=`echo $net |awk "{print \$ $ans}" `
900 if [ $etherdone = 0 ] ; then
901 ether=`ifconfig |cut -d" " -f1 |grep -v '^$' |grep -v lo`
904 ether=`echo $netdevice`
907 ifconfig $ether 2>/dev/null >/dev/null
909 ip=`ifconfig $ether | grep inet | head -1 | sed -n 's/\ \+inet addr:\([0-9]\+\(\.[0-9]\+\)\{3\}\).*/\1/p'`
910 cat >start_network <<END_OF_DATA
913 # Start network -- created by getdiskinfo
918 ifconfig \$dev up \$ip
921 echo "Warning, no ethernet devices found."
922 echo "#!/bin/sh" >start_network
925 ip=`route -n | grep UG | head -1 | awk '{print $2}'`
926 dev=`route -n | grep UG | head -1 | awk '{print $8}'`
927 cat >>start_network <<END_OF_DATA
928 route add default gw $ip $ether
931 chmod 755 start_network
935 cat >$scr/mount_drives <<END_OF_DATA
938 # Mount disk drives -- created by getdiskinfo
940 PATH=$PATH:/var/chroot/sbin:/var/chroot/bin
942 TMP1=`mktemp gdi.1.XXXXXXXXXX`
943 TMP2=`mktemp gdi.2.XXXXXXXXXX`
944 if test x${TMP1} = x; then
946 if test -f ${TMP1}; then
947 echo "Temp file security problem on: ${TMP1}"
951 if test x${TMP2} = x; then
953 if test -f ${TMP2}; then
954 echo "Temp file security problem on: ${TMP2}"
959 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.ext2.bsi >${TMP1}
960 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.ext3.bsi >>${TMP1}
961 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.reiser.bsi >>${TMP1}
962 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.hfs.bsi >>${TMP1}
963 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.xfs.bsi >>${TMP1}
964 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.jfs.bsi >>${TMP1}
965 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.fuseblk.bsi >>${TMP1}
966 sed -n 's/\(^.*\)\ on\ \(.*\)\ type.*$/\1 \/media\/bs-rescue\/chroot\2/p' $di/mount.vfat.bsi >>${TMP1}
968 # sort so that / is first
969 sort -k 2 <${TMP1} >${TMP2}
970 # output mkdir followed by its mount
971 sed -n 's/\(^.*\)\ \(.*$\)/mkdir -p \2 #\1\
972 mount \1 \2/p' ${TMP2} >>$scr/mount_drives
974 # Now build unmount_drives
975 cat >$scr/umount_drives <<END_OF_DATA
978 # Unmount disk drives -- created by getdiskinfo
981 sort -r -k 2 <${TMP1} >${TMP2}
982 sed -n 's/\(^.*\)\ \(.*$\)/umount \2/p' ${TMP2} >>$scr/umount_drives
983 echo "umount /mnt/cdrom 2>/dev/null >/dev/null" >>$scr/umount_drives
984 echo "sync" >>$scr/umount_drives
985 echo "sync" >>$scr/umount_drives
987 rm -f ${TMP1} ${TMP2}
989 chmod 755 $scr/mount_drives $scr/umount_drives
991 #output result of blkid
993 blkid | while read LINE ; do
994 echo $LINE >> $cwd/$host/diskinfo/blkidinfo
999 . $cwd/scripts/findraidevice/findraid_new
1001 if [ ! -f $cwd/$host/scripts/recreate_raid_arrays ];then
1003 echo "";echo "";echo "";echo "You do not seem to have any soft raid devices";echo "";echo "";echo ""
1006 . $cwd/scripts/new_baklient_conf
1007 . $cwd/scripts/get_serial
1010 echo "Done building scripts."
1011 $DIALOG --title "That's it" --msgbox "We are done gathering info \n you can now restore your machine \n (in case it crashes) \n booting on this usb key \n \n \n P.S. If your computer's bios doesn't support booting off usb, \n insert the provided boot cd as well as this usb key and the magic will happen...." 600 600