Instructions to backup USB key drive to another USB key drive

The goal is to reproduce exactly same copy so the target has same permissions, formatting and media name after mounting, even encryption works with same password.I store my private files and key files used to login to remote consoles on encrypted USB key drive. This device is encrypted with luks, when inserted it is mounted as /media/11361B10710FL159/. Various config files in my system (for example /home/.ssh/config) depends on this exact media name and exact file permissions on the thumb drive.

We need target USB drive, that is same size or larger than source USB drive, Insert both USB key drives and run your favorite command to find name of both devices, I use fdisk -l or lshw -C disk. Note that target device will be erased and rewritten by data from source drive.

$ sudo fdisk -l

Disk /dev/sdb: 1031 MB, 1031798784 bytes
32 heads, 62 sectors/track, 1015 cylinders, total 2015232 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00037e2a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1              62     2013759     1006849    7  HPFS/NTFS/exFAT

Disk /dev/mapper/udisks-luks-uuid-469c41b9-f577-4bfd-bf5c-2e2b469189ed-uid1001: 1028 MB, 1028916224 bytes
255 heads, 63 sectors/track, 125 cylinders, total 2009602 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2052474d

This doesn't look like a partition table
Probably you selected the wrong device.

                                                                     Device Boot      Start         End      Blocks   Id  System
/dev/mapper/udisks-luks-uuid-469c41b9-f577-4bfd-bf5c-2e2b469189ed-uid1001p1   ?     6579571  1924427647   958924038+  70  DiskSecure Multi-Boot
/dev/mapper/udisks-luks-uuid-469c41b9-f577-4bfd-bf5c-2e2b469189ed-uid1001p2   ?  1953251627  3771827541   909287957+  43  Unknown
/dev/mapper/udisks-luks-uuid-469c41b9-f577-4bfd-bf5c-2e2b469189ed-uid1001p3   ?   225735265   225735274           5   72  Unknown
/dev/mapper/udisks-luks-uuid-469c41b9-f577-4bfd-bf5c-2e2b469189ed-uid1001p4      2642411520  2642463409       25945    0  Empty

Partition table entries are not in disk order

Disk /dev/sdc: 8086 MB, 8086618112 bytes
249 heads, 62 sectors/track, 1023 cylinders, total 15794176 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001273c

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *          62    15793073     7896506    b  W95 FAT32

From this output you can see that the encrypted source drive is named /dev/sdb and target drive’s name is /dev/sdc, it’s larger, it has file system that looks like FAT32, we do not care about that, it will be erased anyway, make sure not to mess up source and target USB disk, because using the wrong other way will overwrite the source with target and we do not want that.

For exact copy I use dd command, for more information use dd –help, basically no special parameter need to be used as long as you have enough time but I personally use parameter bs to speed up copying process ($ sudo dd if=/dev/sdb of=/dev/sdc bs=64k), use only if you know what you are doing. 

$ sudo dd if=/dev/sdb of=/dev/sdc

if is input file, of is output file, in this case use whole device name, this will copy everything on /dev/sdb to /dev/sdc, including formatting, partitions, … dd will copy bit by bit, it does not care what is on target drive, dd will recreate it with source, you do not have to format target or do anything with it at all, source drive may be even mounted and encryption open.