]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/usb/partition_usb_key
Add new usb rescue key code
[bacula/rescue] / rescue / linux / usb / partition_usb_key
1 #!/bin/sh
2 #
3 # Partition the USB stick -- the stick is assumed to be at least 3GB in size
4 #
5 # First delete all existing partitions
6 #
7 . ./config
8 . ./config2
9
10 # Check for tools needed
11 for i in fdisk gunzip blkid install-mbr sfdisk partprobe syslinux ; do
12   if [ ! -e `which $i` ] ; then
13     echo " "
14     echo "$i does not seem to be installed; cannot continue."
15     echo " "
16     exit 1
17   fi
18 done
19
20 if [ ! `whoami` = "root" ] ; then
21   echo ""
22   echo "You need to be root to run this shell script"
23   echo ""
24   exit 1
25 fi
26 if [ "x$USB_DEV" = "x" ] ; then
27   if [ "x$1" = "x" ] ; then
28      echo "You must supply the USB device name on the command line or in USB_DEV"
29      exit 1
30   else
31      USB_DEV=$1
32   fi
33 fi
34 echo "This script will distroy everything on $USB_DEV"
35 fdisk -l $USB_DEV
36 echo " "
37 echo "Answer yes to continue "
38 read a
39 if [ "$a" != "yes" ] ; then
40   echo "Device $USB_DEV unchanged"
41   exit 1
42 fi
43 sfdisk -l $USB_DEV >original-partitioning.txt
44 install-mbr ${USB_DEV}
45
46 fdisk $USB_DEV <<EOF
47 d
48 4
49 d
50 3
51 d
52 2
53 d
54 1
55 n
56 p
57 1
58
59 ${SIZE_PART1}
60 t
61 c
62 a
63 1
64 n
65 p
66 2
67
68 ${SIZE_PART2}
69 n
70 p
71 3
72
73
74 p
75 w
76 EOF
77 partprobe >/dev/null 2>&1
78 partprobe ${USB_DEV}1 >/dev/null 2>&1
79 umount ${USB_DEV}1 >/dev/null 2>&1
80 mkfs.vfat -F 32 -n xubuntu9 ${USB_DEV}1
81 partprobe >/dev/null 2>&1
82 umount ${USB_DEV}2 >/dev/null 2>&1
83 mkfs.ext3 -j -b 4096 -L casper-rw ${USB_DEV}2
84 # Do fs checking every 100 mounts or 360 days
85 tune2fs -c 100 -i 360 ${USB_DEV}2
86 partprobe >/dev/null 2>&1
87 umount ${USB_DEV}3
88 mkfs.ext3 -j -b 4096 -L bs-rescue ${USB_DEV}3
89 tune2fs -c 100 -i 360 ${USB_DEV}3
90 sync
91
92 echo "New partitioning is:"
93 fdisk -l ${USB_DEV}
94 syslinux ${USB_DEV}1
95 sync
96 partprobe >/dev/null 2>&1
97
98 echo "We're done, now it's a good time to unplug and replug your usb key"
99 echo "Then make sure that /media/bs-rescue is mounted before"
100 echo  "running the copy_bacula_to_usb_key script"