LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How do I "migrate" grub to a new hard disk? (https://www.linuxquestions.org/questions/linux-software-2/how-do-i-migrate-grub-to-a-new-hard-disk-4175543528/)

lucmove 05-25-2015 06:17 AM

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?

Head_on_a_Stick 05-25-2015 06:59 AM

Quote:

Originally Posted by lucmove (Post 5367091)
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.

syg00 05-25-2015 07:01 AM

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:

lucmove 06-04-2015 07:41 AM

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 /

TobiSGD 06-04-2015 07:47 AM

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.

lucmove 06-04-2015 07:56 AM

How do I bind-mount?

fatmac 06-04-2015 09:06 AM

https://docs.1h.com/Bind_mounts

TobiSGD 06-04-2015 09:06 AM

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



All times are GMT -5. The time now is 07:50 AM.