Skip to content

Instantly share code, notes, and snippets.

@fire
Last active May 5, 2022 09:46
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fire/65f7aa33b91d3af2aef0 to your computer and use it in GitHub Desktop.
Save fire/65f7aa33b91d3af2aef0 to your computer and use it in GitHub Desktop.
Install Elementary Freya on ZFS root

Experimental 2015-04-25

# Create a usb disk with Elementary OS and Startup Disk Creator
# Boot it
sudo -i
apt-add-repository --yes ppa:zfs-native/stable
apt-get update
apt-get install --yes spl-dkms zfs-dkms ubuntu-zfs    

setup zfs

zpool create -f rpool /dev/disk/by-id/ata-DISK
zfs set compression=lz4 rpool

zfs create rpool/ROOT
zfs create rpool/ROOT/elementary-1

zfs set mountpoint=/ rpool/ROOT/elementary-1
zpool set bootfs=rpool/ROOT/elementary-1 rpool
parted -s   /dev/disk/by-id/ata-DISK mkpart  GRUB2 48s 2047s
parted -s /dev/disk/by-id/ata-DISK set 2 bios_grub on
zpool export rpool
zpool import -R /mnt rpool
#debootstrap trusty /mnt
cp /etc/hosts /mnt/etc/
cp /etc/resolv.conf /mnt/etc/resolv.conf
nano /mnt/etc/hostname 
mount --rbind /dev      /mnt/dev
mount --rbind /proc     /mnt/proc
mount --rbind /sys      /mnt/sys
chroot /mnt /bin/bash --login
cp -rp /fire/EXISTING-ELEMENTARY-INSTALL /mnt
locale-gen en_US.UTF-8
dpkg-reconfigure tzdata
apt-get update
apt-add-repository --yes ppa:zfs-native/stable
apt-get update
apt-get install --yes ubuntu-zfs
apt-get install --yes grub-pc zfs-initramfs
wget -q -O /etc/cron.hourly/zfs-check https://gist.githubusercontent.com/fire/65f7aa33b91d3af2aef0/raw/a0309ef9a6bec26b497b2ee7e00aaa2889310384/zfs-check.sh
wget -q -O /etc/cron.monthly/zfs-scrub https://gist.githubusercontent.com/fire/65f7aa33b91d3af2aef0/raw/5b0904343897b1410fd57239879a0f43ff634883/zfs-scrub.sh
chmod 755 /etc/cron.hourly/zfs-check /etc/cron.monthly/zfs-scrub

wget -q -O /etc/sudoers.d/zfs https://gist.githubusercontent.com/fire/65f7aa33b91d3af2aef0/raw/36a2b9e37819abffc6bfc2a9a36859afabf47754/zfs.sudoers
chmod 440 /etc/sudoers.d/zfs

# Change name of admin user
USERNAME="johnd"
adduser $USERNAME
cp -a /etc/skel/.[!.]* /home/$USERNAME

chown $USERNAME:$USERNAME /home/$USERNAME

usermod -a -G adm,audio,dialout,dip,cdrom,floppy,fuse,lpadmin,plugdev,sambashare,scanner,sudo,video $YOURUSERNAME
apt-get install grub-common grub-pc
apt-get install zfs-initramfs

cat > /etc/udev/rules.d/70-zfs-grub-fix.rules << 'EOF'
ENV{DEVTYPE}=="partition", IMPORT{parent}="ID_*", ENV{ID_FS_TYPE}=="zfs_member", SYMLINK+="$env{ID_BUS}-$env{ID_SERIAL} $env{ID_BUS}-$env{ID_SERIAL}-part%n"
EOF
udevadm trigger

sudo nano  /etc/default/grub
# add "boot=zfs" to GRUB_CMDLINE_LINUX_DEFAULT=

update-initramfs -c -k all
# update-initramfs: Generating /boot/initrd.img-3.2.0-40-generic
# 6.3 Update the boot configuration file:

update-grub
# Generating grub.cfg ...
# Found linux image: /boot/vmlinuz-3.2.0-40-generic
# Found initrd image: /boot/initrd.img-3.2.0-40-generic
# done
# Verify that boot=zfs appears in the boot configuration file:

grep boot=zfs /boot/grub/grub.cfg
# linux /ROOT/ubuntu-1/@/boot/vmlinuz-3.2.0-40-generic root=/dev/sda2 ro boot=zfs $bootfs quiet splash $vt_handoff
# linux /ROOT/ubuntu-1/@/boot/vmlinuz-3.2.0-40-generic root=/dev/sda2 ro single nomodeset boot=zfs $bootfs
# 6.4 Install the boot loader

