Ubuntu/Debian: Use a variable for the disk
This simplifies a bunch of typing. This does more strongly encourage people to use /dev/disk/by-id naming, as e.g. ${DISK}-part1 does not work if $DISK is /dev/sda. This could be a considered a feature or a bug, depending on one's perspective.
parent
0ea96f54fb
commit
a2e28dcde8
|
@ -67,49 +67,54 @@ If you have a second system, using SSH to access the target system can be conven
|
|||
|
||||
## Step 2: Disk Formatting
|
||||
|
||||
2.1 If you are re-using a disk, clear it as necessary:
|
||||
2.1 Set a variable with the disk name:
|
||||
|
||||
If the disk was previously used in an MD array, zero the superblock:
|
||||
|
||||
apt install --yes mdadm
|
||||
mdadm --zero-superblock --force /dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
Clear the partition table:
|
||||
|
||||
sgdisk --zap-all /dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
2.2 Partition your disk(s):
|
||||
|
||||
Run this if you need legacy (BIOS) booting:
|
||||
|
||||
sgdisk -a1 -n1:24K:+1000K -t1:EF02 /dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
Run this for UEFI booting (for use now or in the future):
|
||||
|
||||
sgdisk -n2:1M:+512M -t2:EF00 /dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
Run this for the boot pool:
|
||||
|
||||
sgdisk -n3:0:+1G -t3:BF01 /dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
Choose one of the following options:
|
||||
|
||||
2.2a Unencrypted or ZFS native encryption:
|
||||
|
||||
sgdisk -n4:0:0 -t4:BF01 /dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
2.2b LUKS:
|
||||
|
||||
sgdisk -n4:0:0 -t4:8300 /dev/disk/by-id/scsi-SATA_disk1
|
||||
DISK=/dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
Always use the long `/dev/disk/by-id/*` aliases with ZFS. Using the `/dev/sd*` device nodes directly can cause sporadic import failures, especially on systems that have more than one storage pool.
|
||||
|
||||
**Hints:**
|
||||
* `ls -la /dev/disk/by-id` will list the aliases.
|
||||
* Are you doing this in a virtual machine? If your virtual disk is missing from `/dev/disk/by-id`, use `/dev/vda` if you are using KVM with virtio; otherwise, read the [troubleshooting](#troubleshooting) section.
|
||||
* If you are creating a mirror or raidz topology, repeat the partitioning commands for all the disks which will be part of the pool.
|
||||
|
||||
2.3 Create the boot pool:
|
||||
2.2 If you are re-using a disk, clear it as necessary:
|
||||
|
||||
If the disk was previously used in an MD array, zero the superblock:
|
||||
|
||||
apt install --yes mdadm
|
||||
mdadm --zero-superblock --force $DISK
|
||||
|
||||
Clear the partition table:
|
||||
|
||||
sgdisk --zap-all $DISK
|
||||
|
||||
2.3 Partition your disk(s):
|
||||
|
||||
Run this if you need legacy (BIOS) booting:
|
||||
|
||||
sgdisk -a1 -n1:24K:+1000K -t1:EF02 $DISK
|
||||
|
||||
Run this for UEFI booting (for use now or in the future):
|
||||
|
||||
sgdisk -n2:1M:+512M -t2:EF00 $DISK
|
||||
|
||||
Run this for the boot pool:
|
||||
|
||||
sgdisk -n3:0:+1G -t3:BF01 $DISK
|
||||
|
||||
Choose one of the following options:
|
||||
|
||||
2.3a Unencrypted or ZFS native encryption:
|
||||
|
||||
sgdisk -n4:0:0 -t4:BF01 $DISK
|
||||
|
||||
2.3b LUKS:
|
||||
|
||||
sgdisk -n4:0:0 -t4:8300 $DISK
|
||||
|
||||
If you are creating a mirror or raidz topology, repeat the partitioning commands for all the disks which will be part of the pool.
|
||||
|
||||
2.4 Create the boot pool:
|
||||
|
||||
zpool create -o ashift=12 -d \
|
||||
-o feature@async_destroy=enabled \
|
||||
|
@ -131,8 +136,7 @@ Always use the long `/dev/disk/by-id/*` aliases with ZFS. Using the `/dev/sd*`
|
|||
-o feature@allocation_classes=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 /dev/disk/by-id/scsi-SATA_disk1-part3
|
||||
-O mountpoint=/ -R /mnt bpool ${DISK}-part3
|
||||
|
||||
You should not need to customize any of the options for the boot pool.
|
||||
|
||||
|
@ -142,38 +146,34 @@ GRUB does not support all of the zpool features. See `spa_feature_names` in [gru
|
|||
* If you are creating a mirror or raidz topology, create the pool using `zpool create ... bpool mirror /dev/disk/by-id/scsi-SATA_disk1-part3 /dev/disk/by-id/scsi-SATA_disk2-part3` (or replace `mirror` with `raidz`, `raidz2`, or `raidz3` and list the partitions from additional disks).
|
||||
* The pool name is arbitrary. If changed, the new name must be used consistently. The `bpool` convention originated in this HOWTO.
|
||||
|
||||
2.4 Create the root pool:
|
||||
2.5 Create the root pool:
|
||||
|
||||
Choose one of the following options:
|
||||
|
||||
2.4a Unencrypted:
|
||||
2.5a Unencrypted:
|
||||
|
||||
zpool create -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 /dev/disk/by-id/scsi-SATA_disk1-part4
|
||||
-O mountpoint=/ -R /mnt rpool ${DISK}-part4
|
||||
|
||||
2.4b LUKS:
|
||||
2.5b LUKS:
|
||||
|
||||
apt install --yes cryptsetup
|
||||
cryptsetup luksFormat -c aes-xts-plain64 -s 512 -h sha256 \
|
||||
/dev/disk/by-id/scsi-SATA_disk1-part4
|
||||
cryptsetup luksOpen /dev/disk/by-id/scsi-SATA_disk1-part4 luks1
|
||||
cryptsetup luksFormat -c aes-xts-plain64 -s 512 -h sha256 ${DISK}-part4
|
||||
cryptsetup luksOpen ${DISK}-part4 luks1
|
||||
zpool create -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 /dev/mapper/luks1
|
||||
-O mountpoint=/ -R /mnt rpool /dev/mapper/luks1
|
||||
|
||||
2.4c ZFS native encryption:
|
||||
2.5c ZFS native encryption:
|
||||
|
||||
zpool create -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 encryption=aes-256-gcm -O keylocation=prompt -O keyformat=passphrase \
|
||||
-O mountpoint=/ -R /mnt \
|
||||
rpool /dev/disk/by-id/scsi-SATA_disk1-part4
|
||||
-O mountpoint=/ -R /mnt rpool ${DISK}-part4
|
||||
|
||||
* The use of `ashift=12` is recommended here because many drives today have 4KiB (or larger) physical sectors, even though they present 512B logical sectors. Also, a future replacement drive may have 4KiB physical sectors (in which case `ashift=12` is desirable) or 4KiB logical sectors (in which case `ashift=12` is required).
|
||||
* Setting `-O acltype=posixacl` enables POSIX ACLs globally. If you do not want this, remove that option, but later add `-o acltype=posixacl` (note: lowercase "o") to the `zfs create` for `/var/log`, as [journald requires ACLs](https://askubuntu.com/questions/970886/journalctl-says-failed-to-search-journal-acl-operation-not-supported)
|
||||
|
@ -331,7 +331,7 @@ Customize this file if the system is not a DHCP client.
|
|||
mount --rbind /dev /mnt/dev
|
||||
mount --rbind /proc /mnt/proc
|
||||
mount --rbind /sys /mnt/sys
|
||||
chroot /mnt /bin/bash --login
|
||||
chroot /mnt /usr/bin/env DISK=$DISK bash --login
|
||||
|
||||
**Note:** This is using `--rbind`, not `--bind`.
|
||||
|
||||
|
@ -356,8 +356,7 @@ Even if you prefer a non-English system language, always ensure that `en_US.UTF-
|
|||
|
||||
apt install --yes cryptsetup
|
||||
|
||||
echo luks1 UUID=$(blkid -s UUID -o value \
|
||||
/dev/disk/by-id/scsi-SATA_disk1-part4) none \
|
||||
echo luks1 UUID=$(blkid -s UUID -o value ${DISK}-part4) none \
|
||||
luks,discard,initramfs > /etc/crypttab
|
||||
|
||||
* The use of `initramfs` is a work-around for [cryptsetup does not support ZFS](https://bugs.launchpad.net/ubuntu/+source/cryptsetup/+bug/1612906).
|
||||
|
@ -377,10 +376,9 @@ Install GRUB to the disk(s), not the partition(s).
|
|||
4.8b Install GRUB for UEFI booting
|
||||
|
||||
apt install dosfstools
|
||||
mkdosfs -F 32 -s 1 -n EFI /dev/disk/by-id/scsi-SATA_disk1-part2
|
||||
mkdosfs -F 32 -s 1 -n EFI ${DISK}-part2
|
||||
mkdir /boot/efi
|
||||
echo PARTUUID=$(blkid -s PARTUUID -o value \
|
||||
/dev/disk/by-id/scsi-SATA_disk1-part2) \
|
||||
echo PARTUUID=$(blkid -s PARTUUID -o value ${DISK}-part2) \
|
||||
/boot/efi vfat nofail,x-systemd.device-timeout=1 0 1 >> /etc/fstab
|
||||
mount /boot/efi
|
||||
apt install --yes grub-efi-amd64 shim-signed
|
||||
|
@ -465,7 +463,7 @@ Later, once the system has rebooted twice and you are sure everything is working
|
|||
|
||||
5.6a For legacy (BIOS) booting, install GRUB to the MBR:
|
||||
|
||||
grub-install /dev/disk/by-id/scsi-SATA_disk1
|
||||
grub-install $DISK
|
||||
|
||||
Note that you are installing GRUB to the whole disk, not a partition.
|
||||
|
||||
|
|
|
@ -59,49 +59,54 @@ If you have a second system, using SSH to access the target system can be conven
|
|||
|
||||
## Step 2: Disk Formatting
|
||||
|
||||
2.1 If you are re-using a disk, clear it as necessary:
|
||||
2.1 Set a variable with the disk name:
|
||||
|
||||
If the disk was previously used in an MD array, zero the superblock:
|
||||
|
||||
apt install --yes mdadm
|
||||
mdadm --zero-superblock --force /dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
Clear the partition table:
|
||||
|
||||
sgdisk --zap-all /dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
2.2 Partition your disk(s):
|
||||
|
||||
Run this if you need legacy (BIOS) booting:
|
||||
|
||||
sgdisk -a1 -n1:24K:+1000K -t1:EF02 /dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
Run this for UEFI booting (for use now or in the future):
|
||||
|
||||
sgdisk -n2:1M:+512M -t2:EF00 /dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
Run this for the boot pool:
|
||||
|
||||
sgdisk -n3:0:+1G -t3:BF01 /dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
Choose one of the following options:
|
||||
|
||||
2.2a Unencrypted:
|
||||
|
||||
sgdisk -n4:0:0 -t4:BF01 /dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
2.2b LUKS:
|
||||
|
||||
sgdisk -n4:0:0 -t4:8300 /dev/disk/by-id/scsi-SATA_disk1
|
||||
DISK=/dev/disk/by-id/scsi-SATA_disk1
|
||||
|
||||
Always use the long `/dev/disk/by-id/*` aliases with ZFS. Using the `/dev/sd*` device nodes directly can cause sporadic import failures, especially on systems that have more than one storage pool.
|
||||
|
||||
**Hints:**
|
||||
* `ls -la /dev/disk/by-id` will list the aliases.
|
||||
* Are you doing this in a virtual machine? If your virtual disk is missing from `/dev/disk/by-id`, use `/dev/vda` if you are using KVM with virtio; otherwise, read the [troubleshooting](#troubleshooting) section.
|
||||
* If you are creating a mirror or raidz topology, repeat the partitioning commands for all the disks which will be part of the pool.
|
||||
|
||||
2.3 Create the boot pool:
|
||||
2.2 If you are re-using a disk, clear it as necessary:
|
||||
|
||||
If the disk was previously used in an MD array, zero the superblock:
|
||||
|
||||
apt install --yes mdadm
|
||||
mdadm --zero-superblock --force $DISK
|
||||
|
||||
Clear the partition table:
|
||||
|
||||
sgdisk --zap-all $DISK
|
||||
|
||||
2.3 Partition your disk(s):
|
||||
|
||||
Run this if you need legacy (BIOS) booting:
|
||||
|
||||
sgdisk -a1 -n1:24K:+1000K -t1:EF02 $DISK
|
||||
|
||||
Run this for UEFI booting (for use now or in the future):
|
||||
|
||||
sgdisk -n2:1M:+512M -t2:EF00 $DISK
|
||||
|
||||
Run this for the boot pool:
|
||||
|
||||
sgdisk -n3:0:+1G -t3:BF01 $DISK
|
||||
|
||||
Choose one of the following options:
|
||||
|
||||
2.3a Unencrypted:
|
||||
|
||||
sgdisk -n4:0:0 -t4:BF01 $DISK
|
||||
|
||||
2.3b LUKS:
|
||||
|
||||
sgdisk -n4:0:0 -t4:8300 $DISK
|
||||
|
||||
If you are creating a mirror or raidz topology, repeat the partitioning commands for all the disks which will be part of the pool.
|
||||
|
||||
2.4 Create the boot pool:
|
||||
|
||||
zpool create -o ashift=12 -d \
|
||||
-o feature@async_destroy=enabled \
|
||||
|
@ -118,8 +123,7 @@ Always use the long `/dev/disk/by-id/*` aliases with ZFS. Using the `/dev/sd*`
|
|||
-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 /dev/disk/by-id/scsi-SATA_disk1-part3
|
||||
-O mountpoint=/ -R /mnt bpool ${DISK}-part3
|
||||
|
||||
You should not need to customize any of the options for the boot pool.
|
||||
|
||||
|
@ -129,28 +133,25 @@ GRUB does not support all of the zpool features. See `spa_feature_names` in [gru
|
|||
* If you are creating a mirror or raidz topology, create the pool using `zpool create ... bpool mirror /dev/disk/by-id/scsi-SATA_disk1-part3 /dev/disk/by-id/scsi-SATA_disk2-part3` (or replace `mirror` with `raidz`, `raidz2`, or `raidz3` and list the partitions from additional disks).
|
||||
* The pool name is arbitrary. If changed, the new name must be used consistently. The `bpool` convention originated in this HOWTO.
|
||||
|
||||
2.4 Create the root pool:
|
||||
2.5 Create the root pool:
|
||||
|
||||
Choose one of the following options:
|
||||
|
||||
2.4a Unencrypted:
|
||||
2.5a Unencrypted:
|
||||
|
||||
zpool create -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 /dev/disk/by-id/scsi-SATA_disk1-part4
|
||||
-O mountpoint=/ -R /mnt rpool ${DISK}-part4
|
||||
|
||||
2.4b LUKS:
|
||||
2.5b LUKS:
|
||||
|
||||
cryptsetup luksFormat -c aes-xts-plain64 -s 512 -h sha256 \
|
||||
/dev/disk/by-id/scsi-SATA_disk1-part4
|
||||
cryptsetup luksOpen /dev/disk/by-id/scsi-SATA_disk1-part4 luks1
|
||||
cryptsetup luksFormat -c aes-xts-plain64 -s 512 -h sha256 ${DISK}-part4
|
||||
cryptsetup luksOpen ${DISK}-part4 luks1
|
||||
zpool create -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 /dev/mapper/luks1
|
||||
-O mountpoint=/ -R /mnt rpool /dev/mapper/luks1
|
||||
|
||||
* The use of `ashift=12` is recommended here because many drives today have 4KiB (or larger) physical sectors, even though they present 512B logical sectors. Also, a future replacement drive may have 4KiB physical sectors (in which case `ashift=12` is desirable) or 4KiB logical sectors (in which case `ashift=12` is required).
|
||||
* Setting `-O acltype=posixacl` enables POSIX ACLs globally. If you do not want this, remove that option, but later add `-o acltype=posixacl` (note: lowercase "o") to the `zfs create` for `/var/log`, as [journald requires ACLs](https://askubuntu.com/questions/970886/journalctl-says-failed-to-search-journal-acl-operation-not-supported)
|
||||
|
@ -307,7 +308,7 @@ Customize this file if the system is not a DHCP client.
|
|||
mount --rbind /dev /mnt/dev
|
||||
mount --rbind /proc /mnt/proc
|
||||
mount --rbind /sys /mnt/sys
|
||||
chroot /mnt /bin/bash --login
|
||||
chroot /mnt /usr/bin/env DISK=$DISK bash --login
|
||||
|
||||
**Note:** This is using `--rbind`, not `--bind`.
|
||||
|
||||
|
@ -337,8 +338,7 @@ If you prefer nano over vi, install it:
|
|||
|
||||
apt install --yes cryptsetup
|
||||
|
||||
echo luks1 UUID=$(blkid -s UUID -o value \
|
||||
/dev/disk/by-id/scsi-SATA_disk1-part4) none \
|
||||
echo luks1 UUID=$(blkid -s UUID -o value ${DISK}-part4) none \
|
||||
luks,discard,initramfs > /etc/crypttab
|
||||
|
||||
* The use of `initramfs` is a work-around for [cryptsetup does not support ZFS](https://bugs.launchpad.net/ubuntu/+source/cryptsetup/+bug/1612906).
|
||||
|
@ -358,10 +358,9 @@ Install GRUB to the disk(s), not the partition(s).
|
|||
4.8b Install GRUB for UEFI booting
|
||||
|
||||
apt install dosfstools
|
||||
mkdosfs -F 32 -s 1 -n EFI /dev/disk/by-id/scsi-SATA_disk1-part2
|
||||
mkdosfs -F 32 -s 1 -n EFI ${DISK}-part2
|
||||
mkdir /boot/efi
|
||||
echo PARTUUID=$(blkid -s PARTUUID -o value \
|
||||
/dev/disk/by-id/scsi-SATA_disk1-part2) \
|
||||
echo PARTUUID=$(blkid -s PARTUUID -o value ${DISK}-part2) \
|
||||
/boot/efi vfat nofail,x-systemd.device-timeout=1 0 1 >> /etc/fstab
|
||||
mount /boot/efi
|
||||
apt install --yes grub-efi-amd64-signed shim-signed
|
||||
|
@ -446,7 +445,7 @@ Later, once the system has rebooted twice and you are sure everything is working
|
|||
|
||||
5.6a For legacy (BIOS) booting, install GRUB to the MBR:
|
||||
|
||||
grub-install /dev/disk/by-id/scsi-SATA_disk1
|
||||
grub-install $DISK
|
||||
|
||||
Note that you are installing GRUB to the whole disk, not a partition.
|
||||
|
||||
|
|
Loading…
Reference in New Issue