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.

user3728501
  • 2,486
  • 6
  • 28
  • 46
  • 1
    Possible duplicate of [Clone only space in use from hard disk](https://superuser.com/questions/1097210/clone-only-space-in-use-from-hard-disk) – Kamil Maciorowski Dec 25 '17 at 16:57
  • 2
    [Clonezilla](http://clonezilla.org) – 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
  • @Anders Do you have proof that Clonezilla's backup will only be 5GB, and not a full raw copy of the 240GB partition? [The help](http://clonezilla.org/clonezilla-live-doc.php) only [shows cloning disk & partitions](http://clonezilla.org/fine-print-live-doc.php?path=./clonezilla-live/doc/01_Save_disk_image/06-dev-img.doc#06-dev-img.doc). That sounds like a `dd` copy, including 245GB of free space (that could have old possibly uncompressible data too, if clonezilla even uses compression) – Xen2050 Dec 27 '17 at 01:17
  • "Clonezilla saves and restores only used blocks in the hard disk. Sector-to-sector copying (by dd) is only done with unsupported file systems (read Features). And I know, not only by actually reading what the software does, but by using it. You can't look at at a screenshot and assume what the software does behind the scenes. This is how clonezilla operates: MBR (by dd) Partition table (by sfdisk and parted), CHS of disk. Data on every partition or LV (logical volume) (by partimage, ntfsclone, partclone or dd. It depends on the "-q" option you choose). Your way is l33t though! – anders Dec 27 '17 at 09:41
  • @Anders Thanks, that's interesting, definitely more versatile than I'd though. They *really* need to work on their help pages, you'd think they'd mention the tool names more in their how-to guides & screenshots itself., and the wall of text that is their home page is TL;DR ;-) Partimage & Partclone are in Debian's repos, ntfsclone is in `ntfs-3g` so probably already installed in most linux's (Clonezilla's page has a dead link to the ntfs tools' page) so they can be used "your favourite" linux. – Xen2050 Dec 27 '17 at 22:30

1 Answers1

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.

Xen2050
  • 13,643
  • 4
  • 24
  • 42