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
  • 3,404
  • 9
  • 39
  • 54

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
  • 14,391