grub-install $(readlink -f /dev/disk/by-id/scsi-SATA_disk1)
# Installation finished. No error reported.
   
exit
# 7.2 Run these commands in the LiveCD environment to dismount all filesystems:

umount -l /mnt/dev
umount -l /mnt/proc
umount -l /mnt/sys
zfs umount -a
zpool export rpool
reboot

# See issue https://github.com/zfsonlinux/pkg-zfs/issues/113 for adding a script to add dev link
# See issue for partition 1 workaround https://github.com/zfsonlinux/grub/issues/5
# cat > /etc/udev/rules.d/70-zfs-grub-fix.rules << 'EOF'
ENV{DEVTYPE}=="partition", IMPORT{parent}="ID_*", ENV{ID_FS_TYPE}=="zfs_member", SYMLINK+="$env{ID_BUS}-$env{ID_SERIAL} $env{ID_BUS}-$env{ID_SERIAL}-part%n"
EOF
# udevadm trigger

Procedure to mirror an os drive

  • Disk1 is original.
  • Disk2 is the new disk.
sudo zpool attach -f rpool /dev/disk/by-id/DISK1_SERIAL /dev/disk/by-id/DISK2_SERIAL
# Alternative version for 4k sectors
# sudo zpool attach -o ashift=12 -f rpool /dev/disk/by-id/DISK1_SERIAL /dev/disk/by-id/DISK2_SERIAL
# Make sure udev script exists to fix bug
sudo parted -s /dev/disk/by-id/DISK2_SERIAL mkpart GRUB2 48s 2047s
sudo parted -s /dev/disk/by-id/DISK2_SERIAL set 2 bios_grub on
sudo grub-install $(readlink -f /dev/disk/by-id/DISK2_SERIAL)
sudo -i
apt-add-repository --yes ppa:zfs-native/stable
apt-get update
apt-get install --yes debootstrap spl-dkms zfs-dkms ubuntu-zfs    

setup zfs

zpool create -f rpool /dev/disk/by-id/ata-DISK
zfs set compression=lz4 rpool

zfs create rpool/ROOT
zfs create rpool/ROOT/ubuntu-1

zfs set mountpoint=/ rpool/ROOT/ubuntu-1
zpool set bootfs=rpool/ROOT/ubuntu-1 rpool
parted -s   /dev/disk/by-id/ata-DISK mkpart  GRUB2 48s 2047s
parted -s /dev/disk/by-id/ata-DISK set 2 bios_grub on
zpool export rpool
zpool import -R /mnt rpool
debootstrap trusty /mnt
cp /etc/hosts /mnt/etc/
nano /mnt/etc/hostname 
mount --rbind /dev      /mnt/dev
mount --rbind /proc     /mnt/proc
mount --rbind /sys      /mnt/sys
chroot /mnt /bin/bash --login
locale-gen en_US.UTF-8
dpkg-reconfigure tzdata

apt-get update
apt-get install --yes ubuntu-minimal software-properties-common wget bsd-mailx patch
apt-add-repository --yes ppa:zfs-native/stable
apt-get update
apt-get install --yes --no-install-recommends linux-generic linux-headers-generic
apt-get install --yes ubuntu-zfs
apt-get install --yes grub-pc zfs-initramfs
wget -q -O /etc/cron.hourly/zfs-check https://gist.githubusercontent.com/fire/65f7aa33b91d3af2aef0/raw/a0309ef9a6bec26b497b2ee7e00aaa2889310384/zfs-check.sh
wget -q -O /etc/cron.monthly/zfs-scrub https://gist.githubusercontent.com/fire/65f7aa33b91d3af2aef0/raw/5b0904343897b1410fd57239879a0f43ff634883/zfs-scrub.sh
chmod 755 /etc/cron.hourly/zfs-check /etc/cron.monthly/zfs-scrub

wget -q -O /etc/sudoers.d/zfs https://gist.githubusercontent.com/fire/65f7aa33b91d3af2aef0/raw/36a2b9e37819abffc6bfc2a9a36859afabf47754/zfs.sudoers
chmod 440 /etc/sudoers.d/zfs

# Change name of admin user
USERNAME="johnd"
adduser $USERNAME
cp -a /etc/skel/.[!.]* /home/$USERNAME


chown $USERNAME:$USERNAME /home/$USERNAME

usermod -a -G adm,audio,dialout,dip,cdrom,floppy,fuse,lpadmin,plugdev,sambashare,scanner,sudo,video $YOURUSERNAME
apt-get install grub-common grub-pc
apt-get install zfs-initramfs

cat > /etc/udev/rules.d/70-zfs-grub-fix.rules << 'EOF'
ENV{DEVTYPE}=="partition", IMPORT{parent}="ID_*", ENV{ID_FS_TYPE}=="zfs_member", SYMLINK+="$env{ID_BUS}-$env{ID_SERIAL} $env{ID_BUS}-$env{ID_SERIAL}-part%n"
EOF
udevadm trigger

sudo nano  /etc/default/grub
# add "boot=zfs" to GRUB_CMDLINE_LINUX_DEFAULT=

update-initramfs -c -k all
# update-initramfs: Generating /boot/initrd.img-3.2.0-40-generic
# 6.3 Update the boot configuration file:

update-grub
# Generating grub.cfg ...
# Found linux image: /boot/vmlinuz-3.2.0-40-generic
# Found initrd image: /boot/initrd.img-3.2.0-40-generic
# done
# Verify that boot=zfs appears in the boot configuration file:

grep boot=zfs /boot/grub/grub.cfg
# linux /ROOT/ubuntu-1/@/boot/vmlinuz-3.2.0-40-generic root=/dev/sda2 ro boot=zfs $bootfs quiet splash $vt_handoff
# linux /ROOT/ubuntu-1/@/boot/vmlinuz-3.2.0-40-generic root=/dev/sda2 ro single nomodeset boot=zfs $bootfs
# 6.4 Install the boot loader

grub-install $(readlink -f /dev/disk/by-id/scsi-SATA_disk1)
# Installation finished. No error reported.

#8.2a Install a command-line environment only:
#apt-get install --yes ubuntu-standard
#8.2b Install a full GUI environment:
apt-get install --yes ubuntu-desktop

exit
# 7.2 Run these commands in the LiveCD environment to dismount all filesystems:

umount -l /mnt/dev
umount -l /mnt/proc
umount -l /mnt/sys
zfs umount -a
zpool export rpool
reboot

# See issue https://github.com/zfsonlinux/pkg-zfs/issues/113 for adding a script to add dev link
# See issue for partition 1 workaround https://github.com/zfsonlinux/grub/issues/5
#!/bin/bash
# Make symlinks in /dev to allow kernel upgrades to succeed.
# Put in /etc/kernel/postinst.d
ZPOOL=$(which zpool)
if [ -z $ZPOOL ]; then
exit 0
fi
$ZPOOL status | grep -P '\t ' | tr -s ' ' | tr -d '\t' | cut -d' ' -f2 | while read line
do
if [ ! -e /dev/$line ]; then
ln -s /dev/disk/by-id/"$line"-part1 /dev/$line
fi
done
#!/bin/sh -eu
which zpool >/dev/null || exit 0
zpool list -H -o health,name 2>&1 | \
awk 'BEGIN {FS="\t"} {if ($1 ~ /^ONLINE/) print $2}' | \
while read pool ; do
zpool scrub "$pool"
done
Cmnd_Alias C_ZFS = \
/sbin/zfs "", \
/sbin/zfs help *, \
/sbin/zfs get, \
/sbin/zfs get *, \
/sbin/zfs list, \
/sbin/zfs list *, \
/sbin/zpool "", \
/sbin/zpool help *, \
/sbin/zpool iostat, \
/sbin/zpool iostat *, \
/sbin/zpool list, \
/sbin/zpool list *, \
/sbin/zpool status, \
/sbin/zpool status *, \
/sbin/zpool upgrade, \
/sbin/zpool upgrade -v
# Allow read-only ZFS commands to be called through sudo without a password.
ALL ALL = (root) NOPASSWD: C_ZFS
@pmarreck
Copy link

pmarreck commented Jan 4, 2020

Do you think this would be more or less an identical procedure on elementaryOS Hera? Looking to try it out on ZFS root

@fire
Copy link
Author

fire commented Jan 5, 2020

I have not touched elementary os in a very long time.

One of my main oses is Fedora and it supports Elementary OS's Pantheon.

https://fedoraproject.org/wiki/Changes/PantheonDesktop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment