LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-02-2006, 03:54 PM   #1
slackhack
Senior Member
 
Registered: Jun 2004
Distribution: Arch, Debian, Slack
Posts: 1,016

Rep: Reputation: 47
copying OS to new hard drive


does anyone have any links to instructions or a guide for copying an OS from one HD to another? i guess it's mostly the MBR that i'm wondering about how to do. i already have the second drive partitioned and formatted, set up as a slave, and i was just going to switch it to be the master, install a quick OS on the spare partition along with grub, boot to that, then copy the old hda contents to the new hda, change the bootloader to point to the old kernel (on the new disk), reboot, and hope that works. but the computer has no monitor and i thought there might be an easier way to do it without having to install a new OS, meaning i would have to drag it out of the garage, hook up a monitor, keyboard, etc. this is a debian system, btw.
 
Old 06-02-2006, 04:03 PM   #2
juanbobo
Member
 
Registered: Mar 2005
Location: Chicago
Distribution: Gentoo AMD64
Posts: 365

Rep: Reputation: 30
Check the "dd" man page. If the new partition is the same size you could just do a dd if=/dev/hdaX of=/dev/hdbX where 'hd*X' is the partition of the originating partition (if) and the destination (of).
 
Old 06-02-2006, 04:13 PM   #3
slackhack
Senior Member
 
Registered: Jun 2004
Distribution: Arch, Debian, Slack
Posts: 1,016

Original Poster
Rep: Reputation: 47
yeah, i already thought of that, but the partitions aren't the same size. out of curiosity, does that also copy the MBR? and could i do that from within the partition i'm trying to copy?
 
Old 06-02-2006, 04:16 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
dd is the right tool indeed.

If the hdds have same size/geometry a simple

dd if=/dev/hda of=/dev/hdc bs=2048

would work.


Cheers,
Tink
 
Old 06-02-2006, 04:17 PM   #5
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 60
it should copy everything from the input file to the output file, or in this case, devices. the MBR is on the device, so it should copy that as well. id imagine itd be best to use a liveCD, such as DSL, running in ram, when you issue the command. lets see what others think.
 
Old 06-02-2006, 04:26 PM   #6
slackhack
Senior Member
 
Registered: Jun 2004
Distribution: Arch, Debian, Slack
Posts: 1,016

Original Poster
Rep: Reputation: 47
they are both the same size, 40GB, but the first one has ~10GB corrupted sectors and stuff at the beginning that are partitioned off and i haven't been using (i dropped it while it was running about a year ago ). that's why i'm switching them. the bad one only gets 1961984 *bytes* on hdparm, with all the right settings, so i know it's on the way out. i think i'd be hesitant to copy the entire thing with dd in those circumstances.

Last edited by slackhack; 06-02-2006 at 04:28 PM.
 
Old 06-02-2006, 05:04 PM   #7
Brian1
LQ Guru
 
Registered: Jan 2003
Location: Seymour, Indiana
Distribution: Distribution: RHEL 5 with Pieces of this and that. Kernel 2.6.23.1, KDE 3.5.8 and KDE 4.0 beta, Plu
Posts: 5,700

Rep: Reputation: 65
Ghost for Linux works great. Just download the ISO and burn the image to a cd. Reboot with the cd.

Brian1
 
Old 06-02-2006, 05:24 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by slackhack
they are both the same size, 40GB, but the first one has ~10GB corrupted sectors and stuff at the beginning that are partitioned off and i haven't been using (i dropped it while it was running about a year ago :o). that's why i'm switching them. the bad one only gets 1961984 *bytes* on hdparm, with all the right settings, so i know it's on the way out. i think i'd be hesitant to copy the entire thing with dd in those circumstances.
In that case ... what's the partitioning scheme on the current
drive? With a flat scheme (only / and swap) I cloned a box
over the net not long ago (using knoppix on the receiving end).

ssh tink@box "cd /;tar cf - /"|tar xf -

After that a
chroot /mnt/hda1; lilo

Similar steps should work with a local copy (of course
you'd have to remove the borked disk and reboot into
rescue-mode with the install-CD).




Cheers,
Tink
 
Old 06-02-2006, 08:48 PM   #9
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
http://www.linuxquestions.org/questi...52#post2231152
 
Old 06-03-2006, 08:59 AM   #10
slackhack
Senior Member
 
Registered: Jun 2004
Distribution: Arch, Debian, Slack
Posts: 1,016

Original Poster
Rep: Reputation: 47
okay, i've managed to copy everything but the MBR quite easily by using the dd command on individual partitions with no options, like in juanbobo's post (e.g., dd if=/dev/hda5 of=/dev/hdb3). i've mounted all the partitions and verified that the data and permissions/owernships are there, and altered the /etc/fstab to reflect the new partition scheme. so i guess i'm back to my original question: how do i transfer the MBR so i can boot this thing? do i use the dd command specifying only certain blocks or sectors? if so, which ones?
 
