You are not logged in.

#1 2016-06-29 21:24:10

duduedri96
Member
Registered: 2016-06-29
Posts: 4

grub-install with LVM on entire disk

Hi there,
yesterday I have decided to set my whole system to work with LVM.
I backed up everything (root filesystem, home filesystem, and other filesystems existing on my 2 HDDs) on an external drive and booted to the livecd.
I have removed all partitions on my disks.

According to the Arch Wiki LVM topic:

Create partitions
If LVM has to be set on the entire disk, there is no need to create any partitions.

So I decided to do so. I set my 2 HDDs as physical volumes and created a Volume Group:

# vgcreate StoragePool /dev/sda /dev/sdb

Next, I created a root lv, home lv and swap lv:

# lvcreate -L 40GB StoragePool -n lvroot
# lvcreate -L 10GB StoragePool -n lvswap
# lvcreate -l 100%FREE StoragePool -n lvhome

Afterwards, I have created filesystems inside the LVs (ext4 and swap), then copied back all my data from the backup external drive to the appropriate partition.

When chrooting into the newly created filesystems (and also when not chrooted), and trying to do grub-install on /dev/sda or /dev/sdb, I was getting this error:

# grub-install /dev/sda

grub-install: error: unable to identify a filesystem in hostdisk//dev/sda; safety check can't be performed.

Googled a bit and didn't find something useful. Eventually I deleted all the PVs and decided to start over, by setting my disks to DOS partition scheme,
and creating a bootable partition, which is /boot.
Then I created two large partitions, one on each disk, and set them to Linux LVM type (8e). Created logical volumes on them, and so on.
When I tried to grub-install it worked.

Arch Wiki LVM topic page didn't mention anything regarding this issue. Maybe we should add more info to this wiki page, or am I missing something?

Thanks!

Offline

#2 2016-07-12 09:12:19

Elizine
Member
From: United Kingdom
Registered: 2015-10-07
Posts: 39
Website

Re: grub-install with LVM on entire disk

Try the below steps -

change mkinitcpio.conf to...

HOOKS="base udev autodetect pata scsi sata usb lvm2 filesystems usbinput fsck"

Then rebuild initramfs and grub.cfg

mkinitcpio -p linux
grub-mkconfig -o /boot/grub/grub.cfg

Offline

#3 2016-07-12 20:37:40

duduedri96
Member
Registered: 2016-06-29
Posts: 4

Re: grub-install with LVM on entire disk

Elizine wrote:

Try the below steps -

change mkinitcpio.conf to...

HOOKS="base udev autodetect pata scsi sata usb lvm2 filesystems usbinput fsck"

Then rebuild initramfs and grub.cfg

mkinitcpio -p linux
grub-mkconfig -o /boot/grub/grub.cfg

Thanks for your comment,
well, how would that solve the problem?
I don't have any problem with creating grub.cfg - the problem occurs when i'm trying to grub-install,
which does not find any partition table on the specified disk and so it refuses to install.

Edit:
And just to make things clear, I did put the lvm2 hook in mkinitcpio.conf and built initramfs, then did grub-mkconfig.
After that, when trying to grub-install, I got the issue I specified above.

Last edited by duduedri96 (2016-07-12 20:42:27)

Offline

#4 2016-07-12 20:44:28

frostschutz
Member
Registered: 2013-11-15
Posts: 840

Re: grub-install with LVM on entire disk

Although you can put LVM on the whole disk, without partition table, that doesn't mean you can use it for booting. For that you need another disk, or an USB stick, or a server in your network...

I would never recommend using whole disk for anything. Always use a partition table. It's the most common way to declare that the disk is in use, and for what.

Well, technically it might not be impossible, but LVM only leaves you with 512 bytes free at the start of the disk. If you can find a bootloader that squeezes in there and a way to convince BIOS to consider this for booting you might get away with it. But it's a stupid thing to do.

Offline

#5 2016-07-12 21:18:27

duduedri96
Member
Registered: 2016-06-29
Posts: 4

Re: grub-install with LVM on entire disk

frostschutz wrote:

Although you can put LVM on the whole disk, without partition table, that doesn't mean you can use it for booting. For that you need another disk, or an USB stick, or a server in your network...

