Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED -- giving up] BIOS / UEFI / partitioning / grub2
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
dpaddy
Tux's lil' helper
Tux's lil' helper


Joined: 25 Jun 2008
Posts: 117

PostPosted: Fri Apr 07, 2017 9:09 am    Post subject: [SOLVED -- giving up] BIOS / UEFI / partitioning / grub2 Reply with quote

Please confirm / correct / school:

1:: There are (at least) two ways by which a gentoo linux system can be booted, one is (sometimes) referred to as BIOS and the other is (sometimes) referred to as UEFI. Moreover a new gentoo install can be made such that both methods are available options (assuming hardware/firmware/whatever supports it).

2:: Following the guide https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Disks to arrive at

Code:
Partition Table: gpt
Disk Flags:

Number      Start      End       Size     File system       Name    Flags
 1          1049kB     3146kB    2097kB                     grub    bios_grub
 2          3146kB     1077MB    1074MB   ext2              boot    boot, esp
 3          1077MB     35.4GB    34.4GB   linux-swap(v1)    swap
 4          35.4GB     1000GB    965GB    ext4              rootfs

and then (following that same guide)

Code:
root #mkfs.ext2 /dev/sda2
root #mkfs.ext4 /dev/sda4
root #mkswap /dev/sda3

is wrong because the partitioning (sizes, or types, or something) is inappropriate for the purpose of having the option to boot via both BIOS or UEFI.
In particular (following that same guide),

Code:
(chroot) livecd init.d # grub-install /dev/sda
grub-install: error: /usr/lib/grub/i386-pc/modinfo.sh doesn't exist. Please specify --target or --directory.
(chroot) livecd init.d # grub-install --target=x86_64-efi --efi-directory=/boot
Installing for x86_64-efi platform.
grub-install: error: /boot doesn't look like an EFI partition.

3:: I found https://wiki.gentoo.org/wiki/GRUB2_Quick_Start but I cannot follow it because I do not understand what the words like "When using an EFI platform, make sure that the EFI System Partition is available (mounted) at /boot/efi", etc mean in concrete terms such as exactly what I should type at the "(chroot) livecd init.d #" prompt. Moreover that guide and https://wiki.gentoo.org/wiki/EFI_stub_kernel suggest (to my feeble mind) that /dev/sda2 should be mounted at /boot and then /dev/sda1 should be mounted at /boot/efi and moreover /dev/sda1 is "the EFI System Partition" which at this point is altogether too small and perhaps has inapprioriate attributes for any of this to work :cry:


Last edited by dpaddy on Fri Apr 07, 2017 12:31 pm; edited 1 time in total
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


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

PostPosted: Fri Apr 07, 2017 10:38 am    Post subject: Reply with quote

dpaddy,

Lets call the program embedded in your motherboard that gets the hardware set up and reads the very first thing off the hard drive, firmware.
This is the program you update when you 'flash the BIOS'.

Modern firmware can operate in legacy mode, called BIOS or in UFEI mode. Hold that thought, we will come back to it.

You may choose to have either a MSDOS disk label or GPT disk label (partition table) on your hard drive. You can only have one per HDD.
The layout of the data on the disk is different for both disk labels.

With MSDOS, the partition table and boot loader stage1 goes into Logical Block address (LBA) 0, then, for historical reasons, there is a gap.
Tradidionally, the first partition stared at LBA 63. That's a bad thing for modern hard drives as its not an exact multiple of 8, so the default has been changed to LBA 2048.
With GPT, LBA 0 is left empty and the partition table uses LBA 1..2047, so there this no empty space before the first partition.
Notice how the MSDOS default and GPT now start the first partition in the same place (LBA 2048). That's not a coincidence. We'll come back to that.

The grub boot loader comes in three pieces. Stage1, stage1.5 and stage2. You will see them in /boot/grub but only stage2 is used from there.
Stage1 is installed to LBA 0, where the firmware in BIOS mode can find it.
Stage1.5 is installed into the empty space before the first partition if you used a MSDOS disk label. That space does not exist with a GPT disk label so this goes into the 2Mb grub partition.
Grub uses it raw. You never mount it and you never make a filesystem on it.
Notice that the free space with an MSDOS disk label and the 2Mb grub partition with a GPT disk label are about the same size.
Stage2 is read from /boot/grub.

