0

For major version upgrades, Tails recommends this convoluted upgrade path where you write an image on a fresh USB drive, then clone the OS partition onto your original USB drive. I'm trying to figure out a better way to do it:

I have a .img file that contains a partition table and a single partition:

$ sudo kpartx -av tails-amd64-5.2.img
add map loop12p1 (253:0): 0 2553856 linear 7:12 2048
$ sudo parted tails-amd64-5.2.img UNIT b print
Model:  (file)
Disk tails-amd64-5.2.img: 1309671424B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start     End          Size         File system  Name   Flags
 1      1048576B  1308622847B  1307574272B  fat32        Tails  boot, hidden, legacy_boot, esp

And a drive with two partitions:

$  sudo kpartx -av /dev/sdb
add map sdb1 (253:2): 0 16777216 linear 8:16 2048
add map sdb2 (253:3): 0 43655168 linear 8:16 16781312
$ sudo parted /dev/sdb UNIT b print
Model: Kingston DataTraveler 3.0 (scsi)
Disk /dev/sdb: 30943995904B
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start        End           Size          File system  Name       Flags
 1      1048576B     8590983167B   8589934592B   fat32        Tails      boot, hidden, legacy_boot, esp
 2      8592031744B  30943477759B  22351446016B               TailsData

I would like to restore the image over top of the first partition on that drive and leave the second partition untouched. I tried this command and the result will boot to GRUB but not the OS:

$ sudo dd if=tails-amd64-5.2.img of=/dev/sdb1 bs=16M

According to fsck, that's because the GPT partition is at the start. This command does nothing:

$ sudo kpartx -d tails-amd64-5.2.img

This command results in a drive that doesn't even boot to GRUB:

$ sudo dd if=tails-amd64-5.2.img of=/dev/sdb1 bs=512 count=2

Is there a way to strip the GUID partition table and make this work?

1 Answer 1

1

You almost provided your own answer. You are already using kpartx but aren't taking advantage of its results:

$ sudo kpartx -av tails-amd64-5.2.img
add map loop12p1 (253:0): 0 2553856 linear 7:12 2048 

Note the response add map loop12p1.

This command has just created a /dev/mapper/loop12p1 device for you, which will give you direct access to the partition within the image file, skipping the GUID partition table.

So you can then do this:

sudo dd if=/dev/mapper/loop12p1 of=/dev/sdb1 bs=16M

This command will remove the /dev/mapper/loop12p1 (or whatever) loopback device once you no longer need it:

sudo kpartx -d tails-amd64-5.2.img
1
  • That worked perfectly - thank you!
    – Jared
    Jul 24, 2022 at 19:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .