Cloning a Linux installed on a usb drive to another usb of the same brand/type
Easiest option that is tried and true: use gparted to make your source partitions 15GB just to be sure. Then clone to the other USB drives.
In essence, this is not a cloning issue, this is a partition sizing issue. Once the partition / disk size is below the maximum size by a comfortable about, just dd if=source of=destination
(assuming Windows) and rock on with your bad self.
Related videos on Youtube
TimothyP
Updated on September 18, 2022Comments
-
TimothyP almost 2 years
I have a completely configured Linux system installed on a 16GB USB drive. I have the same brand/type of USB drive 10 times and the exact same mainboard 10 times.
Now I want to copy the USB drive to the others so I can have 10 systems use the same image.
What I did was create an image of the USB drive using WinDiskImager32 and then I tried writing it back to the original USB drive. That worked because it's the same drive but as soon as I tried to write it to the other USB drives it failed because the image was too big for those drives. Even though they are all 16GB, in reality of course there are always minor differences.
Obviously this is not the correct way of doing this, so I'm wondering how do I correctly "clone" my original USB so that I can deploy it on the others?
(Note, the system is configured to deal with the fact that it's installed on a new computer, so that's not an issue here, just need to get an exact copy)
Update
Based on WesleyDavid's answer I check the drive with gparted and remebered that I originally copied the image from a 8GB device using WinDiskImager32 so the partition is already small enough.
The problem is that WindDiskImager copies the entire drive, not just the partitions.
Now the 'dd' solution fixes that by only copying a partition but then how do I get both the ext2 and swap filesystem on the target usb?
Using dd to copy the entire device results in the full 16GB again which won't always fit on the other devices
Update 2
Using dd as sugested by WesleyDavid works,
just had to use the count parameter of dd, as described hereBasically it means running "fdisk -u -l /dev/sdb" (replace sdb with your device)
> Disk /dev/sdb: 16.3 GB, 16257318912 bytes 64 heads, 32 sectors/track, > 15504 cylinders, total 31752576 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: > 0x000392d4 > > Device Boot Start End Blocks Id System > /dev/sdb1 * 2048 13672447 6835200 83 Linux > /dev/sdb2 13674494 15818751 1072129 5 Extended > /dev/sdb5 13674496 15818751 1072128 82 Linux swap
In my case the end of the last partition is at '15818751' so I used:
dd if=/dev/sdb of=/home/myusername/usbimage.img count=15818752
adding one more just to be safe. That gave me an image that I can install.
-
Wesley over 11 years
dd
can copy an entire device, not just a partition. -
Wesley over 11 yearsE.g.
dd if=/dev/sda of=/dev/sdb
and that gets every partition and even the MBR. Everything from stem to stern. -
TimothyP over 11 yearsBut that results in the image being the full 16GB again (it included the unallocated space)
-
-
TimothyP over 11 yearsI'll see if I can do that will come back to check the answer if it works
-
TimothyP over 11 yearsI've updated the question as I now understand how to copy a partition using dd, but what about the swap?
-
Thalys over 11 yearsIf you set the root device /dev/sdb it should copy everything on it, I believe
-
TimothyP over 11 yearsTrying that now, I'm just hoping it doesn't copy all the device sectors but only the partitions (because windiskimager was copying everything)
-
TimothyP over 11 yearsIt seems to be copying the entire disk including the unallocated space...
-
TimothyP over 11 yearsChecking the solution from this link: serverfault.com/questions/446529/… Where you use the count parameter to limit the amount of bytes that are copied (based on fdisk -u -l output)
-
TimothyP over 11 yearsok using dd and the count parameter works like a charm