Putting the bits together. The old way The firmware is in BIOS mode and you have a MSDOS disk label.
The firmware loads grub stage1 from LBA 0. Grub stage1 loads grub stage 1.5 from the space before the first partition and grub stage1.5 reads the filesystem to load grub stage2, which shows you your boot menu.

The new way. The firmware is in UEFI mode. You must have a GPT disk label as that's all UEFI understands.
I'm not sure if/how grub stage1 is loaded. Stage1.5 is loaded from the 2MB partition, which loads stage2 ...

As both disk labels avoid one anothers data structures there is a third hybrid mode possibility.
Using the firmware in BIOS mode with a GPT partition table.
In BIOS mode with a GPT partition table, there is nowhere to put grub stage1.5. Grub isn't happy about that but grub stage1 can be made to load grub stage2 directly.
This is fragile and not to be encouraged.

BIOS mode does not understand GPT partition tables. Something I glossed over is that some firmware in BIOS mode expects to find a bootable flag set on the partition table read from LBA0.
When you create a GPT partition table, you also get a free 'protective' MSDOS partition table that includes a single partition of type 0xee. This is a flag that GPT is in use.
Its here that the bootable flag must be set, not on the real GPT partition table.
Worse, a few BIOSes check the partition type, if its 0xee, they refuse to boot.

You make up your mind at install time if you will use BIOS mode or UEFI mode. You can't switch later.
A MSDOS disk label can describe at most 2TiB of space. If your HDD is bigger than that, you must use GPT.
The only reason to try the hybrid mode is because your system in BIOS only and you want to fit hard drives bigger than the 2TiB limit.
_________________
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
dpaddy
Tux's lil' helper
Tux's lil' helper


Joined: 25 Jun 2008
Posts: 117

PostPosted: Fri Apr 07, 2017 11:25 am    Post subject: Reply with quote

1) Ok... so If I go with UEFI mode, then is my partitioning of /dev/sda correct?

2) What command(s) -- in my situation -- to install grub? I have /dev/sda2 mounted on /boot, /dev/sda1 is not mounted, but
Code:
(chroot) livecd / # grub-install --target=x86_64-efi --efi-directory=/boot
Installing for x86_64-efi platform.
grub-install: error: /boot doesn't look like an EFI partition.

What should "efi-directory" be (and why), how to proceed?
Back to top
View user's profile Send private message
dpaddy
Tux's lil' helper
Tux's lil' helper


Joined: 25 Jun 2008
Posts: 117

PostPosted: Fri Apr 07, 2017 12:16 pm    Post subject: amd handbook broken? Reply with quote

At this point my (perhaps mistaken) impression is that the amd handbook is broken, because the advocated partitions types / sizes cannot work for UEFI boot...

To boot using UEFI, do I need to: start over with the install, ignore what the handbook has to say about partitions, try to follow https://wiki.gentoo.org/wiki/GRUB2_Quick_Start and https://wiki.gentoo.org/wiki/EFI_stub_kernel, cross my fingers and hope that somehow UEFI works?

Has anyone succeeded in a gentoo install using UEFI boot? Specific concrete advice -- on the level of what exactly to do with disk(s) and partitions -- would be appreciated.
Back to top
View user's profile Send private message
dpaddy
Tux's lil' helper
Tux's lil' helper


Joined: 25 Jun 2008
Posts: 117

PostPosted: Fri Apr 07, 2017 12:29 pm    Post subject: Life is too short... Reply with quote

On second thought, I'll punt on UEFI and try to make BIOS boot work.

I've managed that in the past (with fdisk to partition the disks), and there are too many other things I need to get done...

Thanks for the overview, the comments are enlightening and much appreciated.
Back to top
View user's profile Send private message
Fitzcarraldo
Veteran
Veteran


Joined: 30 Aug 2008
Posts: 1655
Location: United Kingdom

PostPosted: Fri Apr 07, 2017 12:37 pm    Post subject: Reply with quote

