Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] 5.3.9 + GRUB2 + root in LVM: unable to mount fs
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
nipa
n00b
n00b


Joined: 23 Dec 2017
Posts: 8

PostPosted: Mon Nov 11, 2019 9:14 am    Post subject: [SOLVED] 5.3.9 + GRUB2 + root in LVM: unable to mount fs Reply with quote

Hey, everyone.

I've been running a Gentoo install on my ThinkPad for about five years now, but recently got a new desktop PC and am struggling to install it there. The error message on first boot is:

Code:

VFS: Cannot open root device "mapper/system-root" or unknown block(0,0): error -6
Please append a correct "root=" boot option; here are the available partitions:

// list of partitions on NVMe SSDs
// curiously, each SDD root is followed by a line "(driver?)"


It would be great if you could help me figure out where things went wrong. Here are some details of my install (don't know which are relevant to the problem):
  • Kernel 5.3.9 (because of Ryzen 9) with experimental flag (to select "AMD Zen")
  • systemd (skipped timezone and locale config until I can boot with systemd)
  • profile 17.1/desktop/plasma/systemd
  • partitions
    • nvme1n1p2 (Ext 4) for /boot
    • nvme1n1p1 (FAT 32) for /boot/EFI
    • nvme1n1p3 (LVM) for root and others

  • configured LVM:
    • in Kernel (as per docs)
    • in GRUB 2 with device_mapper flag and GRUB_PRELOAD_MODULES=lvm in /etc/default/grub (checked that insmod lvm is present in grub.cfg)
    • no initramfs because I am under the impression that GRUB 2 and kernel can handle LVM on their own (am I wrong?)



Following up on "append a correct 'root=' boot option", I checked grub.cfg:

Code:
set root='lvmid/$VG-ID/$LV-ID'


The volume group ID and logical volume IDs are correct. I'm not sure how exactly etc/mtab is supposed to look, but it seems ok assuming dev/mapper is already available.


Last edited by nipa on Mon Nov 11, 2019 5:21 pm; edited 1 time in total
Back to top
View user's profile Send private message
nipa
n00b
n00b


Joined: 23 Dec 2017
Posts: 8

PostPosted: Mon Nov 11, 2019 9:39 am    Post subject: Reply with quote

Sorry for the multiple posts - the forum told me "error in posting" (or similar), so I tried again.
Back to top
View user's profile Send private message
nipa
n00b
n00b


Joined: 23 Dec 2017
Posts: 8

PostPosted: Mon Nov 11, 2019 10:01 am    Post subject: Reply with quote

Listing devices in GRUB console looks good:

Code:

(hd0) // this is an unformatted HDD
(hd1) (hd1,gpt5) (hd1,gpt4) (hd1,gpt3) (hd1,gpt2) (hd1,gpt1) // another SSD for Windows
(hd2) (hd2,gpt3) (hd2,gpt2) (hd2,gpt1) // Gentoo SSD
(lvm/system-home) (lvm/system-portage) (lvm/system-var) (lvm/system-swap) // yay, LVM!


One thing I noticed, though. In the Ubuntu LiveStick I use, nvm0 and nvm1 occasionally switch order, i.e. the numbers are not stable for the Windows vs Gentoo SSDs. Could this have something to do with my problem?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 44706
Location: 56N 3W

PostPosted: Mon Nov 11, 2019 10:02 am    Post subject: Reply with quote

nipa,

Quote:
no initramfs because I am under the impression that GRUB 2 and kernel can handle LVM on their own (am I wrong?)


Grub2 can load things from LVM but the kernel can't.

Grub2 does its thing, loads the kernel and initrd into RAM, then exits.
To be able to see root inside LVM, you must activate the Logical Volume. The kernel can't do that, you need a userspace tool. (vgchange)
That forces the use of an initrd, which the kernel will use as an interim root filesystem to start your LVM so it can mount your real root filesystem.

If you make the initrd yourself, with no kernel modules, you need not update it with every kernel update.
I have root in LVM on top of raid5. My initrd wan made in 2009. Its like firmware :)

-- edit --

The kernel device names are allocated as devices are discovered, they are usually fixed but you can't count on it.
Use filesystem UUID in /etc/fstab or PARTUUID where you want to refer to a whole partition
To use root=UUID=<fs_UUID> in grub.cfg, and you should, you need the userspace mount command in the initrd.
Logical Volumes don't have a PARTUUID as they are not on partitions.

Now you never use the kernel device names and you system is robust. Even if you add more devices in future and the kernel device names change.

Your initrd is growing arms and legs ...
With mount, you will want fsck.

-- edit some more --

The forums have a ready made View Unanswered Posts search.
Do not reply you your own topic until someone else has. To add more information, edit your original post.
If you reply to yourself, your topic drops out of the View Unanswered Posts search and may be missed.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
nipa
n00b
n00b


Joined: 23 Dec 2017
Posts: 8

PostPosted: Mon Nov 11, 2019 11:44 am    Post subject: Reply with quote

Hey Neddy, thanks for all the explanations and good tips. Looks like I'll be building an initramfs, then - there's a first for everything. :)

---- UPDATE ----

Oh boy, that was quite the journey, but in the end it worked out. For others having the same problem - here are my steps in building an initramfs. First I discovered the lvm2create_initrd use flag on sys-fs/lvm2, but couldn't get the script to work because (ignoring the lack of lvm.static; more on that in a sec) it kept dying during execution because of too little disk space - I doubt that was actually the case and found some theories of a lack of inodes and decided not to pursue it further.

Instead I went for the custom initramfs (note [url=https://wiki.gentoo.org/wiki/Custom_Initramfs#LVM]the section on LVM[/url)]:
  • following the recommendations I added busybox' static binary; I confirmed the image worked with a simple script that echoed "Hello, initramfs"
  • adding a binary for lvm was tough:
    • the static use flag on sys-fs/lvm, which is supposed to result in a self-contained binary lvm.static, is masked and unmasking it lead to weird (to me) conflicts that didn't seem very safe, so I didn't use it
    • using ldd /sbin/lvm, I got a list of LVM's dependencies and started copying them, but missed that most are symlinks, so they didn't work in the resulting image, which resulted in lvm not found errors that send me down the wrong track; the solution was to resolve symlinks on copy with cp --archive -H
  • finally, it wasn't initially obvious to me that my init script had to mount the root from LVM - I thought I just had to prepare the logical volumes and the kernel would then proceed with mounting what it needed; that's wrong

Thanks Neddy for helping me out, not just in this thread but in the many other that I encountered on this goose chase.

I'll post my script once the new machine has a browser and is online.

---- UPDATE ----

Here's my init script:

Code:
#!/bin/busybox sh

rescue_shell() {
    echo "Something went wrong. Dropping you to a shell."
    busybox --install -s
    exec /bin/sh
}

# mount the /proc and /sys filesystems
mount -t proc none /proc
mount -t sysfs none /sys

# mount root from LVM
echo "Mounting root from LVM..."
# detect volume groups, specifically "system"
lvm vgscan --mknodes
lvm lvchange -ay system/root
# scan again to add system/root to /dev/mapper
lvm vgscan --mknodes
mount -o ro /dev/mapper/system-root /mnt/root  || rescue_shell
#echo "...done"

# clean up
umount /proc
umount /sys

# boot the real thing
exec switch_root /mnt/root /sbin/init
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum