Solved

Need to move GRUB boot from one hard drive to another

Posted on 2009-07-13
15
1,525 Views
Last Modified: 2013-12-15
I have a debian webserver all up and running.  I've added a new hard drive and need to move the boot to the new drive.  I'm fairly new to linux admin on this level so hang with me.  My problem comes in with the fact that the old drive is an IDE drive and the new drive is a SATA drive.  ( this machine was set up with a Virtualmin boot disc, FYI )

What I've done so far is plug the drive in, image the old drive to the new drive so it exactly mirrors the original drive.  Now I'm still booted on the old drive, but can see the new drive.  It is not mounted, but I can see it and all it's partitions with " fdisk -l " 

The old drive is /dev/hda and has partitions hda1, hda2, hda3.  The new drive is /dev/sda and has partitions sda1, sda2, sda3.

As I understand it, I think the only thing I have left to do is to install grub into the boot sector of the new drive.  Although I have some concerns with things like fstab mounting the drive since there are entries there with /hda.  This makes me wonder if there are other entries hiding in other config files like the ones for quotas and the like.

Any input here would be great.

I imagine what I'll have to do is to edit the files needed to boot and run correctly on the /dev/sda drive, install grub onto that drive, and then reboot.  Maybe a search of the entire hard drive for any files containing " hda " is in order so I can edit them all to point to " sda " ?

Thanks in advance!


0
Comment
Question by:archaic0
  • 9
  • 6
15 Comments
 
LVL 43

Expert Comment

by:ravenpl
ID: 24846831
first locate what partition grub occupies

[wijata@server hydra]$ df /boot/grub/
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1               248895     17487    228838   8% /boot

in my case it's sda1 (Your may be hda1, which is first partition)

run grub, an execute
grub
> device (hd0) /dev/sda ##tells grub that first bios hdd is actually sda (not hda)
> root (hd0,0) ##it tells grub it's installed on hd0,firstPart
> setup (hd0) ##install grub in the mbr of hd0 - sda
> exit
0
 

Author Comment

by:archaic0
ID: 24849187
OK, when I ran df it shows /dev/sda1 mounted on /.  But it shows the size is 74G or so (old hda drive is 80G), but the actual sda drive is a 1TB drive.

dviweb:/# df /boot/grub
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             74312868   6473540  64064460  10% /
dviweb:/#

I did try one thing before this, and that was to edit the grub menu.lst with a new entry and I tried to boot with it once.  It did seem to "work" but things like the drive size were off so I didn't think it worked.  Plus I found some references to the mbr and my image program suggested that the boot sector would not work correctly without intervention.  The code snippet is the boot menu.  

I booted from the new entry once, but did not use that option for the next boot.

So, how do I truly know what is mounted where right now?



title           Debian GNU/Linux, kernel 2.6.18-6-486
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.18-6-486 root=/dev/hda1 ro
initrd          /boot/initrd.img-2.6.18-6-486
savedefault
 
title           New Drive Attempt
root            (hd1,0)
kernel          /boot/vmlinuz-2.6.18-6-486 root=/dev/sda1 ro
initrd          /boot/initrd.img-2.6.18-6-486
savedefault
 
title           Debian GNU/Linux, kernel 2.6.18-6-486 (single-user mode)
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.18-6-486 root=/dev/hda1 ro single
initrd          /boot/initrd.img-2.6.18-6-486
savedefault

Open in new window

0
 

Author Comment

by:archaic0
ID: 24849247
Here is my fdisk -l

There may be some more light here.
dviweb:/boot/grub# fdisk -l
 
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1      121271   974109276   83  Linux
/dev/sda2          121272      121601     2650725    5  Extended
/dev/sda5          121272      121601     2650693+  82  Linux swap / Solaris
 
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1        9399    75497436   83  Linux
/dev/hda2            9400        9729     2650725    5  Extended
/dev/hda5            9400        9729     2650693+  82  Linux swap / Solaris
dviweb:/boot/grub#

Open in new window

0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 43

Expert Comment

by:ravenpl
ID: 24849837
run exactly those commands I proposed.
grub.conf/menu.lst needs to be changed to mount root filesystem from sda1 rather than hda1 (which You almost did)
0
 

Author Comment

by:archaic0
ID: 24850051
I ran those commands, then rebooted (original menu.lst without new drive option).  now my df command shows /dev/hda1 with the 80G size.  Do I now need to edit the menu.lst to have the new drive listed as the code below shows and then choose that menu option to make it go into effect?

When you said "almost did" with the menu.lst, I thought maybe I needed to specify the root to (hd0,0) instead of 1,0 like I did the first time around.  Is that correct?
title           New Drive Attempt
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.18-6-486 root=/dev/sda1 ro
initrd          /boot/initrd.img-2.6.18-6-486
savedefault

Open in new window

0
 

Author Comment

by:archaic0
ID: 24850171
OK, I rebooted after running those grub commands and puting the menu.lst in place that I described above.  My df command now shows the larger drive size, but still lists /dev/hda1.  Is that normal?  Or should it say /dev/sda1?

Also, there is a swap partition and it seemed like in the boot messages I saw a reference to /hda5 being mounted for that when it should now be /sda5.  Where do I find that setup?

Lastly, if I'm not totally off track here, what is a command I can run to search the entire hard drive for any reference to /hda to change it to /sda (if I need to do that).  I fear that there are things running like quotas that have hard coded references to the old drive.  I say that because in the boot messages I saw a couple references to /hda.

Thanks for sticking with me!


dviweb:/home/swadmin# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda1             915G  6.2G  862G   1% /
tmpfs                 443M     0  443M   0% /lib/init/rw
udev                   10M   80K   10M   1% /dev
tmpfs                 443M     0  443M   0% /dev/shm
 
 
dviweb:/home/swadmin# fdisk -l
 
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1      121271   974109276   83  Linux
/dev/sda2          121272      121601     2650725    5  Extended
/dev/sda5          121272      121601     2650693+  82  Linux swap / Solaris
 
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1        9399    75497436   83  Linux
/dev/hda2            9400        9729     2650725    5  Extended
/dev/hda5            9400        9729     2650693+  82  Linux swap / Solaris
dviweb:/home/swadmin#

Open in new window

0
 
LVL 43

Expert Comment

by:ravenpl
ID: 24851802
All right, one thing You need to do I forgot (having root on /dev/sda1) - rebuilding the initrd file
mkinitrd -f /boot/initrd.img-2.6.18-6-486 2.6.18-6-486
then reboot (the hda should vanish then)

the menu.lst looks fine (hd0,0; root=/dev/sda1)
0
 

Author Comment

by:archaic0
ID: 24859646
hmm, I don't seem to have mkinitrd

dviweb:/# mkinitrd -f /boot/initrd.img-2.6.18-6-486 2.6.18-6-486
bash: mkinitrd: command not found

Everything does seem to be working now, except my dovecot mail server seems to crash after a reboot.  This mkinitrd may be the key if I can find it to run it.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 24859746
On debian it's update-initramfs
You can try: update-initramfs -k 2.6.18-6-486 -c
but before that, read the manual

I doubt the new initrd will solve Your dovecot problem.
How it crashes - the crash message?
0
 

Author Comment

by:archaic0
ID: 24859914
I don't see any messages yet, I'm looking.  When the machine boots, the service shows it's running, but if I telnet to the ports it does not answer.  I just get the blank open connection situation with no banner saying welcome.  If I restart the dovecot service after the reboot, then it seems to stay up just fine.

Maybe there is just something for that service init config that is off?  

I don't see any reference to dovecot.conf that points to hda or anything... where can I look to find information about dovecot not starting correctly?  During boot I see the service start message ok, and it's listed as a running service, it's just not actually answering when I connect to the listening port until I restart the service.  I don't see anything in messages or syslog referencing dovecot, but I do see this:

dviweb kernel: ide: failed opcode was: unknown

The only IDE device I have in the system is a CDROM drive, and it's mounted as hdb and is unused at this point.
0
 

Author Comment

by:archaic0
ID: 24861763
unless you're up for moving forward with helping to troubleshoot the dovecot issue I think this part of the matter is closed (the new drive).  I'd like you to re-post a synopsis of what needed done in one message so I can accept it and not have to split the answer between posts.  You can modify anything you think needs adjust below and just use this if you like:

==================

To move and entire file system from one hard drive to another when the old drive was IDE and the new drive is SATA, this is what I had to do.

First, I added the new SATA drive to the system and used a boot CD cloning utility to make an exact copy from the old drive to the new one.  I used Acronis, but there are many options.

Then boot into the old drive and locate what partition grub occupies

df /boot/grub/

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda1               248895     17487    228838   8% /boot

