How do I properly save an image of my disk

Please consider this:
Filesystem Size Used Avail
/dev/sda 80G 37G 43G

Im tryng to create an image running sudo dd if=/dev/sda | dd of=/home/iosef/linode.img status=progress the problem is this command is capturing the complete disk, including unused space, this means that my disk of 80G needs at least 80G of free space which obviously is impossible.
How can I create an image capturing just the used space?

5 Replies

As long as the disk isn't in raw format and doesn't use custom partitions, you should be able to resize the disk to make it smaller. The minimum size of a disk is equal to the current disk usage within the filesystem.

We have some documentation that can then help you copy and download the disk to another server.

If the purpose of this is to backup your data to a home computer, you may want to look into other options for in our guide to backing up data.

You can use compression to save on unused space. Also you don't want to use dd's default block size settings, you can, it'll just be very slow. Even slower than compression:

Save sda (default disk) to a gz file:
dd if=/dev/sda | gzip > sda.gz

Restore to sda:
gunzip -c sda.gz > /dev/sda

  1. So you can either resize the disk leaving enough space that's larger than your used space size. Then create another ext4 disk again at least as large as your used space, this will be storing the file. Now you have 2 disks each at least as large as your used space size ideally both a little larger or more.

Then reboot into rescue mode with /dev/sda being the disk you want to save, sdb being swap, and sdc being "storage" we'll call it (to save the gz file on).

Do NOT mount /dev/sda at this point. Mount sdc and make the backup compressed file of the disk:
mkdir storage
mount /dev/sdc storage
dd if=/dev/sda | gzip > storage/sda.gz

Then you make a passwd and start ssh in rescue mode to download the file.

or

You can pick one of the options following the "copy and download the disk" CassandraD already gave:

2.a. copy the entire disk without compression just like the instructions (I still recommend changing dd's block size).

2.b. In the first ssh example command replace this:
ssh root@192.0.2.9 "dd if=/dev/sda " | dd of=/home/archive/linode.img status=progress

with:
ssh root@192.0.2.9 "dd if=/dev/sda " | gzip > /home/iosef/sda.gz

Using just basic cat instead of default dd or dd with a larger block size than the default and without compression will be the fastest saving/restoring from/to disk themselves. But if you want to save unused space, maybe save on downloads or data or something, compression is going to be useful if you don't mind waiting longer than a 1:1 to copy of dd (or cat) for just compression/decompression, but either is still less time than default 512KB dd lol…

I would actually recommend updating the Linode doc with a --block-size for dd so it goes way faster than default dd.

Thank you very much you both for the answers.
Im tryng to implement the solution proposed by Ryanbearden creating a new disk. The storage tab is showing me the disk is in fact created however seams the server is nor recognizing this, please take a look in the image: https://i.ibb.co/tMLWHbC/puzzeling.png

Can you telling me what Im missing?

So notice the Configuration tab just to the right of Storage? Edit the configuration to add your other disk to your Linode's OS. You probably only have restore and swap disks in the default Configuration at that point.

But if you boot into rescue mode, before you actually click "reboot", you're given a separate temporary list of your Storage disks to attach.

Done, thank you :)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct