LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-28-2005, 11:48 AM   #1
jharris1993
LQ Newbie
 
Registered: Dec 2002
Location: Masachusetts
Distribution: Various Linux & Windows distros.
Posts: 14

Rep: Reputation: 0
How to backup and restore a multiple partition hd?


I actively use both M$ and Linux operating systems.

I do a lot of software and o/s testing, and it is not uncommon for me to have (for example) both an XP and a Fedora install on the same laptop.

Previous to this, I would use the PowerQuest tools (Partition Magic and Drive Image) for my M$ stuff, and for the Linux stuff, I'd just "take it on the chin"

Things have changed.

1. Symantec bought up PQ, and I don't like Symantec's implementations.

2. The Windows products have never handled Linux partitions as well as the M$ flavored partitions.

3. My Linux installs are becoming more and more complex, and I want to get away from the idea of a "throw-away" linux install. I'm investing more and more time in getting my linux installs "just right" with the networking, wireless, and other quirky preferences set "just the way I like 'em" - so I'd like to be able to backup and restore a Linux install as well.

4. It is not uncommon for me to take a system (a laptop, for example) and want to (temporarily) blow it away, install something, and then restore it to its previous condition after the experiment is finished.

I did some web searching and found two potentially useful tools on the latest Knoppix CD/DVD distro:

qtpartm - a "partition magic" replacement that handled my XP-SP2 image resizing very nicely, thank you...

partimage - a "console" (looks like an old "DOS" based app) tool that claims to be able to backup and restore individual partitions from a disk. (Which, I might add, I have not tried yet)

What I want to find:

I liked the way qtpartm worked so well, I would love to find a "qtdrivei" (drive-image clone)

Ideally it should:

1. Have a nice GUI interface.

2. Be able to image and restore an entire hard drive with multiple partitions on it - as well as the individual partitions themselves. This should include both NTFS and "Linux" partitions.

3. Be able to do a "bare metal" restore - I should be able to pop a new hard drive into a box and restore it to a bootable, working system (status-quo-anti) with a minimum of fuss, preferably w/o having to manually re-create the partitions I'm restoring or rebuild the MBR.

4. Be able to handle a target drive to restore to that is NOT the same size as the original drive.

5. Be able to copy the image file(s) to a connected USB drive, formatted as either VFAT or NTFS.

6. All of the above, but with the image file being stored on a file server somewhere.

Thanks!

Jim
 
Old 08-28-2005, 12:28 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
You were doing good with partimage until you got to #4 an #5.
#4 Partimage needs to restore to the same size partition so if you want to enlarge partitions, you need to restore one partiton and resize it before restoring the next partition.

#5 I save my images to another partition which can be ext3, or vfat. Saving them to an NTFS partition requires your partimage host system to handle NTFS. That's an extra luggage which I don't care to use.

I use a save script script which I made to backup an entire hard drive and MBR to an image which is saved onto another drive. Using the restore script, you can restore the MBR and image. Like I said, if you want to enlarge partitions, you can restore each partition individually and enlarge it before moving on.

Here are my scripts which do work for me but I don't promise anything for you.
You need to make a mount point to the place where you want to save to.
For example:
mkdir /mnt/images
mount /dev/hdb1 /mnt/images


Run the executable script like this.... ./save /dev/hda and ./restore /dev/hda

save script
Code:
#!/bin/bash
##### This saves the MBR / Partition Table
##### and all partitions using partimage
##### example:  ./save /dev/hda

##############################################
#  Ensure that root is running the script.
#
WHOAMI=`/usr/bin/whoami`
if [ $WHOAMI != "root" ]; then
	echo
	echo "You must be root to run this!"
	echo
      exit 1
fi
##############################################

usage()
{
        echo "Usage: $0 /dev/hd#"
        exit 1;
}

test "$1" || usage

if ! [ -e $1 ]; then
    echo "$1 does not exist. Exiting."
    exit 1
fi

if [ -e $1 ]; then
   #Save the MBR with partition table
   mbrfile=`echo -e $1 | awk -F"/" '{print $3}'`;
   dd if=$1 of=/mnt/images/mbr_$mbrfile bs=512 count=1
   clear
   
   for i in `/sbin/sfdisk -l $1 | \
   grep -e "^[/dev]" | awk '{print $1}'`;
   
do
   a=`/sbin/sfdisk -s $i 2> /dev/null`
   test=$(($a + 0))
   stuff=`echo -e $i | sed -e 's/.\{8\}//'`;
   check=`sfdisk -c $1 $stuff`
   
if [ $check != 5 -a $check != 82 -a $test != 0 ];then

   part=`echo -e $i | awk -F"/" '{print $3}'`;
  #Save the partitions
  #use this method for GUI progress
  partimage save -c -b -d -z0 -f3 $i /mnt/images/$part
  
  #use this method for command line progress
  #partimage save -B=foo -c -b -d -z0 -f3 $i /mnt/images/$part
  clear
fi  
done
echo

else
    exit 1
fi

clear
echo "The save operation is complete"
echo "The images have been saved in /mnt/images/"
echo
exit 0
####End
restore script
Code:
#!/bin/bash
##### This retores the MBR / Partition Table
##### and all partitions using partimage
##### example:  ./restore /dev/hda

##############################################
#  Ensure that root is running the script.
#
WHOAMI=`/usr/bin/whoami`
if [ $WHOAMI != "root" ]; then
	echo
	echo "You must be root to run this!"
	echo
      exit 1
fi
##############################################
usage()
{
        echo "Usage: $0 /dev/hd#"
        exit 1;
}

test "$1" || usage

if ! [ -e $1 ]; then
    echo "$1 does not exist. Exiting."
    exit 1
fi

if [ -e $1 ]; then
clear
echo
echo "********************************************************************"
echo "     Caution!!!     This program will erase your hard drive"
echo
echo -n "                Do you want to proceed (Y/N)?"
read answer
if test "$answer" != "Y" -a "$answer" != "y";
then exit 0;
fi
#
clear
   mbrfile=`echo -e $1 | awk -F"/" '{print $3}'`;
   #Erase the old boot sector
   dd if=/dev/zero of=$1 bs=512 count=1
   
   #Restore the MBR with partition table
   dd if=/mnt/images/mbr_$mbrfile of=$1 bs=512 count=1
   clear
   
   for i in `/sbin/sfdisk -l $1 | \
   grep -e "^[/dev]" | awk '{print $1}'`;
   
do
   a=`/sbin/sfdisk -s $i 2> /dev/null`
   test=$(($a + 0))
   stuff=`echo -e $i | sed -e 's/.\{8\}//'`;
   check=`sfdisk -c $1 $stuff`
   
if [ $check = 82 ];then
   #setup the swap partition 
   /sbin/mkswap $i
   
elif [ $check != 5 -a $check != 82 -a $test != 0 ];then

   part=`echo -e $i | awk -F"/" '{print $3}'`;
  #Restore the partitions
  #use this method for GUI progress
  partimage restore -b -f3 $i /mnt/images/$part.000
  
  #use this method for command line progress
  #partimage restore -B=foo -b -f3 $i /mnt/images/$part.000
  clear
fi
done
echo
else
    exit 1
fi

clear
echo "The restore operation is complete"
echo "The partitions have been restored from /mnt/images/"
echo
exit 0
####End

Last edited by homey; 08-28-2005 at 12:30 PM.
 
Old 08-28-2005, 11:53 PM   #3
jharris1993
LQ Newbie
 
Registered: Dec 2002
Location: Masachusetts
Distribution: Various Linux & Windows distros.
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by homey

You were doing good with partimage until you got to #4 an #5.
#4 Partimage needs to restore to the same size partition so if you want to enlarge partitions, you need to restore one partiton and resize it before restoring the next partition.

#5 I save my images to another partition which can be ext3, or vfat. Saving them to an NTFS partition requires your partimage host system to handle NTFS. That's an extra luggage which I don't care to use.
Thanks for the script, it looks interesting and I will most definitely take a peek.

