Skip to content

Instantly share code, notes, and snippets.

@asachs
Created January 11, 2019 15:20
Show Gist options
  • Save asachs/83493aca4c9dbe1305ba56f8956ad6bb to your computer and use it in GitHub Desktop.
Save asachs/83493aca4c9dbe1305ba56f8956ad6bb to your computer and use it in GitHub Desktop.
# Install the 'parted' parition editor
apt-get update && apt-get install -y parted zfs-dkms zfs-initramfs
# make the big partition that is going to be the ZFS participant
range=$(parted -sm /dev/sda unit S print free | tail -n 1 | awk -F: '{print $2 " "$3}')
for d in `ls /dev/sd?`;
do
parted -s $d mkpart primary $range;
done
# Create a ZFS pool named 'tank'
# Please note that I'm using the /dev/disk/by-id interface. This is more resilient than /dev/sda and /dev/sdb
zpool create -f -o ashift=12 -O atime=off -O dedup=off -O compression=lz4 tank raidz `ls /dev/disk/by-id/ata-*-part3`
# Create OS partiton
zfs create tank/os
# Rsync the current system to the new partition.
rsync -a --one-file-system / /tank/os/
# Chroot into the system
cd /tank/os
mount --bind /dev dev
mount --bind /proc proc
mount --bind /sys sys
mount --bind /run run
chroot .
# Install GRUB into the drives
export ZPOOL_VDEV_NAME_PATH=YES
update-grub
for d in `ls /dev/sd?`;
do
grub-install $d;
done
zfs set mountpoint=/ tank/os
# nuke all the partition info on all the sd? disks
for d in `ls /dev/sd?`;
do
for p in `parted -s $d print | awk '/^ / {print $1}'`;
do
echo "deleting $d $p";
parted -s $d rm $p;
done;
done
# Install Ubuntu 18.04 on a 4G partition using the Hetzner 'installimage' script
/root/.oldroot/nfs/install/installimage -a -n recoveryos -r yes -l 1 -p /:ext4:4G -K /root/.ssh/robot_user_keys -i /root/.oldroot/nfs/install/../images/Ubuntu-1804-bionic-64-minimal.tar.gz
# Reboot the system.
/sbin/shutdown -r now
root@recoveryos ~ # parted -l
Model: ATA TOSHIBA MG04ACA6 (scsi)
Disk /dev/sda: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
2 1049kB 2097kB 1049kB bios_grub
1 2097kB 4297MB 4295MB raid
3 4297MB 6001GB 5997GB zfs primary
Model: ATA TOSHIBA MG04ACA6 (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
2 1049kB 2097kB 1049kB bios_grub
1 2097kB 4297MB 4295MB raid
3 4297MB 6001GB 5997GB zfs primary
Model: ATA TOSHIBA MG04ACA6 (scsi)
Disk /dev/sdc: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
2 1049kB 2097kB 1049kB bios_grub
1 2097kB 4297MB 4295MB raid
3 4297MB 6001GB 5997GB zfs primary
Model: ATA TOSHIBA MG04ACA6 (scsi)
Disk /dev/sdd: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
2 1049kB 2097kB 1049kB bios_grub
1 2097kB 4297MB 4295MB raid
3 4297MB 6001GB 5997GB zfs primary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment