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}"
18 # check if the disk is ok for writing
22 for D in ${DESTDISKS}; do
23 if [ -z "${DESTDISK_1}" ]; then
27 echo checking sanity ${D}
29 gpart show ${D} 1>/dev/null
30 if [ "${?}" -eq 0 ]; then
33 if [ "${?}" -ne 0 ]; then
34 echo unable to reset ${D}
38 echo partitioning ${D}
40 N=$( echo ${D} | tr -c -d '0-9' )
41 gpart create -s gpt ${D}
42 gpart add -a 4k -t efi -s 200M -l efiboot${N} ${D}
43 gpart bootcode -p /boot/boot1.efifat -i 1 ${D}
44 gpart add -a 4k -t freebsd-boot -s 512k -l gptboot${N} ${D}
45 gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 2 ${D}
46 gpart add -a 1m -s 32G -t freebsd-swap -l swap${N} ${D}
47 gpart add -a 1m -t freebsd-zfs -l zfs${N} ${D}
48 gpart set -a active ${D}
52 sysctl vfs.zfs.min_auto_ashift=12
54 echo set up zfs pool: ${ZPOOL} alt mount: ${DESTDIR}
55 echo =================
57 zpool create -m none -f -R ${DESTDIR} ${ZPOOL} /dev/gpt/zfs*
58 if [ "${?}" -ne 0 ]; then
59 echo "unable to create zpool"
64 for I in ROOT VAR HOME DATA; do
65 zfs create -o mountpoint=none -o canmount=off ${ZPOOL}/${I}
68 zfs create -o atime=off -o mountpoint=/ ${ZPOOL}/ROOT/master
70 zfs create -o mountpoint=/usr/obj ${ZPOOL}/ROOT/obj
71 zfs create -o compression=off -o mountpoint=/usr/src ${ZPOOL}/ROOT/src
72 zfs create -o mountpoint=/usr/doc -o compression=on ${ZPOOL}/ROOT/doc
73 # useless ? as far /tmp mountpoint will be mounted by tmpfs
74 zfs create -o mountpoint=/tmp ${ZPOOL}/ROOT/tmp
76 zfs create -o mountpoint=/usr/local ${ZPOOL}/LOCAL
77 zfs create -o mountpoint=/usr/local/etc ${ZPOOL}/LOCAL/config
80 zfs create -o mountpoint=/var ${ZPOOL}/VAR/master
81 zfs create -o mountpoint=/var/crash ${ZPOOL}/VAR/crash
82 zfs create -o exec=off -o setuid=off -o mountpoint=/var/db ${ZPOOL}/VAR/db
83 zfs create -o compression=lz4 -o exec=on -o setuid=off -o mountpoint=/var/db/pkg ${ZPOOL}/VAR/db/pkg
84 zfs create -o compression=on -o exec=off -o setuid=off -o mountpoint=/var/mail ${ZPOOL}/VAR/mail
85 zfs create -o compression=on -o exec=off -o setuid=off -o mountpoint=/var/log ${ZPOOL}/VAR/log
86 zfs create -o exec=off -o setuid=off -o mountpoint=/var/run ${ZPOOL}/VAR/run
87 zfs create -o exec=off -o setuid=off -o mountpoint=/var/tmp ${ZPOOL}/VAR/tmp
89 zfs create -o mountpoint=/usr/home ${ZPOOL}/HOME/master
91 zpool set bootfs=${ZPOOL}/ROOT/master ${ZPOOL}
93 chmod 1777 ${DESTDIR}/tmp ${DESTDIR}/var/tmp
98 if [ "${?}" -ne 0 ]; then
99 echo zfs mountpoints are not ready
103 echo Fetching and Extracting base files into ${DESTDIR}
104 echo =======================================
107 for I in base.txz kernel.txz lib32.txz; do
108 fetch http://ftp.freebsd.org/pub/FreeBSD/releases/amd64/12.0-BETA3/${I}
109 tar --unlink -pJxf ${I} -C ${DESTDIR}
112 echo writing configuration files
113 echo ==========================
115 cat << EOF >> ${DESTDIR}/etc/fstab
116 /dev/${DESTDISK_1}p3 none swap sw 0 0
117 tmpfs /tmp tmpfs rw,mode=1777 0 0
120 cat << EOF >> ${DESTDIR}/boot/loader.conf
125 cat << EOF >> ${DESTDIR}/boot/loader.conf.local
126 vfs.root.mountfrom="zfs:${ZPOOL}/ROOT/master"
130 cd ${SCRIPTBASE}${COPYCAT} || exit 1
131 echo installing files into ${COPYCAT}
133 if [ -r "${I}" -a -f ${I} ]; then
134 install -o root -g wheel -m 0644 ${I} ${DESTDIR}${COPYCAT}/
137 COPYCAT="/etc/rc.conf.d"
138 cd ${SCRIPTBASE}${COPYCAT} || exit 1
139 echo installing files into ${COPYCAT}
140 install -o root -g wheel -d -m 0755 ${DESTDIR}${COPYCAT} || exit 1
142 if [ -r "${I}" -a -f ${I} ]; then
143 install -o root -g wheel -m 0644 * ${DESTDIR}${COPYCAT}/
146 COPYCAT="/etc/rc.conf.d/network"
147 cd ${SCRIPTBASE}${COPYCAT} || exit 1
148 install -o root -g wheel -d -m 0755 ${DESTDIR}${COPYCAT} || exit 1
149 echo installing files into ${COPYCAT}
150 install -o root -g wheel -m 0644 * ${DESTDIR}${COPYCAT}/
152 chroot ${DESTDIR} passwd
153 chroot ${DESTDIR} adduser
155 read -p "Do you wish to open a shell ?" yn
159 * ) echo "Please answer yes or no.";;
161 chroot ${DESTDIR} tcsh