#5 is not an issue with me since I would do my backups and restores using a Knoppix boot CD - it can see and mount NTFS partitions - and most of the stuff I back up goes to a USB external hard drive. Many of the original external USB drives were vfat, but now they're showing up as NTFS - and I'd like the tool to be as generic as possible...

Part of what I'm looking for is the ability to back up and restore NTFS partitions as well - and if partimage can do this, better and better.

You may not care for NTFS, but it's not going anywhere anytime soon, I have to support it, so I'm stuck with it.

Ideally, what I'd really like to see is a nice GUI app that runs in X - this would make it easier to train people how to use it.

Jim
 
Old 02-23-2006, 08:49 AM   #4
davsnotn
LQ Newbie
 
Registered: Feb 2006
Distribution: RHEL 4
Posts: 15

Rep: Reputation: 0
Hi. I'm pretty green to Linux. I copied and pasted the save and restore text into my Windows notepad and saved it. Then I copied the "save" and "restore" files to my external USB hard drive (uba1). I booted the Linux computer using SystemRescueCd. I then did the "mount /dev/uba1 /mnt/images" command and that went Ok. I accessed the external drive by "cd /mnt/images" and did an "ls" to make sure I could see the two files, and I could indeed see them. When I typed in "./save /dev/sda" I got the following error, "No such file or directory: ./save". Can someone please offer advice?
 
Old 02-23-2006, 09:39 AM   #5
jharris1993
LQ Newbie
 
Registered: Dec 2002
Location: Masachusetts
Distribution: Various Linux & Windows distros.
Posts: 14

Original Poster
Rep: Reputation: 0
Thumbs up

Are you actually within the directory (on the thumb-drive) where the scrpts are located? The "./" part means "find 'save' right here where I am"

Did you set execute permission on the two scripts? This is one of the biggest differences between Windows and Linux (or other Unixes) - and I am constantly getting "caught" that way myself!

