3 # efisetup [-s swap] [-S serialno] <rawdrive>
5 # Copyright (c) 2017 Matthew Dillon. All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 # Email: Matthew Dillon <dillon@backplane.com>
31 echo "WARNING! EFISETUP WILL WIPE THE TARGET DRIVE!"
33 echo "efisetup [-s <swap>{m,g}] [-S serialno] <rawdrive>"
34 echo " -s <swap{m,g} Defaults to 8g"
35 echo " -S serialno Used to adjust loader.conf, fstab, etc"
36 echo " If not specified, drive spec is used"
65 echo "Bad option: $_switch"
69 if [ "x$var" != "x" ]; then
73 if [ "x$drive" != "x" ]; then
74 echo "Specify only one target drive"
75 echo "WARNING! efisetup will wipe the target drive"
84 if [ "x$drive" = "x" ]; then
88 if [ ! -c $drive ]; then
89 if [ ! -c /dev
/$drive ]; then
90 echo "efisetup: $drive is not a char-special device"
96 if [ $fopt == 0 ]; then
97 echo -n "This will wipe $drive, are you sure? "
109 echo "Aborting command"
115 # Ok, do all the work. Start by creating a fresh EFI
118 gpt destroy
$drive > /dev
/null
2>&1
119 dd if=/dev
/zero of
=$drive bs
=32k count
=64 > /dev
/null
2>&1
122 echo "gpt create failed"
129 gpt add
-i 0 -s 524288 -t "EFI System" ${drive}
130 sects
=`gpt show ${drive} | sort -n +1 | tail -1 | awk '{ print $2; }'`
131 sects
=$
(($sects / 2048 * 2048))
132 gpt add
-i 1 -s $sects -t "DragonFly Label64" ${drive}
136 if [ $?
!= 0 ]; then fail
"mkdir -p /efimnt"; fi
138 # GPT s0 - EFI boot setup
140 newfs_msdos
${drive}s0
141 mount_msdos
${drive}s0
/efimnt
142 mkdir
-p /efimnt
/efi
/boot
143 cp /boot
/boot1.efi
/efimnt
/efi
/boot
/bootx64.efi
146 # GPT s1 - DragonFlyBSD disklabel setup
148 disklabel
-r -w ${drive}s1 auto
149 if [ $?
!= 0 ]; then fail
"initial disklabel"; fi
152 disklabel
${drive}s1
> /tmp
/label.$$
153 cat >> /tmp
/label.$$
<< EOF
159 disklabel
-R ${drive}s1
/tmp
/label.$$
160 if [ $?
!= 0 ]; then fail
"disklabel setup"; fi
165 if [ $?
!= 0 ]; then fail
"newfs ${drive}s1a"; fi
166 newfs_hammer2
${drive}s1d
167 if [ $?
!= 0 ]; then fail
"newfs_hammer2 ${drive}s1d"; fi
169 # DragonFly mounts, setup for installation
171 echo "Mounting DragonFly for copying"
172 mount
${drive}s1d
/efimnt
173 if [ $?
!= 0 ]; then fail
"mount ${drive}s1d"; fi
174 mkdir
-p /efimnt
/boot
175 mount
${drive}s1a
/efimnt
/boot
176 if [ $?
!= 0 ]; then fail
"mount ${drive}s1a"; fi
178 # INSTALLWORLD SEQUENCE
180 echo "Mounted onto /efimnt and /efimnt/boot"
181 echo "Type yes to continue with install"
182 echo "You must have a built the world and kernel already."
183 echo "^C here if you did not."
197 echo "Stopping here. /efimnt and /efimnt/boot remain mounted"
202 # Setup initial installworld sequence
205 make installworld DESTDIR
=/efimnt
206 if [ $?
!= 0 ]; then fail
"make installworld"; fi
207 make installkernel DESTDIR
=/efimnt
208 if [ $?
!= 0 ]; then fail
"make installkernel"; fi
210 make distribution DESTDIR
=/efimnt
211 if [ $?
!= 0 ]; then fail
"make distribution"; fi
213 # Calculate base drive path given serial
214 # number (or no serial number).
216 # serno - full drive path or serial number, sans slice & partition,
217 # including the /dev/, which we use as an intermediate
220 # mfrom - partial drive path as above except without the /dev/,
221 # allowed in mountfrom and fstab.
223 if [ "x$serno" == "x" ]; then
225 mfrom
="`echo ${drive} | sed -e 's#/dev/##g'`"
227 serno
="serno/${serno}."
228 mfrom
="serno/${serno}."
231 echo "Fixingup files for a ${serno}s1d root"
233 # Add mountfrom to /efimnt/boot/loader.conf
235 echo "vfs.root.mountfrom=\"hammer2:${mfrom}s1d\"" >> /efimnt
/boot
/loader.conf
237 # Add dumpdev to /etc/rc.conf
239 echo "dumpdev=\"/dev/${mfrom}s1b\"" >> /efimnt
/etc
/rc.conf
241 # Create a fresh /etc/fstab
243 printf "%-20s %-15s hammer2\trw\t1 1\n" "${mfrom}s1d" "/" \
245 printf "%-20s %-15s ufs\trw\t1 1\n" "${mfrom}s1a" "/boot" \
247 printf "%-20s %-15s swap\tsw\t0 0\n" "${mfrom}s1b" "none" \
249 printf "%-20s %-15s procfs\trw\t4 4\n" "proc" "/proc" \
252 echo "Unmounting /efimnt/boot and /efimnt"