LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Cloning OS on a GPT partitioned drive - to a smaller drive??? (https://www.linuxquestions.org/questions/linux-software-2/cloning-os-on-a-gpt-partitioned-drive-to-a-smaller-drive-4175715010/)

taylorkh 07-24-2022 08:16 AM

Cloning OS on a GPT partitioned drive - to a smaller drive???
 
Since the days of my CP/M Osborne I have always separated my data from the OS. This makes for much easier and effective backup. The data is easy, the OS I have typically performed a cold backup with Ghost, Clonezilla or most recently with redorescue. These producte work great and have saved me many times. EXCEPT if the target drive is even a tiny bit smaller than the source.

I came across this https://blnlabs.com/clone-hdd-to-smaller-sdd-on-linux/ brilliant approach and have used it with success on FAT/MBR formatted media. On GPT - no luck :( I believe that is because, as I understand, GPT stores partition information in multiple places around the drive.

I have some hardware on which I boot Linux from a USB flash drive. For example an Intel NUC which serves as a gateway, firewall, VPN sharing box between my LAN and the Internet. It does not need any storage, only enough to boot the OS and run a couple of programs. I have Linux Mint installed on a Samsung (nominal) 32 GB flash drive. I am attempting to clone it to a SanDisk (nominal) 32 GB flash drive which is a little bit smaller. Plenty of room for the files but Clonezilla and redurescue both barf that the target is too small. I tried the dd approach as described in the linked page above. No luck. My target drive is unreadable.

A couple of years ago when I was playing with Raspberry Pi computers heavily I came across this issue frequently as MicroSD cards are very nominal in size and a few kB difference will cause the cloning programs to fail. I developed this rsync process to do the job.
Code:

sudo rsync -r -l -H -p -E -o -g --devices --specials -t -v  /run/media/ken/PI_BOOT/* /xtra/store_boot

sudo rsync -r -l -H -p -E -o -g --devices --specials -t -v  /run/media/ken/PI_ROOT/* /xtra/store_root

sudo rsync -r -l -H -p -E -o -g --devices --specials -t -v  /xtra/store_boot/* /run/media/ken/PI_BOOT/

sudo rsync -r -l -H -p -E -o -g --devices --specials -t -v  /xtra/store_root/* /run/media/ken/PI_ROOT/

I tried this with the Mint install but grub would not boot. I suspect grub was referencing UUIDs on the original disk although I have not explored down that road yet.

Bottom line... can anyone recommend a program or process to clone a GPT formatted storage device to a smaller one?

TIA,

Ken

p.s. I have several of these situations. I guess I can just purchase some 64 and 128 GB flash drives. I started out with the OS on 16 GB flash drives with much space left over. When I needed to back them up I ended up cloning to 32 GB drives with MUCH MORE space left over. I have verified that I can clone the larger nominal 32 GB drive to a nominal 64 GB drive... But this is getting off track. :banghead:

jmgibson1981 07-24-2022 08:51 AM

I've gotten in the habit of making tarballs instead of cloning and imaging directly. Then the filesystem size and type is irrelevant. Just get your partitions in order, tar into place, make sure fstab is updated and do grub. Is a bit more manual I suppose than a direct clone but also gives plenty more flexibility.

taylorkh 07-24-2022 09:08 AM

Thank you jmgibson1981,

I typically clonezilla or redorescue to an image which I then backup to one of my data servers. I restore said image to the new drive if ever needed.

I use tar extensively for data backups. I never tried it on an OS. Let me give that a try. I understand how to check and update fstab. I am not sure about grub. I will have to research into that a little.

Ken

openbsd98324 07-24-2022 03:09 PM

you can use whatever live like devuan live or ... slackware.
or https://gitlab.com/openbsd98324/flde-live/ <--- it is the best ;) for classic MBR.

I cannot recommend clonezilla unless it is for MS Windows.
If not windows, goes to classic:

Code:

mount /dev/sda4 /mnt
cd /mnt
tar cvpfz allmydisk.tar.gz *

then.
Code:

cd /target
tar xvpfz allmydisk.tar.gz


taylorkh 07-24-2022 03:41 PM

Thanks openbsd98324,

I have a thread going over on the Mint forums asking how to cause the Mint installer to use MBR/DOS rather than GPT. As I suspected I can achieve this by partitioning the drive before running the installer.

A side discussion pointed me to the Foxclone utility. It will write an image to a smaller drive provided the partitions will fit. Gparted is included in the live image for this purpose. I have tested both partitioning schemes successfully.

Ken

openbsd98324 07-24-2022 03:54 PM

Quote:

Originally Posted by taylorkh (Post 6369646)
Thanks openbsd98324,

I have a thread going over on the Mint forums asking how to cause the Mint installer to use MBR/DOS rather than GPT. As I suspected I can achieve this by partitioning the drive before running the installer.

A side discussion pointed me to the Foxclone utility. It will write an image to a smaller drive provided the partitions will fit. Gparted is included in the live image for this purpose. I have tested both partitioning schemes successfully.

Ken

It depends the size of your disk

mbr/dos is limited to smaller disks.
mbr/dos is comfort and luxus, all works easily.

Is it a large disk, like a >= 4,5.... 6 TB ?
For large disk, EFI/GPT is needed on linux.

edit: tar xvpfz / tar cvpfz is your friend.

taylorkh 07-24-2022 04:05 PM

Thanks again for your input openbsd98324,

I put my OS on SMALL disks and my data on LARGE disks which are GPT and encrypted with dmcrypt and Luks. For example I have a data server with 4 x 8 TB drives. I boot it from a USB flash drive - CentOS 7. This way I do not waste on of my 4 SATA ports for the boot drive and I can mirror the data drives in pairs.

Ken

openbsd98324 07-24-2022 04:15 PM

Quote:

Originally Posted by taylorkh (Post 6369651)
Thanks again for your input openbsd98324,

I put my OS on SMALL disks and my data on LARGE disks which are GPT and encrypted with dmcrypt and Luks. For example I have a data server with 4 x 8 TB drives. I boot it from a USB flash drive - CentOS 7. This way I do not waste on of my 4 SATA ports for the boot drive and I can mirror the data drives in pairs.

Ken

you actually just need a grub on one, you could run your server out of ramdisk. I usually run linux out of ram for saving my disks.
devuan/debian can be stored on fs, you run it from squashfs-tools (see debian-scripts).

Is CentOS 7 fast enough?
I use devuan mostly for usb sticks.
(flde)

taylorkh 07-24-2022 05:08 PM

My "server" is just an over grown hard drive. I could use some sort of NAS but a Dell Poweredge T-30 server was a lot cheaper. Less than $200 US for the bare bones box. I boot it up only when I need to store some files to it, movie collection mostly, or to retrieve a file. I could get by with a couple of external USB hard drives I suppose or, considering the way flash memory is going, a handful of MicroSD cards or flash drives. A 1 TB MicroSD card is SCARY :eek: I could easily loose that in a physical sense. That is more data than my first 20 or more hard drives put together!

Ken

remmilou 07-25-2022 03:26 PM

Quote:

Originally Posted by openbsd98324 (Post 6369637)
you can use whatever live like devuan live or ... slackware.
or https://gitlab.com/openbsd98324/flde-live/ <--- it is the best ;) for classic MBR.

I cannot recommend clonezilla unless it is for MS Windows.
If not windows, goes to classic:

Just curious... Why is Clonezilla not recommended for other than MS Windows?
I use it (Rescuezilla) since long for my Debian system with GPT drives. Never had a problem, but want to stay ahead of that as well...;-)
Thanks in advance.

taylorkh 07-25-2022 05:23 PM

According to the Clonezilla web site is seems to handle just about any situation. Same for Rescuezilla. Not sure where you got that information from.

Ken

computersavvy 07-25-2022 05:55 PM

Many many users use clonezilla with linux.
That particular user thought it should only be for windows but no, it works on linux really well in fact.

kleinde66 07-28-2022 11:17 PM

i'v used it a lot, you can add the iso to grub2, and copy the cd.iso to you hdd .
i like systemback also.


All times are GMT -5. The time now is 08:38 PM.