#!/bin/sh # # Calomel.org # https://calomel.org/zfs_freebsd_root_install.html # FreeBSD 9.2-RC3 ZFS Root Install script # zfs92.sh @ Version 0.13 echo "# remove any old partitions on destination drive" umount zroot umount /mnt zpool destroy zroot gpart delete -i 2 ada0 gpart delete -i 1 ada0 gpart destroy -F ada0 echo ENTER read a echo "" echo "# Create the boot and zfs data partitions" gpart create -s gpt ada0 gpart add -b 34 -s 94 -t freebsd-boot ada0 gpart add -t freebsd-zfs -l disk0 ada0 gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0 echo ENTER read a echo "" echo "# Align the Disks for 4K and create the pool" gnop create -S 4096 /dev/gpt/disk0 zpool create -f -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache zroot /dev/gpt/disk0.nop zpool export zroot gnop destroy /dev/gpt/disk0.nop zpool import -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache zroot echo ENTER read a echo "" echo "# Set the bootfs property and set options" zpool set bootfs=zroot zroot zpool set listsnapshots=on zroot zpool set autoreplace=on zroot zpool set autoexpand=on zroot zfs set checksum=fletcher4 zroot zfs set atime=off zroot zfs set copies=2 zroot echo ENTER read a # FreeBSD 9.2 and 10 Compression, ZFS v5 pool v5000 # zpool set feature@lz4_compress=enabled zroot zfs set compression=lz4 zroot echo ENTER read a echo "" echo "# Optional: add sub pools" zfs create zroot/usr zfs create zroot/usr/home zfs create zroot/var zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/var/log zfs create -o compression=lzjb -o exec=off -o setuid=off zroot/usr/src zfs set copies=1 zroot/usr/src zfs create -o compression=lzjb -o setuid=off zroot/usr/ports zfs set copies=1 zroot/usr/ports echo ENTER read a echo "" echo "# Add swap space and apply options" zfs create -V 1G zroot/swap zfs set org.freebsd:swap=on zroot/swap zfs set checksum=off zroot/swap zfs set copies=1 zroot/swap echo ENTER read a echo "" echo "# Create a symlink to /home and fix some permissions" cd /mnt ; ln -s usr/home home echo "" echo "# Install FreeBSD OS from *.txz memstick." echo "# This will take a few minutes..." cd /usr/freebsd-dist export DESTDIR=/mnt # Option 1: only install a 64bit os # for file in base.txz kernel.txz doc.txz ports.txz src.txz; # Option 2: also include 32bit compatable libs for file in base.txz lib32.txz kernel.txz doc.txz ports.txz src.txz; do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}); done echo ENTER read a echo "" echo "# Copy zpool.cache to install disk." cp /var/tmp/zpool.cache /mnt/boot/zfs/zpool.cache echo ENTER read a echo "" echo "# Setup ZFS root mount and boot" echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf echo 'zfs_load="YES"' >> /mnt/boot/loader.conf echo 'vfs.root.mountfrom="zfs:zroot"' >> /mnt/boot/loader.conf echo ENTER read a echo "" echo "# enable networking, allow ssh and stop syslog from listening." echo 'hostname="test"' >> /mnt/etc/rc.conf echo 'ifconfig_re0="inet 192.168.1.1 netmask 255.255.255.0"' >> /mnt/etc/rc.conf echo 'defaultrouter="192.168.1.254"' >> /mnt/etc/rc.conf echo 'sshd_enable="YES"' >> /mnt/etc/rc.conf echo 'syslogd_flags="-ss"' >> /mnt/etc/rc.conf #echo "" #echo "# sshd, disable remote root logins." #echo 'PermitRootLogin no' >> /mnt/etc/ssh/sshd_config #echo 'PermitEmptyPasswords no' >> /mnt/etc/ssh/sshd_config echo "" echo "# /etc/rc.conf disable sendmail" echo 'dumpdev="NO"' >> /mnt/etc/rc.conf echo 'sendmail_enable="NO"' >> /mnt/etc/rc.conf echo 'sendmail_submit_enable="NO"' >> /mnt/etc/rc.conf echo 'sendmail_outbound_enable="NO"' >> /mnt/etc/rc.conf echo 'sendmail_msp_queue_enable="NO"' >> /mnt/etc/rc.conf echo "" echo "# touch the /etc/fstab else freebsd will not boot properly" touch /mnt/etc/fstab sync echo "" echo "# Install Done. Syncing file system." sync #### EOF ####