Old 06-03-2006, 09:33 AM   #11
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 113Reputation: 113
Waste of time to transfer the MBR if you have amended the partition reference, would not say so? This is because the MBR will point to the hard disk address of the previous partition location.

In your case just restore the boot loader into the MBR. Steps are as follow

(1) Boot up a Live CD (or the original installation CD if it has a rescue mode).

(2) Make a temporary directory in /mnt, say this is /mnt/temp

(3) Mount the distress Linux partition on /mnt/temp

(4) change root to /mnt/temp (command = "chroot /mnt/temp")

(5) Restore its boot loader

for Grub use command "grub-install /dev/hda"
for Lilo use command "lilo -b /dev/hda"

The above depends on the partition reference in /boot/grub/menu.lst & /boot/grub/device.map has been correctly updated for Grub. The equivalent for Lilo is /etc/lilo.conf but Lilo does not has a corresponding text version of device.map. I have of course assumed that you have edited the /etc/fstab correctly as claimed.
 
Old 06-03-2006, 09:45 AM   #12
slackhack
Senior Member
 
Registered: Jun 2004
Distribution: Arch, Debian, Slack
Posts: 1,016

Original Poster
Rep: Reputation: 47
yeah, i have to use knoppix or something now. i tried chrooting the new root partition and writing grub again, but it didn't work. i think i overwrote my old MBR with the new scheme somehow (or maybe mixed up an HDx,x or something -- i'm more used to lilo ), and now neither will boot. it should be no problem with a boot CD, just a matter of hooking up a monitor, kb, etc. at least next time i know the mistakes.

Last edited by slackhack; 06-03-2006 at 09:46 AM.
 
Old 06-03-2006, 11:13 AM   #13
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 113Reputation: 113
May be I should talk you into making a bootable Grub floppy with which you can use to boot up any pC system. Just follow the note I have in Task A of the last of my signature. Such bootable Grub floppy has no operating system attached and you use Grub as a mini operating system to boot up the Linux or Windows, using information in /boot/grub/menu.lst or /etc/lilo.conf.

The reason why such a bootable floppy can be your salvation is on booting it up you get a Grub prompt.

(a) Typing "help" will enable you to see all the command available.
(b) Typing "geometry (hd0)" will list out all the partition in the first bootable disk (hd0), Grub counts from 0!
(c) Typing "cat (hd0,1)/boot/grub/menu.lst" will list the content of the Grub configuration file in the 2nd partition of 1st disk.

You can then enter the lines of menu.lst, one at the time, adjust with the correct partition reference to boot up the system manually. With a bootable Grub floppy you can boot up any system in a PC without any prior knowledge of what is inside its hard disks.

All the instruction to boot each system in your PC is inside menu.lst. If your Linux has no Grub but Lilo then you can convert the Lilo information into the Grub command to boot that Linux.

How difficult can that be to type between 3 to 4 line to boot a system manually? There is no better way to learn booting by booting it manually. Grub will stop you if any of the entered line doesn't work and so you can repeat by trial and error to get to the bottom.
 
Old 06-03-2006, 02:30 PM   #14
slackhack
Senior Member
 
Registered: Jun 2004
Distribution: Arch, Debian, Slack
Posts: 1,016

Original Poster
Rep: Reputation: 47
thanks, i will definitely make a grub boot disc.

just for the record, and so i have a copy of what i did in case i lose my notes , here are the complete steps i took in copying the drive and making it bootable. the dd ultimately failed, i guess because the partitions were not the same size, so it wouldn't boot saying there was no kernel installed. so after wiping the partitions clean again, what i did is this:

1. set up target drive as hda, source drive as hdb
2. boot to knoppix
3. mount all filesystems of both drives at /mnt/hdax or /mnt/hdbx
4. cd to partition of source to be copied
5. copy contents of source partition to target partition with command:
Code:
find ./ -xdev -print0 | cpio -pa0V /mnt/hdax
6. repeat for all partitions
7. unmount the boot partition (/mnt/hda2 in this case) if it's not on /
8. chroot the new root partition (chroot /mnt/hda3 in this case)
9. mount /dev/hda2 boot (if necessary)
10. grub-install /dev/hda

reboot, and it works like a charm. the entire process takes about 10 minutes, not counting any time needed to copy the filesystems.

Last edited by slackhack; 06-03-2006 at 02:32 PM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Needing help copying large hard drive to smaller drive sdubble Linux - Software 1 02-21-2006 12:06 PM
Copying from one hard drive to another Cirdan Linux - Hardware 3 01-08-2006 06:00 AM
Copying one hard drive to a partition and having it bootable... how? Nebetsu Linux - Hardware 24 01-02-2006 01:07 PM
need help copying a hard drive valueduser Linux - General 6 10-17-2003 08:26 AM
copying current setup to new hard-drive noshellswill Linux - Hardware 3 10-14-2003 09:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:20 AM.

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