1

I want to backup my complete drive of my brand new PC.

I tried this command:

sudo tar -czvf disk.tar /dev/nvme0n1

But it finishes after 1 second.

The nvme0n1 file in the archive is 0 bytes.

What is wrong here?

Edit:

I always run this command on the partition before so I have no (already deleted) files:

dd if=/dev/zero of=moh bs=100M
rm moh
  • The input isn't a file or directory: /dev/nvme0n1 (just as well, since the output is probably on the same disk...). – Thomas Dickey Dec 24 '19 at 15:05
  • The output is on a different disk. So tar isn't capable of archiving block devices? – somega Dec 24 '19 at 15:06
1

tar should be used to backup files. To backup a exact state of a disk you should use dd.

So if you want a exact copy of the drive use: dd if=/dev/nvme0n1 of=/mnt/some_other_drive/copy_of_the_first_drive.

Even better would be to use compression (if it's a disk of a brand new pc you can strongly compress it) with dd if=/dev/nvme0n1 | bzip2 > /mnt/some_other_drive/copy_of_the_first_drive.bz2

Lot's of other options are also possible:

  • You could use nc or ssh to create a tunnel and transfer the backup to another system while it's being made (if there is no 2nd disk on your system).
  • You could use tar if you only want the files and not the whole state
  • You could use rsync if you only want the files and there is no 2nd disk available.
| improve this answer | |
  • Is it possible to pipe /dev/nvme0n1 into tar, as you did with bzip2? – somega Dec 24 '19 at 15:25
  • Yes but there is no added advantage. tar is only useful for multiple files and /dev/nvme0n is only 1 'file' (it's treated as 1 file by the system). tar just places a lot of files behind each other and saves them as 1 file. It has no compression other useful features. – Garo Dec 24 '19 at 15:29
  • The bzip2 command does not work. It says "Can't open input file" – somega Dec 24 '19 at 16:33
  • Sorry, the > was missing, i edited it – Garo Dec 24 '19 at 19:41
0

first of all you should mount it to a directory like /mnt. after that u can use your command(tar czvf somebackup.tar.gz /mnt). anyway i suggest you to work with rsync. if you wanna pick whole state up to another hard disk you should use dd command else you have not to do so.

| improve this answer | |
  • I also need to backup data which is not stored in files (for example MBR). So mount/cp is not enough. – somega Dec 25 '19 at 9:08
0

tar is intended to work on the file level

You can use tar to create an archive of directories and files, and the archive may or may not be compressed.

This way you can backup the content of the root partition, /, and other partition(s), that you may have in your system.

Examples (run when running another system, e.g. booted from a USB pendrive)

sudo mkdir /mnt/sd1
sudo mkdir /mnt/sd2
sudo mkdir /mnt/sd3

sudo mount /dev/nvme0n1p1 /mnt/sd1
sudo mount /dev/nvme0n1p2 /mnt/sd2
sudo mount /dev/nvme0n1p3 /mnt/sd3

sudo tar -cvzf root.tar.gz /mnt/sd1
sudo tar -cvzf home.tar.gz /mnt/sd2  # optional
sudo tar -cvzf data.tar.gz /mnt/sd3  # optional

It is easy to access a single backed up file, particularly if you do not compress the archive. This is good.

But the partition table (and BIOS bootloader (necessary to boot in BIOS mode)) will not be backed up.

Clonezilla works on a whole drive

You can use Clonezilla, which is a tool to clone or create a [compressed] image of the content of a whole drive with partitions and bootloaders, everything.

  • Download a Clonezilla iso file,
  • create a USB boot drive,
  • boot from it and
  • let Clonezilla do it for you.

Clonezilla is smart enough to only copy used blocks in the file system(s) and skip free space. It will also compress the image, so it is both faster and creates a much smaller image (compared to plain cloning with for example dd). The image is not one file, but a directory with a set of files, and you use Clonezilla to restore from the image.

Clonezilla has also several checkpoints to help you identify the drives and make sure that, when backing up, you are reading from the correct drive, and when restoring, that you are writing to the correct drive.

| improve this answer | |
  • I don't like clonezilla because it's a huge program with complicated file formats (check points and so on). I have used blocks only too (see my update). – somega Dec 25 '19 at 9:04
  • I see. We have different preferences concerning checkpoints etc. Good luck with the dd method :-) – sudodus Dec 25 '19 at 12:05

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.