Cloning a GPT drive
December 06, 2013 —
BarryK
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/201312/first-play-with-usb-quirky.html
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
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.
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.
http://phys.org/news/2013-12-usb-internet-hurdles-globally.html
Cheers
Tags: linux