LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   copying OS to new hard drive (https://www.linuxquestions.org/questions/linux-general-1/copying-os-to-new-hard-drive-451012/)

slackhack 06-02-2006 03:54 PM

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.

juanbobo 06-02-2006 04:03 PM

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).

slackhack 06-02-2006 04:13 PM

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?

Tinkster 06-02-2006 04:16 PM

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

nadroj 06-02-2006 04:17 PM

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.

slackhack 06-02-2006 04:26 PM

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.

Brian1 06-02-2006 05:04 PM

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

Brian1

Tinkster 06-02-2006 05:24 PM

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

jiml8 06-02-2006 08:48 PM

http://www.linuxquestions.org/questi...52#post2231152

slackhack 06-03-2006 08:59 AM

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?

saikee 06-03-2006 09:33 AM

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.

slackhack 06-03-2006 09:45 AM

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 :o), 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. :p

saikee 06-03-2006 11:13 AM

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.

slackhack 06-03-2006 02:30 PM

thanks, i will definitely make a grub boot disc. :cool:

just for the record, and so i have a copy of what i did in case i lose my notes :D, 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. :cool:


All times are GMT -5. The time now is 10:48 PM.