Skip to content

Instantly share code, notes, and snippets.

@ntrepid8
Created September 20, 2022 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ntrepid8/ccc25f5770c0fd42df75f407aa782615 to your computer and use it in GitHub Desktop.
Save ntrepid8/ccc25f5770c0fd42df75f407aa782615 to your computer and use it in GitHub Desktop.
Ubuntu 22.04 btrfs home on 2nd drive

Ubuntu 22.04 btrfs home on 2nd drive

Given this crypttab/fstab:

$ cat /etc/crypttab 
nvme0n1p3_crypt UUID=a20b6cb4-c017-43a5-b695-a98fdb230861 /etc/luks/boot_os.keyfile luks,discard
swap_crypt UUID=02fa823d-6779-47ae-b57e-9eb8ba676227 /dev/urandom swap,offset=1024,cipher=aes-xts-plain64,size=512
sda1_crypt UUID=eaaf657d-3526-402e-9580-3d041e888a8d /etc/luks/boot_os.keyfile luks,discard

$ cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/nvme0n1p3_crypt /               btrfs   defaults,subvol=@,ssd,noatime,commit=120,compress=zstd:1,discard=async 0       0
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=D516-20D8  /boot/efi       vfat    umask=0077      0       1
/dev/mapper/nvme0n1p3_crypt /home           btrfs   defaults,subvol=@home,ssd,noatime,commit=120,compress=zstd:1,discard=async 0       0
# swap was on /dev/nvme0n1p2 during installation
/dev/mapper/swap_crypt none            swap    sw              0       0

Mount the root file systems:

$ sudo mount -t btrfs /dev/mapper/nvme0n1p3_crypt /mnt/nvme0n1p3_btrfs

$ sudo mount -t btrfs /dev/mapper/sda1_crypt /mnt/sda1_btrfs

Create snapshot subvolumes (as needed):

$ sudo btrfs subvolume create /mnt/nvme0n1p3_btrfs/@snapshots

$ sudo btrfs subvolume create /mnt/sda1_btrfs/@snapshots

Create a read-only snapshot of the old home:

$ sudo btrfs subvolume snapshot -r /mnt/nvme0n1p3_btrfs/@home /mnt/nvme0n1p3_btrfs/@snapshots/home_2022-09-20

Send the read-only snapshot to the new drive:

$ sudo btrfs send /mnt/nvme0n1p3_btrfs/@snapshots/home_2022-09-20 | sudo btrfs receive /mnt/sda1_btrfs/@snapshots/

Create a read-write copy of the snapshot:

$ sudo btrfs subvolume snapshot /mnt/data_btrfs/@snapshots/home_2022-09-20 /mnt/data_btrfs/@home

Update fstab:

$ cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/nvme0n1p3_crypt /               btrfs   defaults,subvol=@,ssd,noatime,commit=120,compress=zstd:1,discard=async 0       0
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=D516-20D8  /boot/efi       vfat    umask=0077      0       1

# OLD
#/dev/mapper/nvme0n1p3_crypt /home           btrfs   defaults,subvol=@home,ssd,noatime,commit=120,compress=zstd:1,discard=async 0       0

# NEW
/dev/mapper/sda1_crypt /home           btrfs   defaults,subvol=@home,ssd,noatime,commit=120,compress=zstd:1,discard=async 0       0

# swap was on /dev/nvme0n1p2 during installation
/dev/mapper/swap_crypt none            swap    sw              0       0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment