LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 06-10-2017, 02:01 PM   #1
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 756

Rep: Reputation: 144Reputation: 144
grub2-install doesn't seem to work, trying to clone


I run Fedora 25 installed on a "Samsung SSD 840" 111.8G disk with GPT as /dev/sdb. I want to replace it with something else, so I'm trying to move my existing system to the "ST3500321CS" 465.8G rotating disk which I still have installed as /dev/sda. The idea is to maintain a functioning system while experimenting with installation on the SSD.

I replicated the GPT partitions on /dev/sda:
Code:
$ lsblk -o NAME,FSTYPE,SIZE,LABEL /dev/sda
NAME   FSTYPE   SIZE LABEL
sda           465.8G 
├─sda4 swap      16G a-SWAP
├─sda2 ext4     500M a-BOOT
├─sda5 ext4    44.3G a-ROOT
├─sda3 ext4      51G a-HOME
├─sda1         1007K 
└─sda6 ext4     354G
To copy the data, I booted a rescue USB drive and used "e2image -rap /dev/sdb2 /dev/sda2" and the same for partitions 3 and 5. Unfortunately, the UUIDs and labels were also copied, which caused confusion when I later tried to boot. But I fixed those with tune2fs and e2label.

The only file I think I need to changes is /etc/fstab. I have a version of it with UUIDs that match /dev/sda and I move that file to /etc/fstab after e2image.

To copy the grubby parts, I tried several variations of this either from the rescue or Fedora:
Code:
mount /dev/sda5 /mnt
mount /dev/sda2 /mnt/boot
grub2-install --boot-directory=/mnt/boot --recheck /dev/sda
grub2-mkconfig -o /mnt/boot/grub2/grub.cfg
I also went into BIOS and moved ST3500321CS to the top of the boot order. But when I boot, I always end up on the SSD (/dev/sdb) not /dev/sda as desired. When I physically disconnected the SSD, it wouldn't boot.

Is there something else I have to do to make /dev/sda bootable?
 
Old 06-10-2017, 03:47 PM   #2
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,854

Rep: Reputation: 340Reputation: 340Reputation: 340Reputation: 340
Quote:
Unfortunately, the UUIDs and labels were also copied, which caused confusion when I later tried to boot. But I fixed those with tune2fs and e2label.
Since grub keeps booting up your old installation on the SSD, sdb, there must be something in your grub configuration files pointing grub to your old sdb root partition as the one to boot. Check your grub.cfg and see if the old sdb root partition uuid is coded in there.
 
Old 06-10-2017, 06:18 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 19,783

Rep: Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574
What is sda1 ?. Is it supposed to be the EFI ?.
 
Old 06-10-2017, 08:09 PM   #4
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 756

Original Poster
Rep: Reputation: 144Reputation: 144
Quote:
Originally Posted by syg00 View Post
What is sda1 ?. Is it supposed to be the EFI ?.
My machine predates EFI, but I'm using GPT anyway. GRUB needs room to store it's files, so the first MB (sectors 34 to 2047) is reserved for it. It's type "BIOS boot partion" as reported by gdisk, code EF02.

Replicating it turned out to be non-trivial, but fortunately search engines can find anything these days.
 
Old 06-10-2017, 08:38 PM   #5
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 756

Original Poster
Rep: Reputation: 144Reputation: 144
Quote:
Originally Posted by kilgoretrout View Post
Since grub keeps booting up your old installation on the SSD, sdb, there must be something in your grub configuration files pointing grub to your old sdb root partition as the one to boot. Check your grub.cfg and see if the old sdb root partition uuid is coded in there.
The grub config stuff is a big mystery to me. But no, there is no "sdb" in /boot/grub2/grub.cfg on either sda or sdb.

One possible solution I meant to track down is the format of the lines in grub.d files. "/etc/grub.d/40_custom" says:
Quote:
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
Maybe if I added a line for sda, it would boot. Though I still don't know why it should be necessary.
 
Old 06-10-2017, 08:43 PM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 19,783

Rep: Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574
Whenever I have grub issues, I remove the "other" drive, chroot into the "new" drive and install everything from there. Make sure it boots then re-attach the other drive. Isolate possible error situations.
I might be inclined to try removing the BIOS boot partition from the SSD - not sure how having more than one is managed. Just change the type, rather than delete it.
 
Old 06-10-2017, 09:56 PM   #7
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 756

Original Poster
Rep: Reputation: 144Reputation: 144
Quote:
Originally Posted by syg00 View Post
Whenever I have grub issues, I remove the "other" drive, chroot into the "new" drive and install everything from there.
I tried chroot, but grub2-install knew I was trying to fool it and refused to play. There's another command, switch_root, but I haven't tried it yet.
 
