Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm working on a system of how to back up partitions using dd and have been reading a lot about it. I have a few questions and assumptions that I would like to ask.

These may seem a little noob-ish, but that's exactly what I am as far as System/Server administration goes. I'm a young programmer who is starting to learn Linux system admin stuff (because it's fun!).

Assumptions that I would like verified or discredited:

  1. I cannot back up an entire partition to a DVD unless that partition is smaller than the available DVD space. AKA the outfile argument must have enough space. E.g. if I wanted to back up an LVM partition that is a terabyte, I must have a location/partition with at least a terabyte of free space (give or take a little if I gzip it).

  2. I cannot use dd to create a bootable version of a partition to a DVD or USB.

  3. I can use dd to create a bootable partition on a second disk drive.

  4. If I wanted to back up a live system, is the best way to boot from a live cd or second partition? (Then unmount the partition I want to back up, or mount it as read only).

Questions:

  1. If I use dd to copy sda to sdb and sda has 1TB of disk space and sdb has 2TB, will the extra space be unusable until I reformat/partition it?

  2. If a partition will fit on DVD and I write to it by using

    dd if=/dev/sda1 of=/dev/dvd
    

(will this even work?) Or is it better to write sda1 to an image file, and then burn a data DVD with the image file on it?

share|improve this question
    
The common method to back up a live filesystem using dd would be to create a snapshot first (you are using LVM, aren't you?) and run the copy operation from there. This way you would not introduce any downtime into your running system. –  syneticon-dj Dec 20 '11 at 21:21
    
Personally, I wouldn't back up using dd. I'd back up using rsync. –  Paul Tomblin Dec 21 '11 at 1:22
1  
Please don't ask so many questions in one; you have several very loosely related concerns in there, including what dd does, DVDs vs hard disks vs USB sticks, backing up a partition, backing up a live system, … –  Gilles Dec 21 '11 at 1:58
add comment

migrated from serverfault.com Dec 20 '11 at 21:43

This question came from our site for professional system and network administrators.

3 Answers

  1. Correct. However, you can split an image after you create it with most archiving utilities.
  2. Also correct, boot-from-CD systems need a special boot loader, and often have hard-coded mount points etc., that don't carry over.
  3. Correct, remember you have to point the BIOS to which disk to boot from.
  4. Either way works, booting with a LiveCD, etc. is the best approach.

  5. Correct, you can use gparted to resize the partition to consume the whole disk, or make a new partition.

  6. I do not believe dd will write and master DVDs properly. Like you said, write to an image, then burn the image as a "file" on the DVD.

Happy sysadmin-ing! And welcome to SF!

share|improve this answer
add comment

Assumption 1: I cannot back up an entire partition to a DVD unless that partition is smaller than the available DVD space.

Yes, your (compressed, if you like) backup must fit in the available space. No surprises there, you can't fight against the math.

Assumption 2: I cannot use dd to create a bootable version of a partition to a DVD or USB.

Not quite true: you can't create a bootable DVD with dd or other byte-level tools because optical disks have a different layout from hard disks and flash disks. You can use dd to clone a hard disk partition onto a USB stick; your only limitation is that the partition must fit on the stick, but see also Cloning a bootable USB stick to a different-size stick.

Assumption 3: I can use dd to create a bootable partition on a second disk drive.

Yes. You can use cat, too, since the magic is not in dd but in the device file /dev/sda or the like; see dd vs cat -- is dd still relevant these days?. Browse the tag on this site for examples.

Assumption 4: If I wanted to back up a live system, is the best way to boot from a live cd or second partition?

You can back up a system from itself too, that's what most people do. But fully backing up a live system has some limitations:

  • The backup will be that of a live system, not of a properly shut down system. It will be indistinguishable from having backed up a system that just crashed.
  • The backup may be inconsistent, i.e. it may show a state of the system that never existed. That happens when an application always modifies file A then file B, but the backup process backed up file A just before the application touched both files and file B later, after the application has modified it, so that the back up contains the old A and the new B whereas this never happens on the live system. Whether that matters depends on the applications you run on your system. It is vital for databases, and in fact databases are not normally backed up by copying files but by dumping them (i.e. building a sequence of commands that would recreate the database). Most other applications can cope.
  • If you back up a live system naively, you must back up at the file level, not at the volume level. At the partition level, the chance of getting an inconsistent, unrecoverable backup is very high.

    You can make a consistent volume-level backup by taking a snapshot of the volume. LVM is a typical way of making volume snapshots (the volume must be an LVM logical volume, not a partition).

Question 1: If I use dd to copy sda to sdb and sda has 1TB of disk space and sdb has 2TB

Then half the space on sdb will be wasted. It would be easier to back up only the partition(s) on sda. Alternatively, back up sda as a whole, then edit the partition table on sdb to add one or more partitions occupying the second TB.

Question 2: If a partition will fit on DVD and I write to it by using dd if=/dev/sda1 of=/dev/dvd

Note that this command is equivalent to cat /dev/sda1 >/dev/dvd. It won't work so easily, because writing to optical disks is not straightforward: they are not random-access devices like hard disks and flash disks, you need to write them all at once (or at least large chunks at once) at a controlled speed.

You can use software such as CDRecord, Cdrkit/wodim or DVD+RW-tools/Growisofs to burn either a straight volume image (containing the usual filesystem, e.g. ext4) or an ISO 9660 filesystem, which is the filesystem typically found on CDs and many DVDs. With the Rock Ridge extension, which is supported by almost every Unix system, you can put the usual Unix metadata (hard links, symbolic links, permissions, case-sensitive names, …) on an ISO 9660 filesystem.

Alternatively, you can use packet writing and treat the DVD like any other volume, if your system supports it.


Finally, advice:

  • If you want a straight copy of your system, use a volume management system that permits snapshotting, such as LVM (where you create snapshots of logical volumes) or any RAID-1 system (add a component to the array, synch, remove a component from the array).
  • For everyday use, make incremental file backups (i.e. back up only the files that have changed, or even only the parts of files that have changed).
  • Asking about dd is the wrong question at this stage (and not just because the answer is that dd doesn't matter). First, you need to get a clear idea of what you want to back up, where and when. Learn to separate policy from implementation. Once you know what you need to achieve, study what tools would best reach your objectives.
share|improve this answer
    
Just... Wow. Where from do you get the energy to write all these thorough answers just like that? You use meditation, Jedi powers or what? –  rozcietrzewiacz Dec 21 '11 at 8:06
add comment

You're better off writing sda1 to an image file and then burning that to a CD. While theoretically you could get away with the direct dd method, it probably wouldn't work the way you expect it to, since DVDs are generally assumed to be formatted with either ISO9660 or UDF, while your partition is (probably) formatted with ext(2,3,4).

As a bonus, you can compress the image file before storing it on the CD.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.