0

I've got an SSD with a linux OS on it which I'm not currently using. The SSD usually sits in my desktop computer, but I won't be using it for a while.

I would like to use the SSD in my laptop for a while. Since they're pretty expensive still I don't really want to buy another while I have a perfectly good one here.

I thought about using dd to clone the disk so that I could restore it in the future if I need to get my desktop system working again. However it's 240 GB in size but only 5 GB is currently in use, so ideally I would like to be able to clone it without using all this space.

  • Would this be possible if I compressed the output iso image?

  • Can I just "copy" the files I need for later (including hidden ones?) using rsync? This will be only ~ 5 GB in size - but will I be able to restore these files correctly? eg; I might need to preserve permissions while doing this to prevent problems when I restore the files to the SSD?

  • Is there a better method?

The OS is either debian/ubuntu.

  • 1
    Possible duplicate of Clone only space in use from hard disk – Kamil Maciorowski Dec 25 '17 at 16:57
  • 1
    Clonezilla – anders Dec 25 '17 at 17:24
  • 1
    Just using rsync (with --archive) is probably easiest. @AndersD Clonezilla's still basically a linux distribution with terminal menus? Would be nice to just use it's "workings" directly yourself, seems like it's a big wrapper for dd? – Xen2050 Dec 25 '17 at 23:05
  • And the possible Dup Q is about saving any disk's used space, this Q is basically about backing up a linux system disk, not a real duplicate – Xen2050 Dec 25 '17 at 23:15
  • Ofcourse it's nice to be able to do stuff directly on CLI, but what is right for you in your situation is not always whats right for the next guy. I understand it like this: He wants a full backup with MBR in case he wants to "reinstall" his desktop back to its former glory. Then clonezilla does the work nicely, and the backup will only be 5GB if that is the disk space he has used. And its more like a one click restore process when and if the decides to use the desktop again. – anders Dec 26 '17 at 11:44
2

You just need to save the files, the free space doesn't matter (unless you want to recover it's files later) so a dd like tool would be starting with 235GB (240GB minus the 5GB used) too much. Instead of spending time & effort & the limited write lifetime of the SSD trying to fill all the empty space with zeros, just backup the 5GB of files.

rsync and it's --archive flag would be good.

For an even smaller backup, use a squashfs image. It's what most of the live linux ISO's use. Running from another live system/ISO would avoid any temporary / in-use / lock files too. After mounting (say to /mnt) basically it's:

mksquashfs /mnt backup.squashfs 

You could use a probably smaller & slower xz compression with:

mksquashfs /mnt backup.squashfs -comp xz  -b 1048576

Then just mount & copy the files back when you're ready. Makes a good general backup too, since it's random access - you don't have to scan through an entire .tar.xz or


If you'll be overwriting the boot sector (and GRUB) you might want to save a copy of it too. For MBR it's just the first 512 bytes, so dd would grab it to a file called MBR.dd:

dd if=/dev/sda of=MBR.dd bs=512 count=1

GPT could use sgdisk (ref answer on U&L) like:

sgdisk --backup=<file> <device>

To restore the backup use:

sgdisk --load-backup=<file> <device>

But ignoring the partition table is good too, you'd have the chance to create & restore to a much smaller partition (only using 5GB out of 240GB) and just restoring GRUB with a live ISO is easy too.

| improve this answer | |

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.