I would never recommend using whole disk for anything. Always use a partition table. It's the most common way to declare that the disk is in use, and for what.

Well, technically it might not be impossible, but LVM only leaves you with 512 bytes free at the start of the disk. If you can find a bootloader that squeezes in there and a way to convince BIOS to consider this for booting you might get away with it. But it's a stupid thing to do.

Thank you, now I get it.
I think it might worth a lot to mention this on the LVM wiki page.
What do you think?

Offline

#6 2017-04-06 15:57:14

pm3840
Member
Registered: 2013-12-16
Posts: 9

Re: grub-install with LVM on entire disk

Did

"Only GRUB is known to support LVM."

mean

"Only GRUB is known to support LVM on /."

From Wiki:

Warning: /boot cannot reside in LVM when using a boot loader, which does not support LVM, you must create a separate /boot partition and format it directly. Only GRUB is known to support LVM.

Offline

#7 2017-04-06 16:09:10

frostschutz
Member
Registered: 2013-11-15
Posts: 840

Re: grub-install with LVM on entire disk

@pm3840: grub supports lvm okay, but you still need a partition table, and enough space for grub core image (and dedicated partition in case of GPT table), to install grub to a disk in the first place.

"support LVM on /" doesn't make any sense, / doesn't matter to the bootloader, /boot does (or rather, the place where you store your kernel images). As long as your bootloader can grab the kernel image and initramfs, / can be anything (even remote on a network or what). That's a headache for the kernel/initramfs to solve, once the process got that far the bootloader no longer cares, it already did its job

You can do LVM on / with any bootloader

You can't do "kernel on LVM" with any bootloader, the bootloader has to support LVM or use some other means to know what to load.

You can't do "encrypted kernel" unless the bootloader knows how to decrypt it.

Last edited by frostschutz (2017-04-06 16:11:46)

Offline

#8 2017-04-06 18:04:00

pm3840
Member
Registered: 2013-12-16
Posts: 9

Re: grub-install with LVM on entire disk

You are right. "Only GRUB is known to support LVM on /." doesn't make sense.

My next question: where is "Only GRUB is known to support LVM." represented? Seems like GRUB just like other bootloaders needs /boot(or two files specifically initramfs-linux.img plus vmlinuz-linux) to be available on non LVM.

Edit 1:
Say /boot is standalone formatted as fat32, and most boot loader will be able to get the two files from /boot, and / is still part of some LVM. Does it mean system with such boot loaders will boot successfully?
Or does boot loader do some kind of work to locate / and somehow convey that info to kernel before kernel boots? Is that how "GRUB support LVM" stems from?

not important:
I am playing with virtualbox today, start with just one hd and set the whole hd to lvm and cannot get it to work.
Then I add a second small hd and dedicate it to /boot, leaving the previous hd mounted as / and arch boots successfully.

Last edited by pm3840 (2017-04-06 18:12:29)

Offline

#9 2017-04-06 18:26:32

Slithery
Forum Moderator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 3,493

Re: grub-install with LVM on entire disk

pm3840 wrote:

My next question: where is "Only GRUB is known to support LVM." represented? Seems like GRUB just like other bootloaders needs /boot(or two files specifically initramfs-linux.img plus vmlinuz-linux) to be available on non LVM.

GRUB works fine with /boot on an LVM volume.

The initial issue you had is that the GRUB bootloader itself needs to be installed somewhere. As you didn't partition your drive there was nowhere for GRUB to install itself - it usually lives on the free space that exists before the first partition. By not partitioning this space wasn't available.

Last edited by Slithery (2017-04-06 18:27:18)


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#10 2017-04-06 19:00:06

pm3840
Member
Registered: 2013-12-16
Posts: 9

Re: grub-install with LVM on entire disk

Could it be that boot.img is not able to locate core.img in LVM partition, but able to lcoate core.img in ext4/fat32 and alike partition? Where is core.img installed to?

Only wish I could read and understand the source code at this point. sad

https://www.gnu.org/software/grub/manua … tml#Images

Last edited by pm3840 (2017-04-06 19:09:48)

Offline

