LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 02-10-2005, 04:42 PM   #1
jobless_joe
Member
 
Registered: Apr 2004
Posts: 49

Rep: Reputation: 15
Copying partitions and grub too


I need to copy a whole hard drive to another hard drive (same hardware, os->hardware issues not a problem), but grub doesn't seem to be working. The computer I want to copy to a bunch of others has windows 98 and redhat 9 using grub to dualboot.

The problem is, when I try to copy the hard drive to another computer with norton ghost (it copies the mbr and bootsector, i think) it just comes up with a black screen that says "grub" at the top left (non-gui) what went wrong? and how does that whole "grub stage1, 2, and 3" work. What are they?
 
Old 02-10-2005, 06:45 PM   #2
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
Here's some info.
http://www.rajeevnet.com/hacks_hints...s_cloning.html
 
Old 02-10-2005, 08:55 PM   #3
jobless_joe
Member
 
Registered: Apr 2004
Posts: 49

Original Poster
Rep: Reputation: 15
Good stuff..but in this scenario, do you still have to partition the drive before you run dd? That meaning, could I just have a brand new drive, and clone it with dd, with dd creating all the partitions for me? also, is there a reason ghost didnt work? and is there a switch for dd to copy JUST the mbr or the bootsector of a partition?
 
Old 02-10-2005, 09:10 PM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
jobless_joe,
If you are interested, I made a script for saving an entire hard drive ( with MBR and partition table ) ,
then another script for restoring that complete setup to a new drive.
I setup a drive with all operating systems and software. Primary Master /dev/hda
Then I install another drive , create a partition for saving my images onto. Secondary Master /dev/hdb1

Boot up with Knoppix cd , mount the partition where the scripts are saved and this is also where the images will be saved to.
mount /dev/hdb1 /mnt/hdb1
Now run the save script which you made executable.... ./save /dev/hda
After you have successfully save everything, swap out the Primary Master /dev/hda with a blank drive so you can run the restore script which you made executable.... ./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
 
  


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
Hacking GRUB via copying MBR, need to find address of Stage2 Feebles Linux - Software 1 12-11-2005 12:20 PM
suse and partitions with grub cartman12345 SUSE / openSUSE 4 11-10-2004 02:30 AM
fixing partitions in GRUB aryth Linux - Newbie 12 08-23-2004 12:18 PM
Installing (copying) grub from floppy to MBR caphclimber Linux - Software 2 09-13-2003 01:41 PM
Deleted partitions, stuck in grub Linux_n00b Linux - Newbie 1 11-30-2001 01:31 PM

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

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