[SOLVED] Backing up disk while preserving partition structure?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
Mind to elaborate a little? A reference to something on the web is also fine
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.
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.
Yes since posting I was thinking that something along these lines would make much more sense, and I'm glad it's doable! My swap partition IS an extended parition (The default mint installation set this up... don't know why) but I can change that easily, since it's the only parition on there. In the future if I need to add more paritions I'll worry about how to back them up.
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.
My swap partition IS an extended parition (The default mint installation set this up... don't know why) but I can change that easily, since it's the only parition on there.
There is absolutely no need to backup swap. You don't want to do that. You want to backup up the PARTITIONING INFO that defines where SWAP is, but not the data contained in SWAP itself.
Quote:
In the future if I need to add more paritions I'll worry about how to back them up.
When you have LOGICAL partitions (these are contained within an EXTENDED partition to be absolutely correct, but often times the words "extended" and "logical" are interchanged - not technically accurate, but you see it all the time), one of the entries in the main partition table (contained within the MBR within Track 0) points to an EXTENDED PARTITION TABLE. This extended partition table does not reside in Track 0, so backing up Track 0 does not cover that extended partition table that is off somewhere else on your disk (location obviously will vary).
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:
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.
GRUB is a large bootloader. It will not fit entirely into Track 0. However, the FIRST PART of GRUB is indeed stored in Track 0. Then the remainder of it is stored in a regular partition. The part from Track 0 points to the remainder of it in a regular partition. This "remainder of it" will be found in the /boot filesystem of your LinuxMint installation, unless you changed that during the install.
Quote:
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.
Yes. Everything stored on your computer (for the purposes of this discussion) are stored in FILES in some partition. Microsofts activation stuff is stored somewhere, I can't say exactly where, but probably in "the registry". The registry is nothing more than a file - files, plural, actually - when Windows is not running. And Windows will not be running if you were doing backups from Linux. So Windows is reduced to nothing more than a collection of files, and tar can back all of those up.
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.
There is absolutely no need to backup swap. You don't want to do that. You want to backup up the PARTITIONING INFO that defines where SWAP is, but not the data contained in SWAP itself.
When you have LOGICAL partitions (these are contained within an EXTENDED partition to be absolutely correct, but often times the words "extended" and "logical" are interchanged - not technically accurate, but you see it all the time), one of the entries in the main partition table (contained within the MBR within Track 0) points to an EXTENDED PARTITION TABLE. This extended partition table does not reside in Track 0, so backing up Track 0 does not cover that extended partition table that is off somewhere else on your disk (location obviously will vary).
...
Yea I understand I wouldn't want to backup the swap partition, I was just commenting that right now, my swap partition is stored as a logical partition in the extended partition /dev/sda3, but that I could just delete the extended partition and make a new swap partition as primary. (and yup I'm aware I'll have to update my fstab most likely)
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.