| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- #!/bin/sh
- DESTDISK="ada0"
- DESTDIR="/mnt/zfs"
- ZPOOL="zroot"
- SCRIPTBASE=${PWD}
- # check if the zpool already exists
- ZPOOL_EXISTS=` zpool list -H | cut -f 1 | grep "${ZPOOL}"`
- if [ "${?}" -ne 1 ]; then
- echo "One zpool called ${ZPOOL} already exists, you have to destroy it first:"
- echo " # zpool destroy ${ZPOOL}"
- exit 1
- fi
- # check if the disk is ok for writing
- echo checking sanity ${DESTDISK}
- echo =============
- gpart show ${DESTDISK} 1>/dev/null
- if [ "${?}" -eq 0 ]; then
- gpart destroy -F ${DESTDISK}
- if [ "${?}" -ne 0 ]; then
- echo unable to reset ${DESTDISK}
- exit 1
- fi
- fi
- echo partitioning ${DESTDISK}
- echo =============
- gpart create -s gpt ${DESTDISK}
- gpart add -a 4k -t freebsd-boot -s 512k -l gptboot0 ${DESTDISK}
- gpart add -a 1m -s 32G -t freebsd-swap -l swap0 ${DESTDISK}
- gpart add -a 1m -t freebsd-zfs -l zfs0 ${DESTDISK}
- gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ${DESTDISK}
- gpart set -a active ${DESTDISK}
- gpart show ${DESTDISK}
- sysctl vfs.zfs.min_auto_ashift=12
- echo set up zfs pool: ${ZPOOL} alt mount: ${DESTDIR}
- echo =================
- zpool create -m none -f -R ${DESTDIR} ${ZPOOL} ${DESTDISK}p3 ada1
- if [ "${?}" -ne 0 ]; then
- echo "unable to create zpool"
- exit 1
- fi
- for I in ROOT VAR HOME DATA; do
- zfs create -o mountpoint=none -o canmount=off ${ZPOOL}/${I}
- done
- zfs create -o atime=off -o mountpoint=/ ${ZPOOL}/ROOT/master
- zfs create -o mountpoint=/usr/obj ${ZPOOL}/ROOT/obj
- zfs create -o compression=off -o mountpoint=/usr/src ${ZPOOL}/ROOT/src
- zfs create -o mountpoint=/usr/doc -o compression=on ${ZPOOL}/ROOT/doc
- # useless ? as far /tmp mountpoint will be mounted by tmpfs
- zfs create -o mountpoint=/tmp ${ZPOOL}/ROOT/tmp
- zfs create -o mountpoint=/usr/local ${ZPOOL}/LOCAL
- zfs create -o mountpoint=/usr/local/etc ${ZPOOL}/LOCAL/config
- zfs create -o mountpoint=/var ${ZPOOL}/VAR/master
- zfs create -o mountpoint=/var/crash ${ZPOOL}/VAR/crash
- zfs create -o exec=off -o setuid=off -o mountpoint=/var/db ${ZPOOL}/VAR/db
- zfs create -o compression=lz4 -o exec=on -o setuid=off -o mountpoint=/var/db/pkg ${ZPOOL}/VAR/db/pkg
- zfs create -o compression=on -o exec=off -o setuid=off -o mountpoint=/var/mail ${ZPOOL}/VAR/mail
- zfs create -o compression=on -o exec=off -o setuid=off -o mountpoint=/var/log ${ZPOOL}/VAR/log
- zfs create -o exec=off -o setuid=off -o mountpoint=/var/run ${ZPOOL}/VAR/run
- zfs create -o exec=off -o setuid=off -o mountpoint=/var/tmp ${ZPOOL}/VAR/tmp
- zfs create -o mountpoint=/usr/home ${ZPOOL}/HOME/master
- zpool set bootfs=${ZPOOL}/ROOT/master ${ZPOOL}
- chmod 1777 ${DESTDIR}/tmp ${DESTDIR}/var/tmp
- zfs list -r ${ZPOOL}
- cd ${DESTDIR}/tmp
- if [ "${?}" -ne 0 ]; then
- echo zfs mountpoints arent ready
- exit 1
- fi
- echo Fetching and Extracting base files into ${DESTDIR}
- echo =======================================
- for I in base.txz kernel.txz lib32.txz; do
- fetch http://ftp.freebsd.org/pub/FreeBSD/releases/amd64/11.2-RELEASE/${I}
- tar --unlink -pJxf ${I} -C ${DESTDIR}
- done
- echo writing configuration files
- echo ==========================
- cat << EOF >> ${DESTDIR}/etc/fstab
- /dev/${DESTDISK}p2 none swap sw 0 0
- tmpfs /tmp tmpfs rw,mode=1777 0 0
- EOF
- cat << EOF >> ${DESTDIR}/boot/loader.conf
- zfs_load=YES
- tmpfs_load=YES
- EOF
- cat << EOF >> ${DESTDIR}/boot/loader.conf.local
- vfs.root.mountfrom="zfs:${ZPOOL}/ROOT/master"
- EOF
- cat << EOF >> ${DESTDIR}/etc/rc.conf
- sshd_enable="YES"
- sendmail_enable="NONE"
- kld_list="vmm cuse4bsd cpuctl filemon"
- ntpd_enable="YES"
- # Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
- dumpdev="AUTO"
- zfs_enable="YES"
- EOF
- cd ${SCRIPTBASE}
- for I in resolv.conf rc.conf.local; do
- if [ -r "${I}" ]; then
- echo installing ${I}
- install -o root -g wheel -m 0644 ${I} ${DESTDIR}/etc/
- fi
- done
- for I in loader.conf.local; do
- if [ -r "${I}" ]; then
- echo installing ${I}
- install -o root -g wheel -m 0644 ${I} ${DESTDIR}/boot/
- fi
- done
- echo installing rc.conf.d
- install -o root -g wheel -d -m 0755 ${DESTDIR}/etc/rc.conf.d
- if [ -d "./rc.conf.d" ]; then
- echo installing files into rc.conf.d
- install -o root -g wheel -m 0644 ./rc.conf.d/* ${DESTDIR}/etc/rc.conf.d/
- fi
- chroot ${DESTDIR} passwd
- chroot ${DESTDIR} adduser
- read -p "Do you wish to open a shell ?" yn
- case $yn in
- [Nn]* ) exit 0;;
- [Yy]* ) ;;
- * ) echo "Please answer yes or no.";;
- esac
- chroot ${DESTDIR} tcsh
- exit 0
|