dpaddy, I too found the Gentoo Handbook confusing regarding UEFI. In case you have another go in future, you might find the following of some help: Partitioning hard disk drives for BIOS-MBR, BIOS-GPT and UEFI-GPT in Linux.
_________________
Clevo W230SS: amd64 OpenRC elogind nvidia-drivers & xf86-video-intel.
Compal NBLB2: ~amd64 OpenRC elogind xf86-video-ati. Dual boot Win 7 Pro 64-bit.
KDE on both.

Fitzcarraldo's blog
Back to top
View user's profile Send private message
Roman_Gruber
Advocate
Advocate


Joined: 03 Oct 2006
Posts: 3806
Location: Austro Bavaria

PostPosted: Sat Apr 08, 2017 11:53 am    Post subject: Reply with quote

Fitzcarraldo wrote:
dpaddy, I too found the Gentoo Handbook confusing regarding UEFI. In case you have another go in future, you might find the following of some help: Partitioning hard disk drives for BIOS-MBR, BIOS-GPT and UEFI-GPT in Linux.


I disagree.

I did use the gentoo handbook in october 2015 with my first UEFI box ever and I got it working in a minimum amount of time.

Well i use sysrescue-cd and use the gentoo handbook just for basic guidiance. I assume it's more a lack of computer knowledge or generic knowledge about *nix / shell in the first place. A lack of efforts reading the manual. I did that several times when i swapped my setup. (reading hole redhat lvm2 docs, luks, ...)

The only issue I had was with aligning the partion, but thats only a performance issue, and an emulation issue of those fake SSD drives. SSds behave much differnt as those platter drives.

Personal note: using a quick guide aa newbie is nuts. You need to understand how it works, what it does. I do read the manuals quite often for commands to see what is done, how it works. when i do not grasp it, i go on and read other docs, until i see how it works. what it does

quick guides are only for advanced users. who just only want to see the command queue, and can read out of htose command queues what is done, what the author wants to say.

also bear in mind, some guys are not that well suited to write guides, lack some knowledge, have some faults, ...
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Sun Apr 09, 2017 2:11 pm    Post subject: Reply with quote

dpaddy, the ESP MUST be a FAT32 partition, usually at the start of the disk.
Yours is both ESP and /boot, formatted ext2; using the same partition is only possible if /boot is formatted as fat32, though not usual.
I imagine some of your confusion arises from the paths under /boot/efi, which in your case is /boot. Consider the equivalent /boot/efi/EFI (requiring a mount of ESP after /boot) and /boot/EFI in your setup, as everything UEFI related is under the /EFI subdirectory of the ESP.