In Windows, the ability to execute as code, display as text, or whatever, does NOT depend on the file itself, but on the app you are using to view or manipulate the file. (in the case of executing it, it's the command processor itself) This is why people can do things like "vicious JPG's" in Windows - they can "hide" executable code, scripts, or other nasties in things that you woud not normally associate with being "executables".

In the Unix world - and this includes Linux - you have to specifically grant "execute" permission to a file or script before you can run it.

(It's been a while, and damn if I've forgotten the permissions command - I'll probably remember 30 seconds after I send this off!)

Do you have a copy of "Linux for Dummies" (or Unix for Dummies)? How about O'Reilly's "Unix in a Nutshell"? There's also "Essential System Administration" - these are the books I go to when I have a "... and how am I supposed to do THAT!!" kind of question.

You can also go to any competant search engine and search on something like "Unix change permissions" - and get more info than you really need

Jim
 
Old 02-24-2006, 07:59 AM   #6
davsnotn
LQ Newbie
 
Registered: Feb 2006
Distribution: RHEL 4
Posts: 15

Rep: Reputation: 0
Thank you for the reply. I changed the permissions using the "chmod 777 save" command. I am in the directory where the file is located. I typed in "ls" just to make sure they listed out. It's really odd that I still get the error when I try to run "./save /dev/sda" and see "No such file or directory: ./save". Is there a reason why I can see the file when doing an "ls" but not be able to execute it even though I set the permissions?
 
Old 02-24-2006, 09:00 AM   #7
davsnotn
LQ Newbie
 
Registered: Feb 2006
Distribution: RHEL 4
Posts: 15

Rep: Reputation: 0
I figured out the issue. Linux didn't like the fact that the text files were originally from a windows environment. I did all of my copying and pasting from the website in Linux and resaved the files to my external drive. It now works. I still don't understand the error since the file was there. I would have expected a different type of error.
 
Old 02-24-2006, 01:10 PM   #8
jharris1993
LQ Newbie
 
Registered: Dec 2002
Location: Masachusetts
Distribution: Various Linux & Windows distros.
Posts: 14

Original Poster
Rep: Reputation: 0
Wink

Two things:

1. I try not to chmod "777" unless I absolutely have to. The key here is to grant permissions as sparingly as possible. This way, if something wierd does happen, or your computer is compromised, you've limited the amount of damage that can be done. "744" or "755" are usually better choics depending on what you need done.

2. Go to www.ultraedit.com, and download their latest release.

The "text" issue you noticed is based on the differing way that the "Unix" world and the "Windows" (non-unix) worlds handle end-of-line.

* Non-unix systems typically end lines with a CR/LF pair, (0x0A/0x0D)
* Unix systems typically end lines with only a CR (0x0A), expecting the printer, or print driver, to accomodate it.

Ultra edit allows you to convert from "DOS" (CR/LF) to "Unix" (CR) formats.

If you do some snooping around on the web, you may find utilities that do this - it's fairly easy to write in C, so you could even play with it as an exercise if you're set up to write C code.

If both systems are live, and you can FTP to the Linux box, if you do an "ASCII" transfer, the conversion is done for you.
 
Old 03-15-2006, 07:04 AM   #9
MultiBooter
Member
 
Registered: Aug 2003
Distribution: Ubuntu 6.10 / SUSE 10.1
Posts: 56

Rep: Reputation: 15
Another way to help with the end-of-line issue is to use "Programmer's File Editor" which was written by Alan Phillips. It has an option to save files in Unix format, and I have been using it happily for years. You can set it as the default mode or select it in the "Save As..." dialog. The last version put out was 1.01 and you can find it by searching for "Programmer's File Editor" (with the quotes). He did stop development of it some time ago, but I personally haven't seen a reason he would want to change it.
 
Old 03-18-2006, 01:41 PM   #10
jharris1993
LQ Newbie
 
Registered: Dec 2002
Location: Masachusetts
Distribution: Various Linux & Windows distros.
Posts: 14

Original Poster
Rep: Reputation: 0
Lightbulb partimage restoring to different sized partitions?

This reply is actually to Homey further up the stack.

Quote:
Originally Posted by homey
#4 Partimage needs to restore to the same size partition so if you want to enlarge partitions, you need to restore one partiton and resize it before restoring the next partition.
There is a potential problem here - note this is not a criticzism of partimage, more of a suggestion for an enhancement maybe? - but destination partitions are rarely the same size as the original one, for many reasons.

1. The replacement drive is bigger than the old one. This is a very common scenerio and the restore-and-resize process, though clumsy, will work.

2. The replacement drive is *smaller* than the original. (I can hear you now - "Huh?!!" )

Example: I have an O/S - assume it is critical to me for whatever reason, mounted on a 80 gig HD. When I create the image - the actual image is, say one or two gigs in size... OK. It's 9:30pm on a Saturday. I'm busy doing something important, I have a recent backup, and my drive goes to hell in a handbasket with an ear-splitting screech!

Or, I'm out in the middle of God's Green Nowhere, and the above happens.

Or, maybe I need the 80 gig drive for something else with a larger footprint (Windows? ) and want to transfer to something else.

I need to restore this system ASAP for whatever reason (waiting until tomorrow won't work, or I'm way, way, far away from anywhere that sells HD's, etc.) So, I dig up a 40 gig HD that I have kicking around.

If partimage *absolutely requires* you to restore to the same image size, I'm screwed. The actual image footprint is less than the size of the drive by a huge amount, so there's no way that the image won't fit the drive, it will fit with mucho room to spare. If partimage could do an "automatic resize" - that would be excellent.

Just a suggestion.

What say ye?

Jim

Last edited by jharris1993; 03-18-2006 at 01:44 PM. Reason: Screwed up the "quote" contstruct
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Windows partition backup/restore golinari Linux - General 6 02-20-2005 02:26 PM
backup n restore on multiple cds naren Linux - Software 1 10-14-2004 06:03 AM
Need to backup then restore a linux partition stuart Linux - General 5 07-16-2004 07:30 AM
Why can't I restore a partition table backup containing a reiser partition? oldweasel Linux - Software 2 05-23-2004 12:11 AM
using dd to backup/restore windows partition win32sux Linux - General 9 01-26-2004 03:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:38 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