LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   dd or tar? why? (https://www.linuxquestions.org/questions/linux-newbie-8/dd-or-tar-why-4175555686/)

a22an 10-09-2015 02:33 AM

dd or tar? why?
 
i want to backup a:
1- boot sda1
2- / sda6
3- /home sda7
i did:
Code:

boot from mint live usb
df -k
dd if=/dev/sda1 of=/media/tu/mon/aa/bootimg5-10-2015.iso bs=4096 conv=notrunc,noerror
dd if=/dev/sda6 of=/media/tu/mon/aa/backimg5-10-2015.iso bs=4096 conv=notrunc,noerror
dd if=/dev/sda7 of=/media/tu/mon/aa/homeimg5-10-2015.iso bs=4096 conv=notrunc,noerror


but i want to do this with tar:
i did:
Code:

boot from mint live usb
tar cvzf bootimg5-10-2015.tar.gz /media/tu/mon/aa/
tar cvzf backimg5-10-2015.tar.gz /media/tu/mon/aa/
tar cvzf homeimg5-10-2015.tar.gz /media/tu/mon/aa/


please advice me?

pan64 10-09-2015 02:39 AM

dd works on the raw device (or with a single file, which is an image of a divice), it will not really take care about filesystem, files and dirs on that device, tar can only work with files.
What kind of advice do you need?

a22an 10-09-2015 03:09 AM

thanks pan64,
so i understand you say tar is better for backup a (boot partition, root partition and home partition)?

pan64 10-09-2015 03:32 AM

What is your real goal? What do you need?
tar can only handle files and not full partitions.

a22an 10-09-2015 04:47 AM

Quote:

Originally Posted by pan64 (Post 5432054)
What is your real goal? What do you need?

i install Linux every month, 'training'
i want to shorten time to make a copy of Linux distro and recover it.
dd or tar?

pan64 10-09-2015 04:49 AM

in that case I suggest dd.

Teufel 10-09-2015 05:07 AM

dd creates partition or drive image (including bootloader, MBR, partition table, MFT, filesystems).
tar creates an archive that consists of files that belongs to filesystem, only files, without partition/drive/filesystem information, bootloader images at MBR.

Using dd you can restore system easily, but your partition layout should be the same as it was at dd image creation time. You shouldn't repartition your drive before restoring system from dd image.

With tar archive you can restore system to any partition that has enough space to fit unpacked filesystem.
However, you have to restore bootloader (if you changed partitions layout or if you restore a system to other drive).

In general using tar is faster than using dd because tar worsk at filesystem level.

Added:
Take a look at this article, it was written for Gentoo, but it works for any Linux.
http://www.gentoo-wiki.info/HOWTO_Custom_Stage4

I use it to backup my system.

jpollard 10-09-2015 05:58 AM

In general tar works faster because it doesn't copy unused blocks or metadata blocks. It only copies data, with file identification (name+permissions+attributes). This makes the archive MUCH smaller than is possible with dd.

The fastest way to "recover" a system is to use PXE with a customized initrd.

The initrd can then create the partitions and filesystems needed, use an NFS mount to access the tar files, and restore the filesystems, reinstall the boot.... and if necessary, reboot/halt the system.

That way all you have to do is issue the pxe boot request.

a22an 10-09-2015 04:47 PM

thanks all, another question:
is dd make formate to the partition when extracting iso?

jpollard 10-09-2015 08:01 PM

That depends on what you mean.

dd of an entire disk (such as /dev/sda) will copy everything -boot block (if any), partition table, filesystems... everything.

When copied to another disk (same size or larger) everything is copied back exactly the same.

dd of a partition (such as /dev/sda1) will copy everything in /dev/sda1. It will NOT copy the boot block (if any) it will NOT copy the partition table. It WILL copy just the filesystem in /dev/sda1.

This means that before that copy can be restored, the target disk must be partitioned (the same size or larger than the original partition), then the backup can be copied to that partition. If the partition is LARGER than the original, the filesystem must be retuned to set the new larger size (see the manpage/google on growfs, and you may have add that utility to use it) or the filesystem will just not use the larger size.

a22an 10-10-2015 05:04 AM

Quote:

Originally Posted by jpollard (Post 5432353)
That depends on what you mean.

I mean when i was using windows and make formate to partition many times it cause a bad sector to hard disk,
could dd make bad sector too when i use it too many?

pan64 10-10-2015 05:21 AM

no, dd cannot make bad sector, but may find one.... (or more)

jpollard 10-10-2015 05:46 AM

Quote:

Originally Posted by a22an (Post 5432458)
I mean when i was using windows and make formate to partition many times it cause a bad sector to hard disk,
could dd make bad sector too when i use it too many?

As stated above, dd cannot create bad sectors.

If a bad sector IS found, the disk should replace it with a good sector... unless the list of replacements has been exhausted (in which case, the disk has to be replaced).


All times are GMT -5. The time now is 12:22 AM.