So for a fresh install, we'd use eg:
Code:
mkfs.fat -F 32 /dev/sda1
cf: man mkfs.fat
If you don't want to redo partitioning, you'd use:
Code:
mkfs.fat -F 32 /dev/sda2
Though you should note this (will ofc wipe /boot,) means /boot is now fat32, and to use /boot where you see /boot/efi (symlink: ln -s . /boot/efi won't work on fat?)

grub-install on an EFI platform installs grubx64.efi in the ESP (and a lot more in the main /boot directory.)

You only need a BIOS boot partition if you're using grub and CSM mode, which would need to be explicitly set in the BIOS.

For a new system, I'd advise simply using UEFI mode; you do not need a BIOS boot partition at all, in that case.

I used gdisk to setup the GPT partitions. It's very nice; you can use +50G to get a 50G partition, for instance.
It also takes care to use decent alignment, which filters through to cgdisk, the nicer interface. (This was an issue with cfdisk, ime.)

I recommend this page on both the ESP and alignment, and this one on Linux UEFI (note the advice on disabling Windows-biased BIOS settings.)

For installation, I highly recommend sysrescue cd, and refind as boot manager.
Sysrescue boots as UEFI; if your BIOS supports selection from a menu (which may need to be enabled in settings) then you can just boot it directly.
The keypress used by your BIOS varies, but should be shown on startup.

You can check if you have started sysresccd in EFI mode with ls /sys/firmware/efi/efivars -- if it returns an error ("No such file or directory") then you're not in EFI mode. If it shows a load of variable names, then you are.

Using the EFI stub builtin to kernel means refind can boot it directly, so no need for grub.
Its main advantage though, is in /boot/refind_linux.conf (settings like root= for all kernel versions in the directory, per-config like normal, single and rescue) and how refind scans for kernels. It uses the latest-modified in the directory, by default, which makes upgrades smooth, and rollback easy (simply touch vmlinuz-X.Y.z-gentoo you want to go back to.)
In doing so, it picks up on a matching initrd, and if it exists, adds the parameter to the kernel command-line for you, thus taking away the other major pain for upgrades.
The combination means you don't need to edit files, nor run something like grub-mkconfig, just to change kernel versions. (Nor build in a kernel command-line, as EFI stub kernels need when booted from BIOS.)

Note you should build in the EFI framebuffer, and make sure EFI mixed mode is set on.
Here's my (minimal) EFI-related kernel config for 4.9.16:
Code:
$ grep -F EFI linux/.config
CONFIG_EFI_PARTITION=y
CONFIG_EFI=y
CONFIG_EFI_STUB=y
CONFIG_EFI_MIXED=y
CONFIG_FB_EFI=y
CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK=y
# EFI (Extensible Firmware Interface) Support
CONFIG_EFI_VARS=m
CONFIG_EFI_ESRT=y
# CONFIG_EFI_VARS_PSTORE is not set
# CONFIG_EFI_RUNTIME_MAP is not set
# CONFIG_EFI_FAKE_MEMMAP is not set
CONFIG_EFI_RUNTIME_WRAPPERS=y
# CONFIG_EFI_BOOTLOADER_CONTROL is not set
# CONFIG_EFI_CAPSULE_LOADER is not set
# CONFIG_EFI_TEST is not set
CONFIG_UEFI_CPER=y
CONFIG_EFIVAR_FS=m
# CONFIG_EFI_PGT_DUMP is not set
Start without kernel DRI support for X (CONFIG_DRM is not set); just get the system booting into the EFI console and starting up properly (rootfs, net, localmount.)
You do not need MSDOS_PARTITION if you are only using GPT disks, as on a new UEFI install.

Also, be sure to label your partitions in (c)gdisk, eg ESP, boot, swap, root, home, var, etc.
For one thing, this means you can exclude them from refind's scan, in /boot/efi/EFI/refind/refind.conf.

As you know, the ESP is usually mounted at /boot/efi (after /boot ofc; I have both set to: noauto,sync in /etc/fstab.)
So refind.conf is in the /EFI/refind directory on the ESP; in a merged /boot + ESP this would be /boot/EFI/refind instead of /boot/efi/EFI/refind

If you set a resolution in refind.conf that is unsupported, it will give you a list of supported ones before going back to the default, usually 800x600 (640x480 here.)
Use that to see the highest res, note it down, and then use it in the conf; combined with use_graphics_for linux (the equivalent of grub keep) you get a very high-res console using the EFI framebuffer (1920x1080 here.)
That makes it much easier to do the rest of the install.

Once you're started up in console, it means you're past the UEFI setup, as well as the base kernel config, so can move on to setting up your video card. (kernel CONFIG_DRM, VIDEO_CARDS, then xorg-server.)

Personally, I would redo the partitions, as it looks like a fresh install (unless you have done much configuration or installtion in the chroot), and get rid of the BIOS boot one if you can start sysresccd in EFI mode.

Splitting ESP (the refind author recommends about 550M so I used +566M at 2M start) and /boot (I used +456M) works quite well. There's usually no need to mount /boot/efi for a kernel upgrade, nor to modify kernel-related settings, and you can still use ext2 in /boot.

HTH,
steveL

I missed a trick by forgetting a separate sysresc partition (I wanted a 1G one) but there turned out to be enough space in ESP for /sysresc with sysrcd.dat (and rescue64, initram.igz) which is setup in refind.conf as two entries, both with: linux /sysresc/rescue64 and initrd /sysresc/initram.igz: a backup kernel (setkmap=uk root=/dev/sda3 ro), and to run the standard sysrescue (setkmap=uk docache subdir=/sysresc) much more quickly than from CD.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo 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