Skip to content

Instantly share code, notes, and snippets.

@metahertz
Created August 1, 2023 13:32
Show Gist options
  • Save metahertz/d3f8bb3a32dc71b18eab582fdae4c73a to your computer and use it in GitHub Desktop.
Save metahertz/d3f8bb3a32dc71b18eab582fdae4c73a to your computer and use it in GitHub Desktop.
Backup linux boot-related items.
#!/usr/bin/env bash
## Export variables for the various commands
## find BOOT_DISK, BOOT_PART and EFI_PART with the following commands:
### blkid | grep vfat
### There will likley be one disk only listed, with one or two partitions. This is your BOOT_DISK (example, /dev/sda or /dev/nvme0n1)
export BOOT_DISK=CHANGEME
### sudo fdisk ${BOOT_DISK} print
### This will show one as "EFI partition" this is your EFI partition (example, /dev/sda2 or /dev/nvme0p1n2)
export EFI_PART=CHANGEME
### the other vfat partition listed in the first command is your BOOT_PART (example, /dev/sda1 or /dev/nvme0p1n1)
export BOOT_PART=CHANGEME
### Where can you easily access on your NAS to save the files too (so you can send them to me!) (example /mnt/ZFSPoolName/Share/)
export SAVE_LOCATION=CHANGEME
### Now the backup commands will work based on the exports above
## Take a copy of the GPT partition table
sudo sgdisk --backup=/${SAVE_LOCATION}/partition-table-gpt.txt ${BOOT_DISK}
## Take a file only copy of the mounted /boot directory in the OS
sudo tar -czvf /${SAVE_LOCATION}/mounted-boot-dir.tgz /boot
## Take a compressed raw dump of the grub bootloader partition
sudo dd if=${BOOT_PART} bs=1M | xz --threads=0 --keep -v > /${SAVE_LOCATION}/dd-boot-partition.img.xz
## Take a compressed raw dump of the EFI bootloader partition
sudo dd if=${EFI_PART} bs=1M | xz --threads=0 --keep -v > /${SAVE_LOCATION}/dd-efi-partition.img.xz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment