LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-12-2013, 12:27 PM   #1
jms89
Member
 
Registered: Jan 2013
Posts: 41

Rep: Reputation: Disabled
Question 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!
 
Old 01-12-2013, 07:00 PM   #2
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,982

Rep: Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626Reputation: 3626
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.
 
Old 01-12-2013, 10:28 PM   #3
mreff555
Member
 
Registered: Sep 2011
Location: Philly
Distribution: Gentoo
Posts: 473

Rep: Reputation: Disabled
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.
 
Old 01-12-2013, 11:01 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
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.
 
Old 01-12-2013, 11:16 PM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by syg00 View Post
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
 
Old 01-13-2013, 03:38 PM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
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.
 
Old 01-13-2013, 04:14 PM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.
 
Old 01-13-2013, 05:37 PM   #8
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
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.

Last edited by haertig; 01-13-2013 at 05:41 PM.
 
Old 01-13-2013, 09:37 PM   #9
jms89
Member
 
Registered: Jan 2013
Posts: 41

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by haertig View Post
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.

Thanks a ton for the help!
 
Old 01-13-2013, 11:49 PM   #10
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Quote:
Originally Posted by jms89 View Post
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.

Last edited by haertig; 01-13-2013 at 11:50 PM.
 
1 members found this post helpful.
Old 01-14-2013, 12:23 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
1 members found this post helpful.
Old 01-14-2013, 12:55 AM   #12
jms89
Member
 
Registered: Jan 2013
Posts: 41

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by haertig View Post
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!
 
Old 01-14-2013, 01:00 AM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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
 
Old 01-14-2013, 09:51 AM   #14
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
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/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LVM repair of working disk with corrupted but known partition structure wgtthompson Linux - Server 1 09-08-2010 05:33 AM
Copying jpegs recursively while preserving the directory structure jsmith54 Linux - Newbie 1 08-09-2010 07:17 PM
Preserving Hard Disk Partition Boundaries Woodsman Linux - Hardware 1 10-03-2008 03:12 PM
preserving dates when backing up files newbiesforever Linux - General 8 08-17-2007 12:17 AM
Preserving directory tree structure /etc/fstab Hikito Linux - Newbie 1 09-11-2004 04:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration