0

Please note, there is an issue where I need a solution that is both command line driven and using efi (uefi??) to get my system to work.

I seen this question come up so many times, but all the answers, are all partial, leave out details like whether the disks are mounted or not, and fail to do a complete study of how to do practical backups and restores of an ubuntu install, so if we can explore this example I think it hits all the issues that someone would like to see with respect to backing up your system.

Question : How do I backup an entire bootable disk, maintaining all the 3 partitions, but make a small file/image taking advantage of the fact that most of the big partition is empty?

Conditions: I am currently booted from sdb which is a 1TB disk that has 3 partitions. I have already dd cloned the disk to sda with the dd command.
Partitions 1, and 2 are small but seem to be necessary to make the disk bootable and are of minor issue with respect to compressing, not that compressing them isn't worthwile. Partition 3 is 950gb, but 98% of it is empty. In other words, its the remainder of the diskdrive not consumed by partitions 1 and 2.
Sdc is an empty 240gb disk drive with one partition sdc1

Goal: I would like to be able to make some kind of back zip file, or image file or whatever that I can use to backup up the currently unmounted sda disk maintaining the 3 partitions, but at the same time be able to compress at least the big partition so that the backup image is a much smaller size and something I can store on either sdb or sdc.

I should be able to then use that compressed backup to make a new bootable disk on a new 1TB disk that recreates the three partitions such that partitions 1 and 2 are recreated exactly, and that partition 3 uses the rest of the disk. I would need the instructions for how to do that as well.

Thoughts: I believe the hard part of this is the sizing of the third partition, as an acceptable solution, since I know the 950gb partition is 98% emmpty, aka I'm only using 20gb of the 950gb, I cut that third partition on the source disk to, say 25gb (just to be sure) and then backup just the three partitions, make the backup and then extend the third partion back up to 950gb on the source disk, When I go to restore this image (which at worst is 1G+5G+25G== 31gb) I then have a bootable disk that can fit on a 31gb disk. In my case I can then extend the third partition on this newly restored disk on that 240gb machine to make use of the full 240gb.?

Thanks in advance

jleslie48


Bootdisk-rack3:~$ df

Filesystem     1K-blocks     Used Available Use% Mounted on
udev            16374812        0  16374812   0% /dev
tmpfs            3281996     9328   3272668   1% /run
/dev/sdb3      978410716 15753812 912933464   2% /
tmpfs           16409968       56  16409912   1% /dev/shm
tmpfs               5120        4      5116   1% /run/lock
tmpfs           16409968        0  16409968   0% /sys/fs/cgroup
/dev/sdb1         815104    29096    786008   4% /boot/efi
tmpfs            3281996        0   3281996   0% /run/user/1001

Bootdisk-rack3:~$ sudo fdisk -l

[sudo] password for bootdisk-01:
Disk /dev/sda: 953.9 GiB, 1024209543168 bytes, 2000409264 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: D02C689D-715F-4380-B810-D0624582A381

Device        Start        End    Sectors   Size Type
/dev/sda1      2048    1640447    1638400   800M EFI System
/dev/sda2   1640448   12126207   10485760     5G Microsoft reserved
/dev/sda3  12126208 2000408575 1988282368 948.1G Linux filesystem


Disk /dev/sdb: 953.9 GiB, 1024209543168 bytes, 2000409264 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: F92B5F4A-7AF6-43E2-9E77-E04D4FF4395D

Device        Start        End    Sectors   Size Type
/dev/sdb1      2048    1640447    1638400   800M EFI System
/dev/sdb2   1640448   12126207   10485760     5G Microsoft reserved
/dev/sdb3  12126208 2000408575 1988282368 948.1G Linux filesystem


Disk /dev/sdc: 223.6 GiB, 240057409536 bytes, 468862128 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
Disklabel type: dos
Disk identifier: 0x85a40f8e

Device     Boot Start       End   Sectors   Size Id Type
/dev/sdc1  *     2048 468858879 468856832 223.6G  7 HPFS/NTFS/exFAT

Bootdisk-rack3:~$~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sdb      8:16   0 953.9G  0 disk
--sdb2   8:18   0     5G  0 part
--sdb3   8:19   0 948.1G  0 part /
--sdb1   8:17   0   800M  0 part /boot/efi
sdc      8:32   0 223.6G  0 disk
--sdc1   8:33   0 223.6G  0 part
sda      8:0    0 953.9G  0 disk
--sda2   8:2    0     5G  0 part
--sda3   8:3    0 948.1G  0 part
--sda1   8:1    0   800M  0 part




6
  • Is there a question in there?
    – David
    Mar 1, 2021 at 15:35
  • Make an image using dd or similar and compress them. If they really are mostly empty, they'll compress fine
    – muru
    Mar 1, 2021 at 15:41
  • 1
    Welcome, the tool you're looking for is clonezilla. It automatically compresses the image, and if I remember correctly it fills the last partition to the maximum, but I'm not sure. Your case is too specific to make tests and write an answer. I suggest that you learn how to use the tool in a virtual machine and the apply it in "real life". Mar 1, 2021 at 15:45
  • Does this answer your question? Cloning hard disk partition to smaller SSD on laptop
    – user68186
    Mar 1, 2021 at 15:56
  • is clonezilla command line? Mar 1, 2021 at 19:50

2 Answers 2

0

You make it too complicated, you store information, not partitions. Simply store the information (files) in a .zip, .tar whatever you want, using the compression level desired. Then when the time comes to do the restore that file is extracted to the new partition and the information is back where it needs to be. Then of course the edits to make it boot again need to be done to reflect the new partition layout and UUIDs if using them to boot. After getting that in order re-install of GRUB is next step.

Now I think of it this procedure here is what I use when doing it myself, except the boot-repair I just copy GRUB into the EFI folder myself. It is straight forward enough and can be adapted to your needs.

Cloning Ubuntu from a usb key to a partition of internal SSD

0

Whilst HappyTux has provided an excellent answer you might want to try the following.

  1. Use the parted utility and resizepart in particular to reduce the size of partition 3 on sda to something more manageable. There is information about how to do that here. https://www.tecmint.com/parted-command-to-create-resize-rescue-linux-disk-partitions/
  2. Use dd to copy sda to the 240GB disk but specify the target to be a file, not the whole disk.
  3. Once you have a file on the 240GB disk you can compress it if you need to.
  4. Restoration is simply the reverse of the above

One question for you to think about while doing this. Why are you trying to preserve the 5GB partition that is labelled Microsoft Reserved? That is not necessary for booting a Linux system but the small 800MB EFI partition is needed

2
  • thank you If I understand you correctly, the dd clone operation will only clone the 3 partitions, not the whole 1tb disk. If I use parted to shrink the sda3 partition from 950gb, to say 29gb, when I do a >sudo dd if=/dev/sda bs=128K | pv -s 40G | sudo dd /of=/media/c240gb/bu37_210302.img bs=128K< command the fle on the 240GB drive will be compressed version of just the 3 partitions of sizes 1G+5G+29G == 35G instead of the 950G I am getting now. I can then further gzip the .img file to a .img.gz file to make it even smaller. Mar 4, 2021 at 13:15
  • Yes overall that is what I meant. Not sure about your dd command. I would use something like dd if=/dev/sda of=/path/to/file bs=1024k status=progress. That should give you a progress monitor. Did you decide you need the Microsoft Reserved partition or is Windows involved here in some way?
    – PonJar
    Mar 4, 2021 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.