Pop!OS Linux: Creating a Bootable Backup USB With Encryption
For my Pop!OS Linux workstation, I wanted to have a complete backup on an USB drive.
Of course, it needs to be encrypted, in case the USB drive gets lots.
And to allow me to quickly resume working in the case of an emergency,
I wanted the USB backup to be bootable, too.
Here’s how I set that up:
12345
# find /dev/sd* mountpoint for USB drivelsblk
# open GDisk partition editorsudogdisk/dev/sdX
In gdisk:
Create GPT table: o (create new empty GUID partition table)
Create EFI System Partition:
n (new partition)
Partition number: 1
First sector: Enter (default)
Last sector: +512M (or +1G for larger ESP)
Hex code: ef00 (EFI System)
Create root partition:
n (new partition)
Partition number: 2
First sector: Enter (default)
Last sector: Enter (use remaining space)
Hex code: 8300 (Linux filesystem)
Write changes: w
12345
# Set up LUKS encryptionsudocryptsetupluksFormat/dev/sdX2
# Open the encrypted partitionsudocryptsetupluksOpen/dev/sdX2usb_crypt
12345
# Format EFI System Partition as FAT32sudomkfs.fat-F32/dev/sdX1
# Format encrypted partition as ext4sudomkfs.ext4/dev/mapper/usb_crypt
Let’s mount the newly created filesystems so that I can fill them with data:
In case you cannot remember (like me), here’s a list of the options:
Option
Long Form
Description
a
--archive
Archive mode - equivalent to -rlptgoD. Preserves recursion, links, permissions, timestamps, group, owner, and devices/specials.
v
--verbose
Verbose output
h
--human-readable
Output numbers using K, M, G suffixes
P
--partial --progress
Keep partially transferred files and show progress during transfer
H
--hard-links
Preserve hard links
A
--acls
Preserve ACLs
X
--xattrs
Preserve extended attributes
x
--one-file-system
Prevent rsync from following mount points
–numeric-ids
rsync will transfer numeric group and user IDs rather than using user and group names and mapping them at both ends
To make things bootable, the fstab inside the USB drive needs to point to the correct partition UUIDs:
123456
# Get UUIDssudoblkid/dev/sdX1# EFI partition UUIDsudoblkid/dev/mapper/usb_crypt# Root partition UUID# Edit fstab inside USB OS rootsudonano/mnt/backup_usb/etc/fstab
Update /mnt/backup_usb/etc/fstab with the new UUIDs: