Skip to content

Instantly share code, notes, and snippets.

@binwiederhier
Forked from dasjoe/sbooblehat.sh
Last active April 23, 2017 07:51
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binwiederhier/9ba0983b392b6468504e9bbdf8ae0fa1 to your computer and use it in GitHub Desktop.
Save binwiederhier/9ba0983b392b6468504e9bbdf8ae0fa1 to your computer and use it in GitHub Desktop.
apt-get install debootstrap
fdisk /dev/sdb
o
n
<return>
<return>
<return>
w
zpool create \
-o ashift=9 \
-O normalization=formD \
-O atime=off \
-O canmount=off \
-O compression=lz4 \
-O recordsize=1M \
tank \
/dev/sdb1 # 1 !
zfs create tank/os
cd /tank/os
debootstrap xenial .
mount --rbind /dev dev
mount --rbind /sys sys
mount --rbind /proc proc
mount --rbind /run run
chroot .
<CHROOT>
cat /proc/mounts > /etc/mtab
for i in xenial xenial-{updates,security}; do echo "deb http://archive.ubuntu.com/ubuntu $i main restricted universe" >> /etc/apt/sources.list.d/ubuntu.list; done
echo > /etc/apt/sources.list
cat > /etc/udev/rules.d/70-zfs-grub-fix.rules << 'EOF'
KERNEL=="sd*[a-z]1|cciss*[a-z]1", ENV{DEVTYPE}=="partition", ENV{ID_SERIAL}=="?*", SYMLINK+="$env{ID_BUS}-$env{ID_SERIAL}"
EOF
udevadm trigger
for disk in /dev/disk/by-id/{ata,wwn}*; do name=$(basename $disk); device=$(readlink -f $disk); ln -sfn $device /dev/$name; done
apt-get update
apt install vim man htop zfsutils-linux zfs-dkms zfs-initramfs linux-image-generic grub-pc
echo "root:root" | chpasswd
</CHROOT>
zpool export tank
reboot
# Disable automatic installation of recommended or suggested packages
cat > /etc/apt/apt.conf.d/01norecommend <<EOF
APT::Install-Recommends "0";
APT::Install-Suggests "0";
EOF
# Get required tools, i.e. debootstrap and ZFS userspace tools
apt-get --quiet update
apt-get --yes --quiet install debootstrap zfsutils-linux dosfstools
hdparm --user-master u --security-set-pass Eins /dev/sda
time hdparm --user-master u --security-erase Eins /dev/sda
sleep 2
for disk in /dev/sda
do
sgdisk -a1 -n2:34:2047 -t2:EF02 -c2:grub \
"$disk"
sgdisk -n3:1M:+512M -t3:EF00 -c3:EFI \
-n9:-8M:0 -t9:BF07 -c9:reserved \
-n1:0:0 -t1:BF01 -c1:zfs \
"$disk"
zpool labelclear -f "$disk"1
done
zpool create \
-o ashift=9 \
-O normalization=formD \
-O atime=off \
-O canmount=off \
-O compression=lz4 \
-O mountpoint=/ \
-O recordsize=1M \
-R /mnt \
sbooblehat \
/dev/sda1
# Turn synchronous requests into async ones for faster installation
zfs set sync=disabled sbooblehat
zfs create -o canmount=off -o mountpoint=none sbooblehat/ROOT
zfs create -o canmount=noauto -o mountpoint=/ sbooblehat/ROOT/xenial
zfs mount sbooblehat/ROOT/xenial
zfs create -o setuid=off sbooblehat/home
zfs create sbooblehat/home/dasjoe
zfs create -o mountpoint=/root sbooblehat/home/root
zfs create -o canmount=off -o setuid=off -o exec=off sbooblehat/var
zfs create -o com.sun:auto-snapshot=false sbooblehat/var/cache
zfs create sbooblehat/var/log
zfs create sbooblehat/var/spool
zfs create -o com.sun:auto-snapshot=false -o exec=on sbooblehat/var/tmp
chmod 1777 /mnt/var/tmp
debootstrap xenial /mnt http://de.archive.ubuntu.com/ubuntu
zfs set devices=off sbooblehat
zfs snap sbooblehat/ROOT/xenial@install-debootstrap
# TODO: Replace with real host name
echo 'sbooblehat' > /mnt/etc/hostname
sed -i '1 a 127.0.1.1 sbooblehat' /mnt/etc/hosts
# Install a sane sources.list
cat > /mnt/etc/apt/sources.list <<'EOF'
deb http://de.archive.ubuntu.com/ubuntu xenial main restricted universe multiverse
deb http://de.archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiverse
deb http://de.archive.ubuntu.com/ubuntu xenial-updates main restricted universe multiverse
deb http://de.archive.ubuntu.com/ubuntu xenial-security main restricted universe multiverse
EOF
# Disable automatic installation of recommended or suggested packages
cat > /mnt/etc/apt/apt.conf.d/01norecommend <<'EOF'
APT::Install-Recommends "0";
APT::Install-Suggests "0";
EOF
echo 'LANG="en_US.UTF-8"' > /mnt/etc/default/locale
cat > /mnt/etc/default/grub <<'EOF'
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=3
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
#GRUB_CMDLINE_LINUX_DEFAULT="quiet noplymouth"
GRUB_CMDLINE_LINUX_DEFAULT="noplymouth"
GRUB_CMDLINE_LINUX=""
# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
# Uncomment to disable graphical terminal (grub-pc only)
GRUB_TERMINAL=console
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true
# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
EOF
# Prepare ESP
mkdosfs -F 32 -n EFI /dev/sda3
mkdir /mnt/boot/efi
echo PARTUUID=$(blkid -s PARTUUID -o value /dev/sda3) /boot/efi vfat defaults 0 1 >> /mnt/etc/fstab
mount /dev/sda3 /mnt/boot/efi
modprobe efivars
# Fix the chroot's mtab
ln -s /proc/mounts /mnt/etc/mtab
mount -t devtmpfs /dev /mnt/dev
mount -t devpts /dev/pts /mnt/dev/pts
mount -t sysfs /sys /mnt/sys
mount -t proc /proc /mnt/proc
mount -t tmpfs /run /mnt/run
# Create temporary resolv.conf by manually setting it up
# TODO: feel free to use a different name server, this is Google's
mkdir /mnt/run/resolvconf/
echo "nameserver 8.8.8.8" > /mnt/run/resolvconf/resolv.conf
chroot /mnt /bin/bash -l -- <<'EOF'
set -x
# TODO: replace with your locale needs
for locale in en_US.UTF-8 de_DE.UTF-8; do locale-gen "$locale"; done
# TODO: edit timezone
# This is a workaround for https://bugs.launchpad.net/ubuntu/+source/tzdata/+bug/1554806
ln -fs /usr/share/zoneinfo/Europe/Berlin /etc/localtime
dpkg-reconfigure -f noninteractive tzdata
# Update package cache and upgrade everything
apt-get --quiet update
apt-get --yes --quiet dist-upgrade
# Install a minimal but sane set of packages
# TODO: edit according your needs
apt-get --yes --quiet install \
ubuntu-minimal \
linux-image-generic \
zfsutils-linux \
zfs-initramfs \
openssh-server \
ssh-import-id \
tmux \
aptitude \
vim
# Install grub, force usage of our custom /etc/default/grub
DEBIAN_FRONTEND=noninteractive apt-get --yes --quiet \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
install grub-efi-amd64
addgroup --system lpadmin
addgroup --system sambashare
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck --no-floppy
adduser --disabled-password --gecos "Hajo Möller,,," --home /home/dasjoe dasjoe
usermod -a -G adm,sudo dasjoe
echo "dasjoe:dasjoe" | chpasswd
cp -ar /etc/skel/ /home/dasjoe/
chown -R dasjoe: /home/dasjoe
sudo -Hu dasjoe ssh-import-id dasjoe
# Disable password login via SSH
sed -i 's/^#\{0,1\}\(PasswordAuthentication\) .*/\1 no/g' /etc/ssh/sshd_config
# Install Xubuntu
mkdir -p /run/lock
aptitude install -y -q --with-recommends xubuntu-desktop
# FIXME: "Fix" broken blueman installation
apt-get --yes --quiet --auto-remove remove --purge blueman
exit
EOF
# Prepare zpool for export, unmount /run, /proc, /sys, /dev/pts and /dev
umount /mnt/run
umount /mnt/proc
umount /mnt/sys
umount /mnt/dev/pts
umount /mnt/dev
umount /mnt/boot/efi
zfs umount -a
umount /mnt
# Reset synchronous behaviour to ZFS defaults
zfs inherit sync sbooblehat
zfs snap sbooblehat/ROOT/xenial@install-done
zpool export sbooblehat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment