9 # check if the zpool already exists
11 ZPOOL_EXISTS=` zpool list -H | cut -f 1 | grep "${ZPOOL}"`
12 if [ "${?}" -ne 1 ]; then
13 echo "One zpool called ${ZPOOL} already exists, you have to destroy it first:"
14 echo " # zpool destroy ${ZPOOL}"
19 # check if the disk is ok for writing
21 sysctl kern.geom.part.mbr.enforce_chs=0
23 for D in ${DESTDISKS}; do
24 if [ -z "${DESTDISK_1}" ]; then
28 echo checking sanity ${D}
30 gpart show ${D} 1>/dev/null
31 if [ "${?}" -eq 0 ]; then
34 if [ "${?}" -ne 0 ]; then
35 echo unable to reset ${D}
39 echo partitioning ${D}
41 N=$( echo ${D} | tr -c -d '0-9' )
42 gpart create -s gpt ${D}
43 gpart add -a 4k -t efi -s 200M -l efiboot${N} ${D}
44 newfs_msdos -F 32 -c 1 /dev/${D}p1
45 gpart add -a 4k -t freebsd-boot -s 512k -l gptboot${N} ${D}
46 gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 ${D}
47 gpart add -a 1m -s 32G -t freebsd-swap -l swap${N} ${D}
48 gpart add -a 1m -t freebsd-zfs -l zfs${N} ${D}
49 gpart set -a active ${D}
53 sysctl vfs.zfs.min_auto_ashift=12
55 echo set up zfs pool: ${ZPOOL} alt mount: ${DESTDIR}
56 echo =================
58 zpool create -m none -f -R ${DESTDIR} ${ZPOOL} /dev/gpt/zfs*
59 if [ "${?}" -ne 0 ]; then
60 echo "unable to create zpool"
65 for I in ROOT VAR HOME DATA; do
66 zfs create -o mountpoint=none -o canmount=off ${ZPOOL}/${I}
69 zfs create -o atime=off -o mountpoint=/ ${ZPOOL}/ROOT/master
71 zfs create -o mountpoint=/usr/obj ${ZPOOL}/ROOT/obj
72 zfs create -o compression=off -o mountpoint=/usr/src ${ZPOOL}/ROOT/src
73 zfs create -o mountpoint=/usr/doc -o compression=on ${ZPOOL}/ROOT/doc
74 # useless ? as far /tmp mountpoint will be mounted by tmpfs
75 zfs create -o mountpoint=/tmp ${ZPOOL}/ROOT/tmp
77 zfs create -o mountpoint=/usr/local ${ZPOOL}/LOCAL
78 zfs create -o mountpoint=/usr/local/etc ${ZPOOL}/LOCAL/config
81 zfs create -o mountpoint=/var ${ZPOOL}/VAR/master
82 zfs create -o mountpoint=/var/crash ${ZPOOL}/VAR/crash
83 zfs create -o exec=off -o setuid=off -o mountpoint=/var/db ${ZPOOL}/VAR/db
84 zfs create -o compression=lz4 -o exec=on -o setuid=off -o mountpoint=/var/db/pkg ${ZPOOL}/VAR/db/pkg
85 zfs create -o compression=on -o exec=off -o setuid=off -o mountpoint=/var/mail ${ZPOOL}/VAR/mail
86 zfs create -o compression=on -o exec=off -o setuid=off -o mountpoint=/var/log ${ZPOOL}/VAR/log
87 zfs create -o exec=off -o setuid=off -o mountpoint=/var/run ${ZPOOL}/VAR/run
88 zfs create -o exec=off -o setuid=off -o mountpoint=/var/tmp ${ZPOOL}/VAR/tmp
90 zfs create -o mountpoint=/usr/home ${ZPOOL}/HOME/master
92 zpool set bootfs=${ZPOOL}/ROOT/master ${ZPOOL}
94 chmod 1777 ${DESTDIR}/tmp ${DESTDIR}/var/tmp
99 if [ "${?}" -ne 0 ]; then
100 echo zfs mountpoints are not ready
104 echo Fetching and Extracting base files into ${DESTDIR}
105 echo =======================================
108 for I in base.txz kernel.txz lib32.txz; do
109 fetch http://ftp.freebsd.org/pub/FreeBSD/releases/amd64/12.2-RELEASE/${I}
110 tar --unlink -pJxf ${I} -C ${DESTDIR}
113 for D in ${DESTDISKS}; do
114 echo copying EFI partcode at ${D}
115 mount -t msdosfs /dev/${D}p1 /mnt/boot && mkdir -p /mnt/boot/EFI/BOOT && cp ${DDESTDIR}/boot/loader.efi /mnt/boot/EFI/BOOT/BOOTX64.EFI
119 echo writing configuration files
120 echo ==========================
122 cat << EOF >> ${DESTDIR}/etc/fstab
123 /dev/${DESTDISK_1}p3 none swap sw 0 0
124 tmpfs /tmp tmpfs rw,mode=1777 0 0
127 cat << EOF >> ${DESTDIR}/boot/loader.conf
132 cat << EOF >> ${DESTDIR}/boot/loader.conf.local
133 vfs.root.mountfrom="zfs:${ZPOOL}/ROOT/master"
137 cd ${SCRIPTBASE}${COPYCAT} || exit 1
138 echo installing files into ${COPYCAT}
140 if [ -r "${I}" -a -f ${I} ]; then
141 install -o root -g wheel -m 0644 ${I} ${DESTDIR}${COPYCAT}/
144 COPYCAT="/etc/rc.conf.d"
145 cd ${SCRIPTBASE}${COPYCAT} || exit 1
146 echo installing files into ${COPYCAT}
147 install -o root -g wheel -d -m 0755 ${DESTDIR}${COPYCAT} || exit 1
149 if [ -r "${I}" -a -f ${I} ]; then
150 install -o root -g wheel -m 0644 ${I} ${DESTDIR}${COPYCAT}/
153 COPYCAT="/etc/rc.conf.d/network"
154 cd ${SCRIPTBASE}${COPYCAT} || exit 1
155 install -o root -g wheel -d -m 0755 ${DESTDIR}${COPYCAT} || exit 1
156 echo installing files into ${COPYCAT}
157 install -o root -g wheel -m 0644 * ${DESTDIR}${COPYCAT}/
159 chroot ${DESTDIR} passwd
160 chroot ${DESTDIR} adduser
162 read -p "Do you wish to open a shell ?" yn
166 * ) echo "Please answer yes or no.";;
168 chroot ${DESTDIR} tcsh