📜 ⬆️ ⬇️

LVM + lilo> GPT + EFI (or why GRUB is so awkward)

TL; DR : the author laments that GRUB cannot live fully with LVM and is surprised to discover that the lilo bootloader abandoned in 2015 can do it perfectly.

MBR?


Few people know and understand that the MBR is essentially the greatest mistake of mankind. Well, listen, well, seriously, who had the idea to mix in one block the data needed to load the system and information about partitions?

Once again, I repeat, I don’t need to say “it happened”, but turn on the logic. MBR is terrible.

Even worse, she is trying to fix design errors with crutches. To avoid the idiotic limitation of 4 partitions in one MBR record, you need to offer the concept of an “extended” partition (logically), deceiving and creating a bunch of half-empty MBRs over the entire disk (physically). Again, I will not dwell on this in detail, the experts will understand, the rest does not matter.
')
Another problem with the MBR is that the partitions cannot be simply enlarged (well, except for the last). Want to resize a partition? Well, it's simple - you need to remove it and recreate it by moving its end. Dear comrade amarao wrote down the excellent utility ptmax , which allows you to somehow relieve this pain, but listen, once again, because there is another way!

A separate point is the excellent behavior of the GRUB bootloader with the MBR. Well, since the bootloader does not have enough 446 bytes for a full life, it places its core.img into a “gap” between the end of the MBR and the beginning of the first partition (which is proposed to start with 1 megabyte, although it used to be closer).

GPT?


Eeee, no. GPT cures the problem that the hedgehog is already collected in the MBR in one bottle. GPT seems to tell us that now there are no hidden areas where GRUB will write something, here’s a separate section for it. Fine. But where to go from the fact that the sections still can not be increased?

Well, for example, I put the system. I allocated 32 GB for rootfs, and tomorrow I realized that I needed 64. And how to live? What to do? If I created a partition after swap for rootfs, then the expansion of the partition as rootfs looks like this:

1. Turn off swap
2. Demolish section under swap
3. Resize the partition as rootfs
4. Expand the rootfs file system
5. Create a section under swap
6. Enable swap

Everything would be fine, but if I have a data partition for my rootfs and I cannot move it? Well, then you need to suffer.

LVM


Oh yes, this is cool! After all, here the question of sections is taken out of brackets in general. I can create as many sections as I want and not think about how to increase them later. Cool? Yes.

But unfortunately, the logic that LVM replaces the MBR and GPT does not come to everyone. Until now, a whole series of approaches by system administrators are spinning around on the logic of “let's create a partition on the whole disk, and add a partition to LVM”.

Well, the cool money ends when you want to abandon the MBR or GPT completely, and stay only with LVM.

Attempt with Ubuntu installer


Note: hereinafter I will talk about Ubuntu, if a respected community tells you how things are going with this issue in other distros, I will be glad.

"What is the problem? I’ve even seen a line about LVM in the Ubuntu installer! ”Anyone who has installed at least once, say, Ubuntu, will be right.

Yes, well, let's see what the hell option we offer the installer.



Everything is beautiful here. From small things to important.

To begin with, appreciate the irony - under LVM a section is given, not a disk. Why? I will leave it on the conscience of those who invented it. The particular cynicism is that the section is extended, i.e. the disk will hang two blocks with the MBR. Okay.

Then we evaluate the usual / boot partition. Yes, you want LVM, but you will have an MBR too. Why is that? Well, earlier it could be justified by the fact that grub did not know how these are your LVMs, but he has been able for a long time.

Well, smoothly to the important. Doesn't anyone bother anyone that in fact LVM is stretching like an owl on a globe over an MBR? What is that supposed to mean? Why is this at all?

Bury the stewardess


Abandoning the MBR is simple - we can give the whole drive into submission to LVM? We can and we need. How to do it from the installer? Alas, no way. Hands That is, before the Partition disks step, you need to switch to the next tty and do the following with your hands (it is assumed that the disk where we want to install the system is / dev / sda):

pvcreate /dev/sda vgcreate ubuntu /dev/sda lvcreate -n root -L6G ubuntu lvcreate -n swap -l100%FREE ubuntu 

Then I give 6 gigabytes on rootfs, remaining on the swap, change as desired.

Well and further on at the stage of partitioning the disk we will see the partitions we have created, we can distribute what and where further.

Houston, we have problems


And everything will be fine, but exactly up to the bootloader installation phase. The installer will offer to install GRUB. We, of course, agree. And what is wrong?

Let me remind you that LVM usually retreats 1Mb from the beginning of the physical medium. How do I know? Well team

 pvs -o +pe_start 

will show it. What does this mean for us? The first megabyte of disk is free, no one bothers GRUB to write down its 446 bytes of the bootloader, plus core.img. That's just without the MBR, he can not do it!

Once again, I am amazed at the tenderness of GRUB: they give you a disk, come on, do it so that you can boot from there. You know how LVM, what's the problem?

Even attempts to manually call grub-install with the -s option only resulted in “unable to perform”.

Burning raws reveals the cruel truth: GRUB simply does not know how to install itself if there is no live MBR with at least one partition.

Lyrical digression: true fighters will say with contempt: “Why would you bother with this backward GRUB at all? Come to our EFI church! ”

In general, I agree, everything is much simpler with EFI, but there is a problem with a bunch of Legacy machines that EFI will not be able to do. That is, to force EFI to boot as BIOS is usually possible, the opposite, alas, is not always doable. And I want LVM and ice cream, ugh, loading not only with EFI.

EFI?


In general, EFI is conceived quite well. There are no areas hidden to you, create a partition, put the bootloader in the form of an .efi file, 7 configuration lines, and boot.

No, wait. Again create a section? Maybe someone will guess in the EFI specification to add support for LVM? You are welcome?

As an output, of course, you can take a small flash drive and format it into the desired EFI FAT as a whole, without partitions. There is already bread, but still the system will have to keep two disks, one for EFI, the other entirely under LVM, where the system is already.

lilo?


Here, I think, there will be a loud WAT. Yes, alas, the way it is, it is a real and serious WAT.

Have you ever thought why GRUB is so monstrous? Because usually it is well suited for difficult situations, when we want to load one system, we want options here, we want this, and we want that here. But just a minute, for system administrators, where everything has been virtualized a long time ago, this is usually nonsense. You just need to boot the system with minimal pain.

And what do we find out? That lilo knows how to install on an LVM disk; can / boot in LVM; does not require at least some MBR to be created on the disk and works remarkably well on the same Ubuntu 16.04, i.e. the package is and it is adequate.

The trouble is different. The development of lilo ceased at the end of 2015. Well, on the other hand, it can do everything necessary to load a modern system entirely on LVM.

Conclusion


Once again, please understand the main message of this article - discard the usual partition table. Be it an MBR, be it a GPT, you don't need it if you have LVM. Never give LVM partitions (except when you need some perverse dual-boot with Windows), this simply does not make sense.

And let's hope together that someday we will have support for LVM in EFI. For now we will suffer, fie, to use lilo.

Source: https://habr.com/ru/post/342482/


All Articles