Skip to content

Instantly share code, notes, and snippets.

@fdv
Created August 18, 2017 22:07
Show Gist options
  • Save fdv/404b79d22b6613c563a8a618aa2e912a to your computer and use it in GitHub Desktop.
Save fdv/404b79d22b6613c563a8a618aa2e912a to your computer and use it in GitHub Desktop.
#!/bin/bash
SWAP_SIZE=4g
TEMP_ROOT_PASSWORD="53nD0tt3rP1c5"
# Partition table
mfiutil delete mfid0
for drive in $(mfiutil show drives | grep -v SSD | awk '{print $1}'); do
mfiutil create jbod $drive
done
for i in {0..11}; do
gpart create -s gpt mfid$i
gpart add -t freebsd-boot -l boot -s 512K mfid$i
gpart add -t freebsd-swap -l swap -s $SWAP_SIZE -a 1m mfid$i
gpart add -t freebsd-zfs -l zfs$i mfid$i
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 mfid$i
dd if=/dev/zero of=mfid${i}p3 count=560 bs=512
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 mfid$i
done
zpool create -f -m none -o altroot=/mnt -o cachefile=/tmp/zpool.cache -O compress=lz4 -O atime=off zroot raidz2 gpt/zfs0 gpt/zfs1 gpt/zfs2 gpt/zfs3 gpt/zfs4 gpt/zfs5 gpt/zfs6 gpt/zfs7 gpt/zfs8 gpt/zfs9 gpt/zfs10
zpool add zroot spare gpt/zfs11
zfs create -o mountpoint=/ zroot/ROOT
zfs create -o mountpoint=/usr zroot/usr
zfs create -o mountpoint=/var zroot/var
zfs create -o mountpoint=/tmp zroot/tmp
zfs create -o mountpoint=/www zroot/www
zfs create -o mountpoint=/usr/home zroot/usr/home
zfs create -o mountpoint=/srv zroot/srv
zpool set bootfs=zroot/ROOT zroot
# Bootstrap
cd /mnt
fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/11.1-RELEASE/base.txz
fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/11.1-RELEASE/kernel.txz
tar --unlink -Jxpf base.txz -C /mnt
tar --unlink -Jxpf kernel.txz -C /mnt
rm base.txz kernel.txz
# Configuration
## fstab && swap
cat << EOF > /mnt/etc/fstab
mfid0p2 none swap sw 0 0
EOF
## rc.conf
cat << EOF > /mnt/etc/rc.conf
ifconfig_ix0="DHCP"
ifconfig_ix1="DHCP"
fsck_y_enable="YES"
background_fsck="YES"
zfs_enable="YES"
sshd_enable="YES"
EOF
## loader.conf
cat << EOF > /mnt/boot/loader.conf
zfs_load="YES"
vfs.root.mountfrom="zfs:zroot/ROOT"
boot_multicons="YES"
boot_serial="YES"
comconsole_speed="9600"
console="comconsole"
comconsole_port="0x2F8"
EOF
## TTY pour la console série (fais moi peur)
cat << EOF >> /mnt/etc/ttys
ttyu1 "/usr/libexec/getty std.9600" vt100 on secure
EOF
## tmp root pass
echo "$TEMP_ROOT_PASSWORD" | pw -R /mnt user mod -n root -h 0
## The final condom
cd ~
zpool export zroot
zpool import -o altroot=/mnt -o cachefile=/tmp/zpool.cache zroot
cp /tmp/zpool.cache /mnt/boot/zfs
halt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment