LinuxQuestions.org
Help answer threads with 0 replies.
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 05-25-2015, 07:17 AM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,537

Rep: Reputation: 112Reputation: 112
How do I "migrate" grub to a new hard disk?


I have a hard disk with a few partitions: /boot is mounted on sda1 and / is mounted on sda3. The sda2 partition is currently not used.

Now I have a new hard disk with a considerably different layout. Among other things, / will be mounted on sda2.

The new disk is installed as slave while I copy a lot of things over. After all the copying is finished, I predict the following conundrum:

If I don't install grub on the new disk, it won't boot.

If I install grub on it, grub will not only create a wrong entry (from assuming / on sda3), but probably also detect the two Linux installations and configure itself with both entries based on that.

In good old grub, that would be fantastically straightforward. In stupid new grub, that is fantastically convoluted.

Short of burning a rescue CD or pen drive that has the new grub, how can I accomplish that last step of the migration?
 
Old 05-25-2015, 07:59 AM   #2
Head_on_a_Stick
Senior Member
 
Registered: Dec 2014
Location: London, England
Distribution: Debian stable (and OpenBSD-current)
Posts: 1,187

Rep: Reputation: 285Reputation: 285Reputation: 285
Quote:
Originally Posted by lucmove View Post
If I install grub on it, grub will not only create a wrong entry (from assuming / on sda3), but probably also detect the two Linux installations and configure itself with both entries based on that.
I think you will be fine as long as the grub.cfg is updated as well.

From Debian:
Code:
# grub-install /dev/sda
# update-grub
This is presuming you are using a non-EFI system.

If you have problems, use the SuperGRUB2 rescue CD:
http://www.supergrubdisk.org/

EDIT: Sorry, I hadn't thought that through properly -- syg00 is right.

Last edited by Head_on_a_Stick; 05-25-2015 at 08:17 AM.
 
Old 05-25-2015, 08:01 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,286

Rep: Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165Reputation: 4165
Simply chroot into the new disk when all the copying is done, then "grub-install /dev/sdb". Reboot, select the new disk in BIOS.

Edit: maybe we're both half right - I forgot the update-grub .... :shrug:

Last edited by syg00; 05-25-2015 at 08:41 AM.
 
2 members found this post helpful.
Old 06-04-2015, 08:41 AM   #4
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,537

Original Poster
Rep: Reputation: 112Reputation: 112
I am finally ready for the move and... it didn't work.

root@luc:/# grub-install /dev/sdb
sh: 1: /etc/default/grub: cannot create /dev/null: Permission denied
Installing for i386-pc platform.
/proc/devices: No entry for device-mapper found
device node not found
device node not found
/proc/devices: No entry for device-mapper found
device node not found
grub-install: error: cannot find a GRUB drive for /dev/sdb2. Check your device.map.

I ignored it, swapped the disks and rebooted, and got a "System missing" error message.

Any other idea, please?

Note:
sdb1 = /boot
sdb2 = /

Although there is a full copy of /boot inside /

Last edited by lucmove; 06-04-2015 at 08:42 AM.
 
Old 06-04-2015, 08:47 AM   #5
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Before you chroot into the new installation to install Grub, bind-mount /dev, /sys and /proc into it. Grub will have a hard time to install to /dev/sdb when there is no /dev/sdb in the chroot.
 
1 members found this post helpful.
Old 06-04-2015, 08:56 AM   #6
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,537

Original Poster
Rep: Reputation: 112Reputation: 112
How do I bind-mount?
 
Old 06-04-2015, 10:06 AM   #7
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: One main distro, & some smaller ones casually.
Posts: 5,709

Rep: Reputation: Disabled
https://docs.1h.com/Bind_mounts
 
Old 06-04-2015, 10:06 AM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
In your case:
Code:
mount /dev/sda2 /mnt
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc
Then chroot into the new system, do your Grub stuff, exit the chroot and do it in reverse to unmount all that:
Code:
umount /mnt/{dev,proc,sys}
umount /mnt
 
1 members found this post helpful.
  


Reply

Tags
grub


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
Can't boot? "Caution: This hard disk may be infected by virus!" IamNoob Linux - General 2 08-29-2009 01:51 AM
Stuck on "GRUB_" Screen - Will boot from Live CD "Boot from first hard disk" option Snowman11 Linux - Newbie 10 02-01-2009 07:52 PM
Hard disk/partition woes. "In interrupt handler - not syncing" Nathan-H2-Dog Linux - Laptop and Netbook 3 01-27-2006 05:54 PM
Suse 9.2 "GRUB Hard Disk Error" Help! fxafelix Linux - Newbie 3 02-22-2005 06:37 AM
GRUB bootloader spits out "GRUB hard disk error" Crampedson Linux - Software 2 01-26-2005 07:34 PM

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

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