From bc0d29539d4798099817fb6640b4f9815dde47e3 Mon Sep 17 00:00:00 2001 From: sean Date: Mon, 8 Jul 2019 19:24:45 -0700 Subject: [PATCH] Untested - unfinished, just saving state --- setup.sh | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 150 insertions(+), 6 deletions(-) diff --git a/setup.sh b/setup.sh index d71f438..3672d62 100644 --- a/setup.sh +++ b/setup.sh @@ -25,15 +25,159 @@ height=`tput lines` # set line separator IFS=$'\n' - devices=""; for device in $(ls /dev/disk/by-id | grep -v part); do devices="$devices $device off"; done -disks=`dialog --separate-output --no-collapse --no-items --title "Root devices" --checklist "Select boot drives" $height $width ${window}$devices 2>&1 1>/dev/tty` +disks=`dialog --separate-output --no-cancel --no-items --title "Root devices" --checklist "Select boot drives" $height $width ${window}$devices 2>&1 1>/dev/tty` +hostname=""; while [ -z "$hostname" ]; do result=`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` for disk in "$disks"; do # remove echo for testing echo "Partitioning disk $disk..." - echo "sgdisk --zap-all /dev/disk/by-id/$disk >/dev/null 2>/dev/null" - echo "sgdisk -n2:1M:+512M -t2:EF00 /dev/disk/by-id/$disk >/dev/null 2>/dev/null" - echo "sgdisk -n3:0:+512M -t3:BF01 /dev/disk/by-id/$disk >/dev/null 2>/dev/null" + # collect the return values, check them for errors and display them + echo "sgdisk --zap-all /dev/disk/by-id/$disk >/dev/null 2>&1" + echo "sgdisk -n2:1M:+512M -t2:EF00 /dev/disk/by-id/$disk >/dev/null 2>&1" + echo "sgdisk -n3:0:+512M -t3:BF01 /dev/disk/by-id/$disk >/dev/null 2>&1" + echo "sgdisk -n4:0:0 -t4:BF01 /dev/disk/by-id/$disk >/dev/null 2>&1" echo "Done." -done \ No newline at end of file +done + +# create boot mirror list +bootmirror=""; for disk in "$disks": do bootmirror="$bootmirror /dev/disk/by-id/${disk}-part3"; done + +rootraidz=""; for disk in "$disks"; do rootraidz="$rootraidz /dev/disk/by-id/${disk}-part4"; done + +echo "zpool create -f -o ashift=12 -d -o feature@async_destroy=enable -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" + +raidtype=`dialog --no-items --no-cancel --title "Root pool ZFS RAID" --radiolist "Select root pool ZFS RAID type" 11 35 4 raidz off raidz2 off mirror off none off 2>&1 1>/dev/tty` +if [ "$raidtype" = "none" ]; then + raidtype="" +else + raidtype=" $raidtype" +fi + +# test for boot pool creation + +echo "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}" + +#zfs create -o canmount=off -o mountpoint=none rpool/ROOT +#zfs create -o canmount=off -o mountpoint=none bpool/BOOT +# zfs create -o canmount=noauto -o mountpoint=/ rpool/ROOT/ubuntu +# zfs mount rpool/ROOT/ubuntu +# zfs create -o canmount=noauto -o mountpoint=/boot bpool/BOOT/ubuntu +# zfs mount bpool/BOOT/ubuntu +# zfs create rpool/home +# zfs create -o mountpoint=/root rpool/home/root +# zfs create -o canmount=off rpool/var +# zfs create -o canmount=off rpool/var/lib +# zfs create rpool/var/log +# zfs create rpool/var/spool +# zfs create -o com.sun:auto-snapshot=false rpool/var/cache +# zfs create -o com.sun:auto-snapshot=false rpool/var/tmp +# chmod 1777 /mnt/var/tmp +# zfs create rpool/opt +# zfs create rpool/srv +# zfs create -o canmount=off rpool/usr +# zfs create rpool/usr/local +# zfs create rpool/var/mail +# zfs create -o com.sun:auto-snapshot=false rpool/var/lib/docker +# zfs create -o com.sun:auto-snapshot=false rpool/var/lib/nfs +# zfs create -o com.sun:auto-snapshot=false rpool/tmp +# chmod 1777 /mnt/tmp +# debootstrap bionic /mnt +# zfs set devices=off rpool +# echo HOSTNAME > /mnt/etc/hostname +# echo "127.0.1.1 $hostname" >> /mnt/etc/hosts +# vi /mnt/etc/hosts +# echo "deb http://archive.ubuntu.com/ubuntu bionic main universe\ndeb-src http://archive.ubuntu.com/ubuntu bionic main universe\ndeb http://security.ubuntu.com/ubuntu bionic-security main universe\ndeb-src http://security.ubuntu.com/ubuntu bionic-security main universe\ndeb http://archive.ubuntu.com/ubuntu bionic-updates main universe\ndeb-src http://archive.ubuntu.com/ubuntu bionic-updates main universe" > /mnt/etc/apt/sources.list + +# you really need static config here too! + +macaddr=$(echo $hostname|md5sum|sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/') +network="network:\n version: 2\n renderer: networkd\n ethernets:" +for nic in "$nicdevices"; do + network="$network\n ${nic}:\n dhcp4: no" +done +network="$network\n bridges:\n br0:\n macaddress: ${macaddr}\n dhcp4: yes\n parameters:\n stp: true\n interfaces:" +for nic in "$nicdevices";l do + network="$network\n - ${nic}" +done +# echo "$network" > /mnt/etc/netplan/bridge.yaml + +# mount --rbind /dev /mnt/dev +# mount --rbind /proc /mnt/proc +# mount --rbind /sys /mnt/sys +# chroot /mnt /bin/bash --login + +# ln -s /proc/self/mounts /etc/mtab +# apt update + +#echo -e 'LANG="en_US.UTF-8"\nLANGUAGE="en_US:en"\n' > /etc/default/locale +#dpkg-reconfigure tzdata +#apt install -y --no-install-recommends linux-image-generic +#apt install -y vim bash screen tmux zfs-initramfs dosfstools openssh-server +i="0" +for disk in "$disks"; do + echo "mkdosfs -F 32 -s 1 -n EFI /dev/disk/by-id/${disk}-part2" + echo "mkdir /boot/efi${i}" + echo "echo PARTUUID=$(blkid -s PARTUUID -o value /dev/disk/by-id/${disk}-part2) /boot/efi${i} vfat nofail,x-systemd.device-timeout=0 0 1 >> /etc/fstab" + echo "mount /boot/efi${i}" + i=$((i + 1)) +done + +#apt install -y grub-efi-amd64-signed shim-signed +#passwd + +#echo "[Unit]\n DefaultDependencies=no\n Before=zfs-import-scan.service\n Before=zfs-import-cache.service\n \n [Service]\n Type=oneshot\n RemainAfterExit=yes\n ExecStart=/sbin/zpool import -N -o cachefile=none bpool\n [Install]\n WantedBy=zfs-import.target " > /etc/systemd/system/zfs-import-bpool.Service" +#systemctl enable zfs-import-bpool.Service + +#cp /usr/sharesystemd/tmp.mount /etc/systemd/system/ +#systemctl enable tmp.mount +#addgroup --system lpadmin +#addgroup --system sambashare + +zfscheck=`grub-probe /boot` +#update-initramfs -u -k all + +# you need sed to do this right! +# GRUB_CMDLINE_LINUX="root=ZFS=rpool/ROOT/ubuntu" <--- replace this + +#update-grub +i="0" +for f in "$disks"; do + echo "grub-install --target=x86_64-efi --efi-directory=/boot/efi${i} --botloader-id=ubuntu --recheck --no-floppy" + echo "umount /boot/efi${i}" + i=$((i + 1)) +done + +#zfs set mountpoint=legacy bpool/BOOT/ubuntu +#echo bpool/BOOT/ubuntu /boot zfs nodev,relatime,x-systemd.requires=zfs-import-bpool.service 0 0 >> /etc/fstab +#zfs set mountpoint=legacy rpool/var/log +#echo rpool/var/log /var/log zfs nodev,relatime 0 0 >> /etc/fstab +#zfs set mountpoint=legacy rpool/var/spool +#echo rpool/var/spool /var/spool zfs nodev,relatime 0 0 >> /etc/fstab +#zfs set mountpoint=legacy rpool/var/tmp +#echo rpool/var/tmp /var/tmp zfs nodev,relatime 0 0 >> /etc/fstab +#zfs set mountpoint=legacy rpool/tmp +#echo rpool/tmp /tmp zfs nodev,relatime 0 0 >> /etc/fstab +#systemctl enable openssh-server + + + +# create parker user automated way +#zfs create rpool/home/YOURUSERNAME +# adduser YOURUSERNAME +# cp -a /etc/skel/.[!.]* /home/YOURUSERNAME +# chown -R YOURUSERNAME:YOURUSERNAME /home/YOURUSERNAME +# usermod -a -G adm,cdrom,dip,lpadmin,plugdev,sambashare,sudo YOURUSERNAME + +#create swap space, too if necessary + + + + +#exit +#mount | grep -v zfs | tac | awk '/\/mnt/ {print $3}' | xargs -i{} umount -lf {} +#zpool export -a +#reboot +