Cloning a GPT drive


I reported on my first Quirky image, only 93MB, but when I wrote it (using dd) to another USB flash drive, the drive was broken:
http://bkhome.org/news/?viewDetailed=00013

I have done some research ...gulp, it is almost 4.00am... and found out the cause of the problem, and the solution.

The GPT system has a primary partition table at the start of the drive, and a secondary table right at the end of the drive.
The problem is that I want to copy between flash drives that are going to be slightly different sizes. I am using 8GB drives, but they differ in actual storage capacity. Some el-cheapos use 8x1000x1000x1000 bytes, instead of the full 8GB which is 8x1024x1024x1024.

Creating partitions slightly smaller than the full size of the drive, and using dd to create an image file just big enough for those partitions, gives an image file that can be written to any "8GB" drive (or bigger).
This works for the old MBR system, but for GPT the secondary table gets left behind. Result, broken drive.

One solution is given here:
http://kudzia.eu/b/2013/07/cloning-gpt-disk-to-a-smaller-drive/

The manpages for sgdisk and gdisk:
http://www.rodsbooks.com/gdisk/sgdisk.html
http://linux.die.net/man/8/gdisk

I need to use gdisk, and I have written a simple script to perform the fix. 'dd' is used to copy the image file to the drive, then 'gdisk' recreates the secondary table at the end of the drive.

Tried it, it works!

I have created a PET for gdisk. Actually, the package is named 'gptfdisk', homepage:
http://www.rodsbooks.com/gdisk/

Incidentally, the original problem that caused me to use GPT rather than traditional MBR, is the "root=/dev/sdb" problem in the bootloader, where the drive letter may change when booting with other drives plugged in, or on different PCs. Solution is "root=PARTUUID=<partuuid>", which requires GPT.

Furthermore, that partuuid value does not have to be changed. Once I have created it in the image file, that's it. You can write the image to any drive, no need to change that partuuid.


Comments:

Might this be of use   Posted on 10 Dec 2013, 7:35 by Tony
Hi Barry, came across this article on self replicating USB sticks for spreading software around countries with limited access.
http://phys.org/news/2013-12-usb-internet-hurdles-globally.html
Cheers
Tony

Re Flash wear out   Posted on 6 Dec 2013, 22:34 by BarryK
zygo,
There is no 'pupsave' file, Quirky6 is like a full-hard-drive installation. There is no layered filesystem.

Quirky6 is using the new f2fs filesystem, which is especially designed for Flash memory, avoids banging the same physical memory locations with repeated writes. So, no longer any need, or rather very greatly reduced need, to work in RAM only.

I'm testing Opera in Quirky, displays my blog OK, let's see if it posts OK...

Title   Posted on 6 Dec 2013, 18:40 by Author


Title   Posted on 6 Dec 2013, 18:39 by Author


flash ware out   Posted on 6 Dec 2013, 11:09 by zygo
Is the pupsave on the flash? You, thankfully, went to some trouble some years back to avoid waring out the flash memory when booting from such a medium. Is anything written to flash on a regular basis after boot eg swap partition?

flash ware out   Posted on 6 Dec 2013, 10:46 by zygo
Is the pupsave on the flash? You, thankfully, went to some trouble some years back to avoid waring out the flash memory when booting from such a medium. Is anything written to flash on a regular basis after boot eg swap partition?

flash ware out   Posted on 6 Dec 2013, 10:31 by zygo
Is the pupsave on the flash? You, thankfully, went to some trouble some years back to avoid waring out the flash memory when booting from such a medium. Is anything written to flash on a regular basis after boot eg swap partition?

Re SD card   Posted on 6 Dec 2013, 7:52 by BarryK
zygo,
I think it should work with an SD card, that is the intention, but I haven't tried it yet.

First partition is 16MB fat16, second is about 7.5GB f2fs partition. The first partition is only for bootup.

The second partition is where Quirky files are, and while running will have to be rw.

However, one goal is to have auditing, with rollback, so you could remove all changes made in, say, last session.


SD card?   Posted on 6 Dec 2013, 7:28 by zygo
Will your image (and its installer) work with an SD card? What is the second partition for? Can the card be set to read-only?