mirror of
https://github.com/hukl/freebsd-toolbox.git
synced 2025-11-20 03:08:43 +01:00
Update zfs_bootstrap.sh
This commit is contained in:
@ -1,9 +1,14 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# Check:
|
# Check:
|
||||||
# https://wiki.freebsd.org/RootOnZFS/GPTZFSBoot/Mirror
|
# https://wiki.freebsd.org/RootOnZFS/GPTZFSBoot/9.0-RELEASE
|
||||||
# http://wp.strahlert.net/wordpress/zfs-2/expanding-zpool/
|
# http://wp.strahlert.net/wordpress/zfs-2/expanding-zpool/
|
||||||
|
|
||||||
|
# Tested on FreeBSD 10 and 11
|
||||||
|
|
||||||
|
###############################################################
|
||||||
|
# WARNING: Go through line by line and adjust where necessary #
|
||||||
|
###############################################################
|
||||||
|
|
||||||
# Create Partition Table
|
# Create Partition Table
|
||||||
echo "Create Partition Table"
|
echo "Create Partition Table"
|
||||||
@ -17,14 +22,14 @@ gpart create -s gpt ada1 # Main HDD
|
|||||||
|
|
||||||
# Create Boot Partition
|
# Create Boot Partition
|
||||||
echo "Create Boot Partition"
|
echo "Create Boot Partition"
|
||||||
gpart add -a 4k -s 64k -t freebsd-boot ada0
|
gpart add -a 4k -s 512k -t freebsd-boot ada0
|
||||||
gpart add -a 4k -s 64k -t freebsd-boot ada1
|
gpart add -a 4k -s 512k -t freebsd-boot ada1
|
||||||
|
|
||||||
|
|
||||||
# Create Swap Partitions
|
# Create Swap Partitions
|
||||||
echo "Create Swap Partitions"
|
echo "Create Swap Partitions"
|
||||||
gpart add -a 4k -s 4G -t freebsd-swap -l swap0 ada0
|
gpart add -a 4k -s 8G -t freebsd-swap -l swap0 ada0
|
||||||
gpart add -a 4k -s 4G -t freebsd-swap -l swap1 ada1
|
gpart add -a 4k -s 8G -t freebsd-swap -l swap1 ada1
|
||||||
|
|
||||||
|
|
||||||
# Create Main Partitions
|
# Create Main Partitions
|
||||||
@ -51,15 +56,23 @@ gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada1
|
|||||||
# gpart add -a 4k -t freebsd-zfs -l l2arc1 ada3
|
# gpart add -a 4k -t freebsd-zfs -l l2arc1 ada3
|
||||||
|
|
||||||
|
|
||||||
|
# Load ZFS extensions
|
||||||
|
kldload opensolaris.ko
|
||||||
|
kldload zfs.ko
|
||||||
|
|
||||||
|
|
||||||
|
# Force ZFS to use 4k sectors
|
||||||
|
sysctl vfs.zfs.min_auto_ashift=12
|
||||||
|
|
||||||
# Create ZFS Pool
|
# Create ZFS Pool
|
||||||
echo "Create ZFS Pool"
|
echo "Create ZFS Pool"
|
||||||
zpool create tank mirror /dev/gpt/disk0 /dev/gpt/disk1
|
zpool create -f tank mirror /dev/gpt/disk0 /dev/gpt/disk1
|
||||||
|
|
||||||
# Set proper mountpoint
|
# Set proper mountpoint
|
||||||
echo "Setting Mountpoint"
|
echo "Setting Mountpoint"
|
||||||
zfs set mountpoint=/ tank
|
zfs set mountpoint=/ tank
|
||||||
|
|
||||||
# Export and import the Pool
|
# Export and import the Pool
|
||||||
zpool export tank
|
zpool export tank
|
||||||
zpool import -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache tank
|
zpool import -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache tank
|
||||||
|
|
||||||
@ -67,7 +80,6 @@ zpool import -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache tank
|
|||||||
echo "Enabling Compression"
|
echo "Enabling Compression"
|
||||||
zfs set compression=lz4 tank
|
zfs set compression=lz4 tank
|
||||||
|
|
||||||
|
|
||||||
# Add ZIL and L2ARC
|
# Add ZIL and L2ARC
|
||||||
# echo "Add ZIL and L2ARC"
|
# echo "Add ZIL and L2ARC"
|
||||||
# zpool add tank log mirror /dev/gpt/zil0 /dev/gpt/zil1
|
# zpool add tank log mirror /dev/gpt/zil0 /dev/gpt/zil1
|
||||||
@ -85,21 +97,29 @@ echo "Installing FreeBSD"
|
|||||||
cd /usr/freebsd-dist
|
cd /usr/freebsd-dist
|
||||||
export DESTDIR=/mnt
|
export DESTDIR=/mnt
|
||||||
for f in base.txz lib32.txz kernel.txz doc.txz ports.txz src.txz;do
|
for f in base.txz lib32.txz kernel.txz doc.txz ports.txz src.txz;do
|
||||||
(cat $f | tar --unlink -xvpJf - -C ${DESTDIR:-/});
|
(cat $f | tar --unlink -xvpJf - -C ${DESTDIR:-/});
|
||||||
done
|
done
|
||||||
|
|
||||||
cp /var/tmp/zpool.cache /mnt/boot/zfs/
|
cp /var/tmp/zpool.cache /mnt/boot/zfs/
|
||||||
|
|
||||||
|
echo "Enter hostname FQDN"
|
||||||
|
read HOSTNAME
|
||||||
|
|
||||||
|
echo "Enter last public IP octet"
|
||||||
|
read IP_ENDING
|
||||||
|
|
||||||
|
echo "Enter username"
|
||||||
|
read USERNAME
|
||||||
|
|
||||||
cat > /mnt/etc/rc.conf << RCCONF
|
cat > /mnt/etc/rc.conf << RCCONF
|
||||||
hostname="my.host.name"
|
hostname="$HOSTNAME"
|
||||||
|
|
||||||
zfs_enable="YES"
|
zfs_enable="YES"
|
||||||
|
|
||||||
# Network
|
# Network
|
||||||
|
|
||||||
defaultrouter="xxx.xxx.xxx.xxx"
|
defaultrouter="0.0.0.0"
|
||||||
ifconfig_em1="inet xxx.xxx.xxx.xxx/xx"
|
ifconfig_igb0="inet 0.0.0.$IP_ENDING/32"
|
||||||
|
|
||||||
# Services
|
# Services
|
||||||
sendmail_enable="NONE"
|
sendmail_enable="NONE"
|
||||||
@ -114,8 +134,43 @@ cat > /mnt/etc/fstab << FSTAB
|
|||||||
FSTAB
|
FSTAB
|
||||||
|
|
||||||
|
|
||||||
cat > /mnt/boot/loader.conf << LOADER
|
cat >> /mnt/boot/loader.conf << LOADER
|
||||||
zfs_load="YES"
|
zfs_load="YES"
|
||||||
vfs.root.mountfrom="zfs:tank"
|
vfs.root.mountfrom="zfs:tank"
|
||||||
vfs.zfs.arc_max="16G"
|
vfs.zfs.arc_max="8G"
|
||||||
LOADER
|
LOADER
|
||||||
|
|
||||||
|
cat >> /mnt/etc/sysctl.conf << SYSCTL
|
||||||
|
vfs.zfs.min_auto_ashift=12
|
||||||
|
SYSCTL
|
||||||
|
|
||||||
|
|
||||||
|
cat > /mnt/etc/resolv.conf << RESOLV
|
||||||
|
nameserver 0.0.0.0
|
||||||
|
nameserver 0.0.0.0
|
||||||
|
RESOLV
|
||||||
|
|
||||||
|
|
||||||
|
# Mount a devfs to have /dev/random /dev/zero etc in our chroot
|
||||||
|
mount -t devfs none /mnt/dev
|
||||||
|
|
||||||
|
# Bootstap pkg and install minimal packages for ansible
|
||||||
|
chroot -u root -g wheel /mnt/ env ASSUME_ALWAYS_YES=YES pkg bootstrap
|
||||||
|
chroot -u root -g wheel /mnt/ env ASSUME_ALWAYS_YES=YES pkg install sudo zsh
|
||||||
|
|
||||||
|
# Add user
|
||||||
|
chroot -u root -g wheel /mnt/ pw useradd -n $USERNAME -u 1001 -s /usr/local/bin/zsh -m -d /home/$USERNAME -G wheel -h 0
|
||||||
|
|
||||||
|
# Fetch user pub key from github
|
||||||
|
mkdir -p /mnt/home/$USERNAME/.ssh
|
||||||
|
|
||||||
|
# This fetches the pub key from the sepcified github users and adds them
|
||||||
|
# to the .authorized_keys of the new system user
|
||||||
|
echo "List of Github users for pubkey retrieval (space separated):"
|
||||||
|
read users
|
||||||
|
|
||||||
|
for user in $users; do
|
||||||
|
fetch https://github.com/$user.keys --no-verify-peer -o - >> /mnt/home/deploy/.ssh/authorized_keys
|
||||||
|
done
|
||||||
|
|
||||||
|
chown -R 1001:1001 /mnt/home/$USERNAME/.ssh
|
||||||
|
|||||||
Reference in New Issue
Block a user