#11 2017-04-06 19:38:29

Slithery
Forum Moderator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 3,493

Re: grub-install with LVM on entire disk

This is what I was referring to in my previous post, boot.img and core.img are written onto the disk in the free space that usually exists before the 1st partition. By not partitioning this free space doesn't exist, hence your error.

Edit - Just to clarify, in GPT partitioned disks there is only room for boot.img in the free space before the 1st partition. This is why you also need a BIOS Boot Partition to use GRUB with GPT formatted drives.

Last edited by Slithery (2017-04-06 19:39:05)


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#12 2017-04-06 19:43:25

frostschutz
Member
Registered: 2013-11-15
Posts: 840

Re: grub-install with LVM on entire disk

pm3840 wrote:

Could it be that boot.img is not able to locate core.img in LVM partition, but able to lcoate core.img in ext4/fat32 and alike partition? Where is core.img installed to?

If msdos partition table, somewhere in the 1st MiB of the disk (sector 2-62).

Or if GPT partitions, with bios compatibility mode, wherever you put your bios_grub partition (if you don't have one and 1st partition starts at 1MiB, you can squeeze it into sector 64-2047).

Or if using UEFI, which requires a regular FAT partition, then there as a regular file (grub.efi or whatever).

It's not that you locate the core.img but the core.img is provided/built when you grub-install and it locates everything else. (what used to be stage1.5? in grub1)

Offline

#13 2017-04-06 21:10:16

pm3840
Member
Registered: 2013-12-16
Posts: 9

Re: grub-install with LVM on entire disk

Wiki[1] to the rescue again. Finally I understand this and the resemblance between how linux 0.x boot back in the old days of floppy drive. Thanks everyone.

Stage 1.5: core.img is by default written to the sectors between the MBR and the first partition, when these sectors are free and available. For legacy reasons, the first partition of a hard drive does not begin at sector 1 (counting begins with 0) but at sector 63, leaving 62 sectors of empty space not part of any partition or file system, and therefore not prone to any problems related with it. Once executed, core.img will load its configuration file and any other modules needed, particularly file system drivers; at installation time, it is generated from diskboot.img and configured to load the stage 2 by its file path.

[1] https://en.wikipedia.org/wiki/GNU_GRUB

Last edited by pm3840 (2017-04-06 22:24:03)

Offline

#14 2017-04-07 00:35:38

tom.ty89
Member
Registered: 2012-11-15
Posts: 896

Re: grub-install with LVM on entire disk

Neither BIOS/UEFI would be able to boot a "partitionless" disk on its own since they got nowhere to look for a bootloader, end of story. That's just common sense and has nothing to do with grub/LVM specificly.

P.S. Well, some UEFI might be able to boot a partitionless FAT-formatted drive...

Offline

#15 2018-06-23 04:58:41

xtricman
Member
Registered: 2015-09-19
Posts: 3

Re: grub-install with LVM on entire disk

frostschutz wrote:

Although you can put LVM on the whole disk, without partition table, that doesn't mean you can use it for booting. For that you need another disk, or an USB stick, or a server in your network...

I would never recommend using whole disk for anything. Always use a partition table. It's the most common way to declare that the disk is in use, and for what.

Well, technically it might not be impossible, but LVM only leaves you with 512 bytes free at the start of the disk. If you can find a bootloader that squeezes in there and a way to convince BIOS to consider this for booting you might get away with it. But it's a stupid thing to do.

At least grub will work just fine if you made the whole disks as btrfs, trust me, I've tested that, but you know, sometimes people really want a ext 4 and really hate MBR or GPT, so is there any possibilities to make things work? Like completely-hardware-based raid or could software raid be working?

Offline

#16 2018-06-26 01:30:41

circleface
Member
Registered: 2012-05-26
Posts: 639

Re: grub-install with LVM on entire disk

xtricman, please do not necrobump old threads.  The post you quoted is almost two years old, so I doubt the original poster is still looking for a solution.

Offline

#17 2018-06-26 09:17:32

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 7,963

Re: grub-install with LVM on entire disk

As mentioned, please don't necrobump old threads.

Closing.

Offline

Board footer

Powered by FluxBB