How I backup partitions using Gzip and DD

Thu Dec 07 2023


If you read my last post, you know that I had a broken Arch setup. And even tho I tried everything possible it didn't worked and I decided to switch to Nobara Linux, which is a Fedora based system that comes with some extra patches over Fedora.

But before installing it on my system, I needed to backup the old Arch Partition becouse I still have some important files on it that I can't just delete. Instead what I'm gonna do is backup that partition to a USB storage just using DD and GZIP.

Before continuing, I should warn you that you need to be careful with DD. It stands for Disk Destroyer and it could destroy any of your data without any warnings. Please read the command you type before running it.

Backing up partitions

At the beginning I had my broken Arch installation and the Windows 11 that I rescued from the broken Arch. And since I already had the same windows 11 inside the Arch I only needed to backup the Arch and it's EFI partition. It was easy I was just able to use dd. With the command down below I can read the partition and compress it with gzip and output that to backup.img.gz file.

dd if=/dev/sda1 conv=sync,noerror bs=64K | gzip -c  > /path/to/backup.img.gz

Restoring backup

In my case I restored my backup to a .raw file and mounted it to a Arch KVM so that I can read the files out of it. But you can also write it down to a partition if you want. But the partition has to be at the same size or bigger than the backup partition otherwise filesystem could freak out and you could end up with an unreadable fs. To restore the Filesystem you can simply use the command

gunzip -c /path/to/backup.img.gz | dd of=/dev/sda

If you want to do something like I do and need to write it to a file, you can simply change the output of dd to point a file instead of a partition and it will work.

So this was it. I'm a bit busy these days with the final exams and after passing them I have a lot of projects to do. But I just need some time. So see you later!

Reply via E-Mail

Thank You!

Batuhan Y. Yılmaz - 03.12.2023 - 36/100