Skip to content

Instantly share code, notes, and snippets.

@mz0
Last active April 18, 2019 14:14
Show Gist options
  • Save mz0/37044fee1e34977f35726abe80d6caf7 to your computer and use it in GitHub Desktop.
Save mz0/37044fee1e34977f35726abe80d6caf7 to your computer and use it in GitHub Desktop.
ZFS

https://github.com/zfsonlinux/zfs/wiki/Ubuntu-18.04-Root-on-ZFS

2.3 Create the root pool: 2.3a Unencrypted:

Delete GPT copy at end of disk:

# dd if=/dev/zero of=/dev/disk/by-id/ata-TOSHIBA_HDWD130_95FE8EEKS bs=4k seek=732566645 count=1
## Verify:
# dd if=/dev/disk/by-id/ata-TOSHIBA_HDWD130_95FE8EEKS bs=4k skip=732566645 count=1 |od -x

# time zpool create -o ashift=12 \
      -O atime=off -O canmount=off -O compression=lz4 \
      -O xattr=sa -O mountpoint=/ -R /mnt/rpool \
      rpool raidz \
   /dev/disk/by-id/ata-TOSHIBA_HDWD130_95FE8EEKS \
   /dev/disk/by-id/ata-TOSHIBA_HDWD130_683T527AS \
   /dev/disk/by-id/ata-TOSHIBA_HDWD130_683T827AS \
   /dev/disk/by-id/ata-TOSHIBA_HDWD130_58VSRTAAS

   
real	0m3,843s
user	0m0,018s
sys	0m0,017s

# zpool status
  pool: rpool
 state: ONLINE
  scan: none requested
config:

	NAME                               STATE     READ WRITE CKSUM
	rpool                              ONLINE       0     0     0
	  raidz1-0                         ONLINE       0     0     0
	    ata-TOSHIBA_HDWD130_95FE8EEKS  ONLINE       0     0     0
	    ata-TOSHIBA_HDWD130_683T527AS  ONLINE       0     0     0
	    ata-TOSHIBA_HDWD130_683T827AS  ONLINE       0     0     0
	    ata-TOSHIBA_HDWD130_58VSRTAAS  ONLINE       0     0     0

errors: No known data errors

3.1

# zfs create -o canmount=off -o mountpoint=none rpool/ROOT

3.2

# zfs create -o canmount=noauto -o mountpoint=/ rpool/ROOT/ubuntu
# zfs mount rpool/ROOT/ubuntu

3.3

root@q:/# zfs create                 -o setuid=off              rpool/home
root@q:/# zfs create -o mountpoint=/root                        rpool/home/root
root@q:/# zfs create -o canmount=off -o setuid=off  -o exec=off rpool/var
root@q:/# zfs create -o com.sun:auto-snapshot=false             rpool/var/cache
root@q:/# zfs create -o acltype=posixacl -o xattr=sa            rpool/var/log
root@q:/# zfs create                                            rpool/var/spool
root@q:/# zfs create -o com.sun:auto-snapshot=false -o exec=on  rpool/var/tmp

3.4 (LUKS-only -- skip)

3.5

# cd /mnt/rpool/
# mkdir /mnt/backup
# mount /dev/disk/by-id/usb-Seagate_Backup+_Hub_BK_NA8T1D1P-0:0-part2 /mnt/backup/
# tar tvzf /mnt/backup/lxdU18.tgz |less
# tar xzf /mnt/backup/lxdU18.tgz

4.4

# mount --rbind /dev  /mnt/rpool/dev
# mount --rbind /proc /mnt/rpool/proc
# mount --rbind /sys  /mnt/rpool/sys/
# chroot /mnt/rpool/ /bin/bash --login
(chroot) ? # ln -sf /proc/self/mounts /etc/mtab
(chroot) # apt update 
(chroot) # apt install zfs-initramfs  ### installs zfs-initramfs zfs-zed zfsutils-linux etc.
(chroot) # mount /dev/disk/by-id/usb-SanDisk_Cruzer_Fit_4C532000020531123414-0\:0-part1 /mnt/boot/
### ls -l /boot/initrd.img-4.15.0-34-generic /mnt/boot/initrd.img-4.15.0-34-generic 
### 54115891 Sep 14     /boot/initrd.img-4.15.0-34-generic
### 52378994 Sep 12 /mnt/boot/initrd.img-4.15.0-34-generic

4.11

(chroot) # zfs set mountpoint=legacy rpool/var/log
(chroot) # zfs set mountpoint=legacy rpool/var/tmp
(chroot) # cat >> /etc/fstab << EOF
rpool/var/log /var/log zfs defaults 0 0
rpool/var/tmp /var/tmp zfs defaults 0 0
EOF
(chroot) # grub-probe /
zfs
(chroot) # update-initramfs -c -k all
### 54169482 Sep 14 16:38     /boot/initrd.img-4.15.0-33-generic
### 54168180 Sep 14 16:38     /boot/initrd.img-4.15.0-34-generic
### 54115891 Sep 14 16:24 /mnt/boot/initrd.img-4.15.0-34-generic
### 52314526 Aug 24 17:49 /mnt/boot/initrd.img-4.15.0-33-generic
(chroot) # cp -p /boot/initrd.img-4.15.0-34-generic /mnt/boot/initrd.img-4.15.0-34-generic
(chroot) # <edit grub.cfg>

6.2

(chroot) # exit

6.3

# mount | grep -v zfs | tac | awk '/\/mnt/ {print $3}' | xargs umount -l 
# mount | grep -v zfs | tac | awk '/\/mnt/ {print $3}' | xargs -i{} umount -l {}
# cd /
# zpool export rpool
@mz0
Copy link
Author

mz0 commented Apr 18, 2019

#8200 has this comment: (2018.12.10 @rlaager)
This is really up to @gmelikov, but since it's a wiki and changes are easy to revert, I went ahead and boldly edited this. I see no point to the equal level filesystems approach. Either the filesystems should be at the top-level (as per the HOWTO) because they should not be rolled back with the root filesystem, or they should be a child of the root filesystem (as per the earlier example in the initrd documentation) because you do want them rolled back with the root filesystem but also want them as a separate dataset for some reason. The middle ground of having them under rpool/ROOT seems pointless (and could also confuse a beadm tool).

I also removed the examples of /boot and /var as things to separate under the root dataset: /var because it conflicts with the root-on-ZFS HOWTO, and /boot because that's where GRUB lives and GRUB is earlier in the process here. If someone knows what they are doing, they can modify things, but we shouldn't have attractive nuisances like that.

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