-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake_bootable_usb.sh
More file actions
executable file
·161 lines (122 loc) · 2.38 KB
/
Copy pathmake_bootable_usb.sh
File metadata and controls
executable file
·161 lines (122 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/sh
DEV=/dev/da0
ROOTSIZE=5GB
CLEANUP=/home/sniffer/cleanup.sh
ID=`id -u`
if [ "$ID" != "0" ]; then
echo "Should be run as root, use: sudo $0 $*"
exit 1;
fi
if [ ! -e "$DEV" ]; then
echo "Block device $DEV not found, make sure you inserted USB stick!"
exit 1;
fi
gpart show $DEV
echo -n "All data on $DEV will be lost, continute (y/N) ? "
read yesno
if [ "$yesno" != "y" ]; then
echo "Abort!"
exit 1
fi
df -m
echo
ROOTSIZE=`df -m | awk '/ada0p2/{print $3+1 "M"}'`
echo -n "You will need ${ROOTSIZE} on $DEV, continue (y/N) ? "
read yesno
if [ "$yesno" != "y" ]; then
echo "Abort!"
exit 1
fi
if [ ! -d "/mnt" ]; then
mkdir /mnt
fi
echo "Forcibly unmounting all ${DEV}*"
umount -f ${DEV}* 2>/dev/null
echo "Destroting partition table on $DEV"
if gpart destroy -F $DEV ; then
else
echo "Abort!"
exit 1
fi
echo "Creating GPT table on $DEV"
if gpart create -s gpt $DEV ; then
else
echo "Abort!"
exit 1
fi
if echo "Adding EFI partition to $DEV"
gpart add -t efi -l efiboot -a 4k -s 100M $DEV ; then
else
echo "Abort!"
exit 1
fi
echo "Adding FreeBSD UFS partition to $DEV"
if gpart add -t freebsd-ufs -s $ROOTSIZE $DEV ; then
else
echo "Abort!"
exit 1
fi
echo "Adding FreeBSD Swap partition to $DEV"
if gpart add -t freebsd-swap -s 1G $DEV ; then
else
echo "Abort!"
exit 1
fi
echo "Formatting EFI on $DEV with FAT16"
if newfs_msdos -F 16 -c 1 ${DEV}p1 ; then
else
echo "Abort!"
exit 1
fi
echo "Mounting EFI partition ${DEV}p1 to /mnt"
if mount_msdosfs ${DEV}p1 /mnt ; then
else
echo "Abort!"
exit 1
fi
echo "Copying FreeBSD bootloader to /mnt/EFI"
if cp -r /boot/efi/efi /mnt/ ; then
else
echo "Abort!"
exit 1
fi
echo "Unmounting EFI partition ${DEV}p1"
if umount ${DEV}p1 ; then
else
echo "Abort!"
exit 1
fi
echo "Formatting FreeBSD UFS partition ${DEV}p2"
if newfs ${DEV}p2 ; then
else
echo "Abort!"
exit 1
fi
echo "Mounting FreeBSD UFS partition ${DEV}p2 to /mnt"
if mount ${DEV}p2 /mnt ; then
else
echo "Abort!"
exit 1
fi
echo "Dumping / filesystem to ${DEV}p2"
if (cd /mnt; dump -0 -L -f - / | restore -v -r -f - .); then
else
echo "Abort!"
exit 1
fi
echo "Modifying /etc/fstab"
if sed -e 's/\/ada/\/da/' -i .old /mnt/etc/fstab ; then
else
echo "Abort!"
exit 1
fi
rm /mnt/etc/fstab.old
echo "Calling cleanup script $CLEANUP"
sh $CLEANUP 2> /dev/null
echo
df
echo
echo "Done!"
echo
echo "Please check /mnt manually before making image of $DEV"
exit 0