run grub and type these commands in (the ## are just comments, don't type those)

grub
> device (hd0) /dev/sda      ##tells grub that first bios hdd is actually sda (not hda)
> root (hd0,0)                      ##it tells grub it's installed on hd0,firstPart
> setup (hd0)                      ##install grub in the mbr of hd0 - sda
> exit

Then mount the new drive into the current file system.  In my case I made a folder called newdrive and mounted my root partition there:

mkdir /newdrive
mount /dev/sda1 /newdrive

Then edit the /boot/menu.lst ON THE NEW DRIVE to reflect the new drive like so for my situation:

title           New Drive Attempt
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.18-6-486 root=/dev/sda1 ro
initrd          /boot/initrd.img-2.6.18-6-486
savedefault

The last thing I did was to grep the whole new drive for any reference to /dev/hda and edit that to be /dev/sda.  I only found a couple things (mainly in the /etc directory) and I don't know that they were entirely needed because they dealt with hibernating and I don't do that, but I did it anyway just to clean up any old drive references.  One in particular was causing my machine to hang on boot with a "could not stat the resume device file" message.  Turns out when I edited this file ( /etc/uswsusp.conf ) I then needed to run "update-initramfs -u" to clean something up.  While booted on the new drive of course.  More info here:  http://linux.derkeiler.com/Mailing-Lists/Debian/2008-04/msg00173.html

After all that, things seem to be working correctly.  I do have one glitch with my Dovecot server not starting correctly on boot, but needing to be restarted directly after boot that is yet unresolved.  But that may or may not be directly related to this hard drive move.

Thanks ravenpl for all your help!


0
 

Author Comment

by:archaic0
ID: 24882576
ravenpl, you still with me?
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 24882593
Yes, if You find any logs from dovecot, get them here.
Also, You can try starting it with strace or gdb, to find out why it's crashing.
0
 

Author Comment

by:archaic0
ID: 24882621
I think we should close this thread since it was about moving the hard drive and start a new thread for the dovecot crash issue.  If you'll re-post my synopsis in post 24861763, I'll accept that as an answer (if it looks good to you, if not edit it however you think)

I would just accept multiple answers to get it all, but when I'm looking through other answers it's confusing to have to pool together multiple answers like that so as a favor to searchers I'd like to combine the solution into one post.

I'll re-visit the dovecot crash after my weekend out of town.
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 500 total points
ID: 24882640
To move and entire file system from one hard drive to another when the old drive was IDE and the new drive is SATA, this is what I had to do.

First, I added the new SATA drive to the system and used a boot CD cloning utility to make an exact copy from the old drive to the new one.  I used Acronis, but there are many options.

Then boot into the old drive and locate what partition grub occupies

df /boot/grub/

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hda1               248895     17487    228838   8% /boot

run grub and type these commands in (the ## are just comments, don't type those)

grub
> device (hd0) /dev/sda      ##tells grub that first bios hdd is actually sda (not hda)
> root (hd0,0)                      ##it tells grub it's installed on hd0,firstPart
> setup (hd0)                      ##install grub in the mbr of hd0 - sda
> exit

Then mount the new drive into the current file system.  In my case I made a folder called newdrive and mounted my root partition there:

mkdir /newdrive
mount /dev/sda1 /newdrive

Then edit the /boot/menu.lst ON THE NEW DRIVE to reflect the new drive like so for my situation:

title           New Drive Attempt
root            (hd0,0)
kernel          /boot/vmlinuz-2.6.18-6-486 root=/dev/sda1 ro
initrd          /boot/initrd.img-2.6.18-6-486
savedefault

The last thing I did was to grep the whole new drive for any reference to /dev/hda and edit that to be /dev/sda.  I only found a couple things (mainly in the /etc directory) and I don't know that they were entirely needed because they dealt with hibernating and I don't do that, but I did it anyway just to clean up any old drive references.  One in particular was causing my machine to hang on boot with a "could not stat the resume device file" message.  Turns out when I edited this file ( /etc/uswsusp.conf ) I then needed to run "update-initramfs -u" to clean something up.  While booted on the new drive of course.  More info here:  http://linux.derkeiler.com/Mailing-Lists/Debian/2008-04/msg00173.html
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AWS Glacier is Amazons cheapest storage option and is their answer to a ‘Cold’ storage service.  Customers primarily use this service for archival purposes and storage of infrastructure backups.  Its unlimited storage potential and low storage cost …
When we purchase storage, we typically are advertised storage of 500GB, 1TB, 2TB and so on. However, when you actually install it into your computer, your 500GB HDD will actually show up as 465GB. Why? It has to do with the way people and computers…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question