Backing up disk while preserving partition structure?
Hi, I'm farily new to Linux and I'm getting to the point where my computer is set up in a way I like. I'm dual booting linux mint and windows 7 (each installed on seperate primary partitions) and I have another partition for swap space and a fourth ntfs partition for sharing files between linux and windows easily.
So, my attention now is turning to backing up my system, and understanding how to do so in a systematic way. I would like to back things up in such a way that I could restore my computer to exactly the state it was when I backed it up, including preserving all my partitions and the windows 7 and linux installations. I think what I want to do is make an image of my disk, but I'm not sure how exactly to do it, and if it will preserve my partitioning. Also, once I have things backed up, I'm not entirely sure how'd I'd use the backup to restore my system, in the event I ever had to. So, if anyone could help me get started I'd really appreciate it! Also, I'd prefer to avoid using GUI packages that do everything for you, because in the future I'd like to set up scripts to automate the whole process for me, but for now I'm just trying to get started doing things manually. Thanks! |
I guess you could dig into how clonezilla uses partimage and other tools to clone a system. There might be a way to command line gparted also.
|
dd can be used to make reliable images of disks if you have sufficient space to back them up.
You would have to use a boot disk to back up or restore your system with this method because all of your system partitions would need to remain unmounted. |
It is very difficult to have any confidence in "dd" images. In error situations it does things you wouldn't inflict on your worst enemy.
And doesn't tell you. clonezilla is an option, as is mondorescue. I happen to like it as I can rebuild an entire system (including Windoze) , and resize and/or change the filesystem type if I want and maintain the data consistency. I write to DVD isos, and keep a copy on a backup disk (2 actually, but that's just me) as well as cutting real DVD's. I'm pretty confident I can rebuild my systems in need. But the whole process is sloooow. Good, but slow to take the initial backup - especially if you validate the backup - as you should IMHO. |
Quote:
|
dd mindlessly copies everything it finds - which is great for forensics/recovery. Not for backups.
If there are any errors in the underlying filesystem(s), they are replicated without awareness. You may think you have a valid backup, but wouldn't you rather know about errors on the filesystem ?. Also guides on using dd (including a large thread here on LQ) advise various combinations of "sync/noerror/notrunc". You'd better be real conversant with their effects on the output before committing valuable data. Personally I always prefer a filesystem aware utility so I know my data is backup up properly. And I also like to able to restore to whatever size media I happen to have at the time - bigger or smaller. |
IMHO, ddrescue is better than dd for image backups. It will adjust its block size on the fly if it reaches a problem spot on the disk, and will retry if it hits a bad block. Unreadable blocks are replaced with zeros. I'd only recommend a bare metal backup for a new installation. Use a file based backup. An image backup should only be used for emergencies.
I'd also recommend backing up the MBR using dd. It can become damaged, and restoring it will restore your partition table quickly. If only the MBR was damaged, the filesystems won't need recovering. Also run "disk -l" and save the results as part of the backup. |
If you only have the four partitions you listed (I'm assuming they are all PRIMARY partitions, not EXTENDED/LOGICAL partitions), then I would recommend backing up "Track 0", which contains your MBR - Master Boot Record - which in turn contains your Partition Table. Track 0 also most likely includes part/all of your boot loader, but this depends on the specific boot loader. This Track 0 backup is all you would need to restore the partitioning part (again, assuming you don't have EXTENDED/LOGICAL partitions). So with this copy of Track 0, and individual backups of each partition, you have everything you need to do a restore.
Or, you could image the entire disk as you proposed, but that will take a lot of backup space. This is how you can backup Track 0 (this is "creating an image of it"): dd if=/dev/sda of=track0.bin bs=512 count=63 Note that you will need to change /dev/sda to match your particular systems description of your primary hard disk. Also, do NOT mix up "if" and "of" in the dd command, lest you end up with quite a mess! Double-check your typed command before you hit ENTER!!! To backup ONLY the MBR, not the entire Track 0, change the above command to: dd if=/dev/sda of=mbr.bin bs=512 count=1 Now you can separately backup each partition. I would not back these up as images, instead I would use cp, rsync, tar, cpio, ntfsclone, and/or many other available programs to do the individual partition backups. An "image" copies the entire partition, whether all of it it is being used or not. The other programs I mentioned above backup the files on the partition, not the raw bits. So unused portions of the partition are not backup up (and you don't need to back them up, unless you potentially plan on trying to resurrect deleted files from them). So these non-image backups will be much smaller, easier to access for a newbie, potentially allow for "incremental" backups (if you do it correctly), etc. |
Quote:
How can I find out if indeed my bootloader is stored on track 0, if I wanted to back that up as well? I'm using GRUB2. Also, supposing I just tar my whole windows partition... will this preserve the windows activation (assuming no major hardware configuation changes)? I'd like to have as little to do with Microsoft in the future as I can, and would hate to have to call them to have my validation key re-authenticated. Thanks a ton for the help! |
Quote:
Quote:
When you use something like fdisk to view your partitions, fdisk knows how to follow pointers from the main partition table into extended partition tables, and that is why fdisk is able to show you your whole partitioning structure (both primary partitions and extended partitions). But fdisk is doing this by following those pointers. If you only backup Track 0 then you are not following those pointers. That's why I mentioned a warning on this. You can "solve" the issue by only using primary partitions. Or you can research and find out how to follow the pointers. Basically, an extended partition has it's own partition table right at the front of it, similarly to the way the main partition table is stored in Track 0 at the first part of the DISK. And one of the entries in that extended partition table can point to yet another different extended partition table. which can point to still another extended partition table, and so on. Sorry about that poor explanation. It probably muddied the waters more than clarified them! There is a guy named Dan Goodell who has a very complete explanation of multibooting. Part of that is discussion about partition tables and such. His webpages are quite old, and address the issue of how to multi-boot Windows from an extended partition. This is something that many people believe is impossible. It's not, but you have to understand all this partition table stuff. Anyway, here's a link to Dan's stuff (remember it is Windows-centric and old) and you can learn alot from reading through his pages (this stuff applies to partitioning, not Windows, even though it is presenting within a WIndows multi-booting context): http://www.goodells.net/multiboot/partitions.shtml http://www.goodells.net/multiboot/ptable.shtml There is lots of good stuff on Dan's webpages, just nose around a bit to uncover it. Dan's stuff is also invaluable if you do something like backup Windows from, say, the second partition and then try to restore it to the third partition. While this would not present a problem for Linux, Windows doesn't like it. This is where many people pull out their hair and yell "Norton Ghost screwed up my backups". Ghost (an old program) can sometimes restore Windows to a different partition than where it came from, but sometimes it fails. This is where you fall back to Dan's info on "boot records" and stuff like that to fix it yourself. Not for the squeemish. I have done it several times myself - just for the practice - so I know I can fix any Windows booting problem I may encounter. Unfortunately, now that I've pretty much abandoned Windows, I haven't played with it for years. But I still retain a basic comprehension of the things involved, and know where to look to get the details (Dan's webpages). Quote:
Quote:
|
You also don't want to backup /sys or /proc.
Note that if you do use a tool that backs up everything(!) eg clonezilla, mondorescue, systemimage, ddrescue etc, you have to restore to the same HW, as they backup the device drivers, kernel settings etc. If you may be restoring to a non-identical HW, use a file aware backup and be prepared to install just the bare OS, then restore your file-level backup. |
Quote:
Thanks for all the info and advice though, it's been very helpful! I think I have enough to get me started writing some scripts and getting stuff backed up. I'll be sure to read through those links tomorrow. I've been using linux now for about two weeks, and it's been a great learning experience so far. I'm sure over the next few months I'll learn more about how my computer works than a lifetime of using windows would ever teach me! |
If you're that new, you may find these useful
http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ http://www.linuxlinks.com/article/20...03/Backup.html Enjoy :) |
Also, make sure you DON'T do this! (Poor fellow - it might be recoverable, but still quite the hassle.)
http://www.linuxquestions.org/questi...sk-4175445523/ |
All times are GMT -5. The time now is 08:26 PM. |