Old 06-11-2017, 12:19 AM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 19,783

Rep: Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574Reputation: 3574
chroot is what you need - you must have not set it up properly. We can't help if you don't tell us what you did, and what happened.
 
Old 06-11-2017, 10:48 AM   #9
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,854

Rep: Reputation: 340Reputation: 340Reputation: 340Reputation: 340
Quote:
there is no "sdb" in /boot/grub2/grub.cfg on either sda or sdb
IIRC fedora arranges the grub configuration files a little differently; not running fedora at the moment. However, in *buntu the main configuration files is grub.cfg and in it there is a line for "root=<uuid of root partition>". That's what I was referring to. There has to be something somewhere in your grub configuration files pointing grub to sda* as the root partition. Again, not that familiar with how fedora lays out the boot files.
One thing you could try is changing the uuid on sdb root partition to the same one that is currently on the sda root partition and then either disconnect sda or change the sda root partition to something else. If you try this you would also have to change the sdb fstab for the new uuid of the sdb root partition.
 
Old 06-11-2017, 02:43 PM   #10
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,513

Rep: Reputation: 1010Reputation: 1010Reputation: 1010Reputation: 1010Reputation: 1010Reputation: 1010Reputation: 1010Reputation: 1010
In the grub.cfg, on the "kernel" line, switch the root=UUID to root=device, i.e. /dev/sda2.
 
Old 06-13-2017, 03:12 AM   #11
KenJackson
Member
 
Registered: Jul 2006
Location: Maryland, USA
Distribution: Fedora and others
Posts: 756

Original Poster
Rep: Reputation: 144Reputation: 144
Quote:
Originally Posted by syg00 View Post
chroot is what you need - you must have not set it up properly. We can't help if you don't tell us what you did, and what happened.
Code:
$ sudo mount /dev/sda5 /mnt/sda5
$ sudo mount /dev/sda2 /mnt/sda5/boot
$ sudo mount /dev/sda3 /mnt/sda5/home
$ sudo chroot /mnt/sda5
# grub2-install /dev/sda5
Installing for i386-pc platform.
grub2-install: error: cannot find a device for /boot/grub2 (is /dev mounted?).
I'm still don't know how to use grub2-install, but I did make progress. I went through my /boot/grub2/grub.cfg files line-by-line, ignored the "DO NOT EDIT THIS FILE" warning and replaced UUIDs so they all refer to the correct disk. I also made sure the file on /dev/sda had only "root='hd0,gpt2'" and /dev/sdb had only "root='hd1,gpt2'".

After doing that, it still booted to /dev/sdb even though BIOS is configured to boot the other drive first. But then I found the /boot/grub2/device.map file, which was this:
Code:
# this device map was generated by anaconda
(hd0)      /dev/sdb
(hd1)      /dev/sdc
(hd2)      /dev/sdb
Odd. I have now replace this file with this, on both drives. (I haven't rebooted yet, but if it fails to boot, I can easily boot the rescue and swap this file back.)
Code:
# this device map was generated by Ken Jackson
(hd0)      /dev/sda
(hd1)      /dev/sdb
 
Old 06-13-2017, 04:06 AM   #12
jago25_98
Member
 
Registered: Jun 2001
Posts: 302

Rep: Reputation: 30
this is why I like to use grub-customizer - because it's so easy to get confused.

...not a fan of grub/grub2: you should be able to change the default boot option from within grub itself (implemented by passing a boot option to the OS and the OS updates the default entry)

related?:
Code:
$ sudo grub-probe -t device /boot/grub
/dev/mmcblk0p6
...how can my MBR boot device be on the 6th partition...?
 
  


Reply

Tags
boot, clone, grub, grub2, install


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
Acer Aspire 4752 - GRUB2 doesn't install/work?!?! themacmeister Linux - Laptop and Netbook 8 10-28-2015 06:19 PM
[SOLVED] Apt-get install -f doesn't work? Super TWiT Linux - Software 2 04-01-2011 02:03 PM
grub2 detects Mac OSX on sdb, but doesn't install it to grub.cfg? JohnLocke Linux - Newbie 16 02-17-2010 05:10 PM
I need to Clone a Red Hat drive and install clone in HP server drummer54 Linux - Newbie 14 03-07-2009 04:15 PM
why doesn't this work? ./install.sh mpooley Linux - Software 15 04-08-2007 01:36 AM

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

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