From 8f6ae4707d0a9bb9f8a378e5ce5dc7ce05c105a6 Mon Sep 17 00:00:00 2001 From: sean Date: Tue, 9 Jul 2019 17:59:06 -0700 Subject: [PATCH] tweaks --- setup.sh | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/setup.sh b/setup.sh index 36f45ab..ea371a0 100644 --- a/setup.sh +++ b/setup.sh @@ -1,8 +1,5 @@ #! /bin/bash -#IFS=$'\n' - -# fresh update on apt in Ubuntu echo "" echo "Updating local packages..." errors=`apt-add-repository universe >/dev/null 2>/dev/null && apt update >/dev/null 2>/dev/null` @@ -28,25 +25,19 @@ width=`tput cols` height=`tput lines` window=$((height - 5)) -# set line separator +# gather input at the start devices=""; for device in $(ls /dev/disk/by-id | grep -v part); do devices="$devices $device off"; done disks=`dialog --separate-output --no-cancel --no-items --title "Root devices" --checklist "Select boot drives" $height $width ${window}$devices 2>&1 1>/dev/tty` raidtype=`dialog --no-items --no-cancel --title "Root pool ZFS RAID" --radiolist "Select root pool ZFS RAID type" 12 35 5 raidz off raidz2 off raidz3 off mirror off none off 2>&1 1>/dev/tty` - hostname=""; while [ -z "$hostname" ]; do hostname=`dialog --no-cancel --inputbox "Host name/Server name" 8 100 2>&1 >/dev/tty`; done nicdevices=""; for nic in $(ip -o link show | awk -F': ' '{print $2}' | grep -v '^lo'); do nicdevices="$nicdevices $nic off"; done nics=`dialog --separate-output --no-cancel --no-items --title "Network devices for bridge" --checklist "Select the network devices to be bridged" $height $width ${window}$nicdevices 2>&1 1>/dev/tty` - rootpassword=`dialog --no-cancel --title "Root password" --passwordbox "Enter root password" $height $width 2>&1 1>/dev/tty` - timezone=`dialog --no-cancel --title "Timezone" --inputbox "Enter time zone" $height $width "America/Los_Angeles" 2>&1 1>/dev/tty` - for disk in `echo "$disks"`; do - # remove echo for testing echo "" echo "Partitioning disk $disk..." - # collect the return values, check them for errors and display them errors=`sgdisk --zap-all /dev/disk/by-id/$disk 2>&1 1>/dev/null && sgdisk -n2:1M:+512M -t2:EF00 /dev/disk/by-id/$disk 2>&1 1>/dev/null && sgdisk -n3:0:+512M -t3:BF01 /dev/disk/by-id/$disk 2>&1 1>/dev/null && sgdisk -n4:0:0 -t4:BF01 /dev/disk/by-id/$disk 2>&1 1>/dev/null` if ! [ "$?" = "0" ]; then echo "Failed to partition disk $disk - $errors" @@ -58,19 +49,9 @@ done # create boot mirror list bootmirror=""; rootraidz=""; for disk in `echo "$disks"`; do bootmirror="$bootmirror /dev/disk/by-id/${disk}-part3"; rootraidz="$rootraidz /dev/disk/by-id/${disk}-part4"; done -# refresh drives +# refresh drives or there are missing partitions partprobe 2>/dev/null 1>/dev/null -# wait for the partitions to show up -#for disk in `echo "$disks"` -#do# -# while ! [ -e "/dev/disk/by-id/${disk}-part3" ]; do -# sleep 1s -# done -#done - -#ls -l /dev/disk/by-id | grep part3 - echo "" echo "Creating boot zpool..." errors=`zpool create -f -o ashift=12 -d -o feature@async_destroy=enabled -o feature@bookmarks=enabled -o feature@embedded_data=enabled -o feature@empty_bpobj=enabled -o feature@enabled_txg=enabled -o feature@extensible_dataset=enabled -o feature@filesystem_limits=enabled -o feature@hole_birth=enabled -o feature@large_blocks=enabled -o feature@lz4_compress=enabled -o feature@spacemap_histogram=enabled -o feature@userobj_accounting=enabled -O acltype=posixacl -O canmount=off -O compression=lz4 -O devices=off -O normalization=formD -O relatime=on -O xattr=sa -O mountpoint=/ -R /mnt bpool mirror$bootmirror 2>&1 1>/dev/null` @@ -80,14 +61,13 @@ if ! [ "$?" = "0" ]; then fi echo "Done." +# special exception for none raid - this just operates the disks like a stripe, for 1 or more disk - *not* recommended if [ "$raidtype" = "none" ]; then raidtype="" else raidtype=" $raidtype" fi -# test for boot pool creation - echo "" echo "Creating main zpool..." error=`zpool create -f -o ashift=12 -O acltype=posixacl -O canmount=off -O compression=lz4 -O dnodesize=auto -O normalization=formD -O relatime=on -O xattr=sa -O mountpoint=/ -R /mnt rpool${raidtype}${rootraidz} 2>&1 1>/dev/null` @@ -100,7 +80,6 @@ echo "Done." echo "" echo "Setting up main zpool dataset configuration..." errors=`zfs create -o canmount=off -o mountpoint=none rpool/ROOT 2>&1 1>/dev/null && zfs create -o canmount=off -o mountpoint=none bpool/BOOT 2>&1 1>/dev/null && zfs create -o canmount=noauto -o mountpoint=/ rpool/ROOT/ubuntu 2>&1 1>/dev/null && zfs mount rpool/ROOT/ubuntu 2>&1 1>/dev/null && zfs create -o canmount=noauto -o mountpoint=/boot bpool/BOOT/ubuntu 2>&1 1>/dev/null && zfs mount bpool/BOOT/ubuntu 2>&1 1>/dev/null && zfs create rpool/home 2>&1 1>/dev/null && zfs create -o mountpoint=/root rpool/home/root 2>&1 1>/dev/null && zfs create -o canmount=off rpool/var 2>&1 1>/dev/null && zfs create -o canmount=off rpool/var/lib 2>&1 1>/dev/null && zfs create rpool/var/log 2>&1 1>/dev/null && zfs create rpool/var/spool 2>&1 1>/dev/null && zfs create -o com.sun:auto-snapshot=false rpool/var/cache 2>&1 1>/dev/null && zfs create -o com.sun:auto-snapshot=false rpool/var/tmp 2>&1 1>/dev/null && chmod 1777 /mnt/var/tmp 2>&1 1>/dev/null && zfs create rpool/opt 2>&1 1>/dev/null && zfs create rpool/srv 2>&1 1>/dev/null && zfs create -o canmount=off rpool/usr 2>&1 1>/dev/null && zfs create rpool/usr/local 2>&1 1>/dev/null && zfs create rpool/var/mail 2>&1 1>/dev/null && zfs create -o com.sun:auto-snapshot=false rpool/var/lib/docker 2>&1 1>/dev/null && zfs create -o com.sun:auto-snapshot=false rpool/var/lib/nfs 2>&1 1>/dev/null && zfs create -o com.sun:auto-snapshot=false rpool/tmp 2>&1 1>/dev/null && chmod 1777 /mnt/tmp 2>&1 1>/dev/null` - if ! [ "$?" = "0" ]; then echo "Error setting up ZFS settings - $errors" exit 5 @@ -142,7 +121,7 @@ echo "deb http://archive.ubuntu.com/ubuntu bionic-updates main universe" >> /mnt echo "deb-src http://archive.ubuntu.com/ubuntu bionic-updates main universe" >> /mnt/etc/apt/sources.list echo "Done." -# you really need static config here too! +# network configuration should have optional static configuration - not just DHCP, it's very important echo "" echo "Writing netplan file" @@ -184,7 +163,7 @@ echo "echo \"\"" >> /mnt/setup-chroot.sh echo "echo \"Updating apt repositories inside chroot...\"" >> /mnt/setup-chroot.sh echo "errors=`apt update 2>&1 1>/dev/null`" >> /mnt/setup-chroot.sh echo "if ! [ \"\$?\" = \"0\" ]; then ">> /mnt/setup-chroot.sh -echo " echo \"Failed to update apt repositories inside chroot - $errors\"" >> /mnt/setup-chroot.sh +echo " echo \"Failed to update apt repositories inside chroot - \$errors\"" >> /mnt/setup-chroot.sh echo " exit 1">> /mnt/setup-chroot.sh echo "fi">> /mnt/setup-chroot.sh echo "echo \"Done.\"">> /mnt/setup-chroot.sh @@ -218,7 +197,11 @@ echo "exit 0" >> /mnt/setup-chroot.sh #addgroup --system lpadmin #addgroup --system sambashare -#zfscheck=`grub-probe /boot` +echo "echo \"Checking ZFS root...\"" >> /mnt/setup-chroot.sh +echo "zfscheck=`grub-probe /boot 2>&1 1>/dev/null`" >> /mnt/setup-chroot.sh +echo "if ! [ \"\$?\" = \"0\" ]; then echo \"grub-probe check failed - \$zfscheck\"; exit 2; fi" >> /mnt/setup-chroot.sh +echo "echo \"Success.\"" >> /mnt/setup-chroot.sh + echo "update-initramfs -u -k all" >> /mnt/setup-chroot.sh # you need sed to do this right!