§2023-10-22

  1. prepare disk@h2Hammy.yushei.net, odroid-h2
Device        Start       End   Sectors Size Type
/dev/sdb1      2048   4196351   4194304   2G Linux filesystem    <-- this has to be ef00, EFI system partition
/dev/sdb2   4196352  20973567  16777216   8G Linux swap
/dev/sdb3  20973568 222300159 201326592  96G Linux filesystem 
  1. Prepare to be arch-chroot into it

wget https://distfiles.gentoo.org/releases/arm64/autobuilds/20231015T223200Z/stage3-arm64-systemd-20231015T223200Z.tar.xz, enevn I made a mistake using arm64 version, I still could arch-chroot into it

$ wget https://distfiles.gentoo.org/releases/amd64/autobuilds/20231015T161657Z/stage3-amd64-systemd-20231015T161657Z.tar.xz
$ sudo mount /dev/sdb3 /mnt/gentoo/
$ sudo tar xvfp stage3-amd64-systemd-20231015T161657Z.tar.xz -C /mnt/gentoo/
  1. arch-chroot
$ sudo arch-chroot /mnt/gentoo/ /bin/bash
h2Jammy / # source /etc/profile
  1. locale-gen
h2Jammy / # nano /etc/locale.gen 
h2Jammy / # locale-gen
 * Generating 3 locales (this might take a while) with 4 jobs
 *  (3/3) Generating C.UTF-8 ...                        [ ok ]
 *  (2/3) Generating ja_JP.UTF-8 ...                    [ ok ]
 *  (1/3) Generating en_US.UTF-8 ...                    [ ok ]
 * Generation complete
 * Adding locales to archive ...
# export LANG, LC_ALL 
export LANG=en_US.UTF-8
# LANG is the primary environmental variable that sets the default locale for your system.
export LC_ALL=C.UTF-8
# LC_ALL is another environmental variable that can override the settings of LANG and other LC_* variables for all locale categories.
# 

# PS1
export PS1="(chroot) $PS1"
h2Jammy / # nano /etc/profile
h2Jammy / # source /etc/profile
(chroot) h2Jammy / # 
  1. /etc/resolv.conf
(chroot) hc4Gentoo / # nano /etc/resolv.conf
(chroot) hc4Gentoo / # cat /etc/resolv.conf 
nameserver 8.8.8.8
nameserver 8.8.4.4
(chroot) x8664Arch / # ping -c 3 google.com
PING google.com (172.217.163.46) 56(84) bytes of data.
64 bytes from maa05s01-in-f14.1e100.net (172.217.163.46): icmp_seq=1 ttl=57 time=4.74 ms
64 bytes from tsa01s13-in-f14.1e100.net (172.217.163.46): icmp_seq=2 ttl=57 time=6.92 ms
  1. add the MAKEOPTS to /etc/portage/make.conf
#
# *** MAKEOPTS ***  for Odroid-h2
# With MAKEOPTS you define how many parallel compilations should occur
# when you install a package. A good choice is the number of CPUs (or CPU cores)
# in your system plus one, but this guideline isn't always perfect.
MAKEOPTS="-j4"
  1. set time zone

??LC_TIME

(chroot) h2Jammy / # date
Sun Oct 22 07:36:20 -00 2023
(chroot) h2Jammy / # timedatectl set-timezone Asia/Taipei
(chroot) h2Jammy / # date
Sun Oct 22 07:36:44 -00 2023   --> not changed?? LC_TIME??
  1. nano /etc/portage/repos.conf/gentoo.conf as
(chroot) h2Jammy / # cp -v /usr/share/portage/config/repos.conf /etc/portage/repos.conf/gentoo.conf
'/usr/share/portage/config/repos.conf' -> '/etc/portage/repos.conf/gentoo.conf'
(chroot) h2Jammy / # cat /etc/portage/repos.conf/gentoo.conf 
[DEFAULT]
main-repo = gentoo

[gentoo]
location = /var/db/repos/gentoo
sync-type = rsync
sync-uri = rsync://rsync.gentoo.org/gentoo-portage
auto-sync = yes
sync-rsync-verify-jobs = 1
sync-rsync-verify-metamanifest = yes
sync-rsync-verify-max-age = 24
sync-openpgp-key-path = /usr/share/openpgp-keys/gentoo-release.asc
sync-openpgp-keyserver = hkps://keys.gentoo.org
sync-openpgp-key-refresh-retry-count = 40
sync-openpgp-key-refresh-retry-overall-timeout = 1200
sync-openpgp-key-refresh-retry-delay-exp-base = 2
sync-openpgp-key-refresh-retry-delay-max = 60
sync-openpgp-key-refresh-retry-delay-mult = 4
sync-webrsync-verify-signature = yes
  1. emerge-webrsync
(chroot) h2Jammy / # ls -l /etc/portage/make.profile 
lrwxrwxrwx 1 root root 67 Oct 15 19:00 /etc/portage/make.profile -> ../../var/db/repos/gentoo/profiles/default/linux/amd64/17.1/systemd
(chroot) h2Jammy / # ls -l /var/db/repos/gentoo/profiles/default/linux/amd64/17.1/systemd 
total 20
drwxr-xr-x 3 root root 4096 Oct 22 07:42 clang
-rw-r--r-- 1 root root    2 Dec  8  2017 eapi
drwxr-xr-x 2 root root 4096 Oct 22 07:42 merged-usr
-rw-r--r-- 1 root root   34 Dec  8  2017 parent
drwxr-xr-x 3 root root 4096 Oct 22 07:42 selinux

(chroot) h2Jammy / # eselect profile show 
Current /etc/portage/make.profile symlink:
  default/linux/amd64/17.1/systemd

(chroot) h2Jammy / # emerge-webrsync
(chroot) h2Jammy / # ls -l /etc/portage/make.profile   --> after `emerge-webrsync` the following link is OK
lrwxrwxrwx 1 root root 67 Oct 16 03:43 /etc/portage/make.profile -> ../../var/db/repos/gentoo/profiles/default/linux/arm64/17.0/systemd
(chroot) h2Jammy / # ls -l /var/db/repos/gentoo/profiles/default/linux/arm64/17.0/systemd
total 20
-rw-r--r-- 1 root root    2 Oct  6  2017 eapi
drwxr-xr-x 3 root root 4096 Oct 22 06:24 llvm
drwxr-xr-x 2 root root 4096 Oct 22 06:24 merged-usr
-rw-r--r-- 1 root root   34 Oct  6  2017 parent
  1. eselect profile
(chroot) h2Jammy / # eselect profile list
Available profile symlink targets:
  [1]   default/linux/amd64/17.1 (stable)
  [2]   default/linux/amd64/17.1/selinux (stable)
  [3]   default/linux/amd64/17.1/hardened (stable)
  [4]   default/linux/amd64/17.1/hardened/selinux (stable)
  [5]   default/linux/amd64/17.1/desktop (stable)
  [6]   default/linux/amd64/17.1/desktop/gnome (stable)
  [7]   default/linux/amd64/17.1/desktop/gnome/systemd (stable)
  [8]   default/linux/amd64/17.1/desktop/gnome/systemd/merged-usr (stable)
  [9]   default/linux/amd64/17.1/desktop/plasma (stable)
  [10]  default/linux/amd64/17.1/desktop/plasma/systemd (stable)
  [11]  default/linux/amd64/17.1/desktop/plasma/systemd/merged-usr (stable)
  [12]  default/linux/amd64/17.1/desktop/systemd (stable)
  [13]  default/linux/amd64/17.1/desktop/systemd/merged-usr (stable)
  [14]  default/linux/amd64/17.1/developer (exp)
  [15]  default/linux/amd64/17.1/no-multilib (stable)
  [16]  default/linux/amd64/17.1/no-multilib/hardened (stable)
  [17]  default/linux/amd64/17.1/no-multilib/hardened/selinux (stable)
  [18]  default/linux/amd64/17.1/no-multilib/systemd (dev)
  [19]  default/linux/amd64/17.1/no-multilib/systemd/merged-usr (dev)
  [20]  default/linux/amd64/17.1/no-multilib/systemd/selinux (exp)
  [21]  default/linux/amd64/17.1/no-multilib/systemd/selinux/merged-usr (exp)
  [22]  default/linux/amd64/17.1/systemd (stable) *
  [23]  default/linux/amd64/17.1/systemd/merged-usr (stable)
  [24]  default/linux/amd64/17.1/systemd/selinux (exp)
  [25]  default/linux/amd64/17.1/systemd/selinux/merged-usr (exp)
  [26]  default/linux/amd64/17.1/clang (exp)
  [27]  default/linux/amd64/17.1/systemd/clang (exp)
  [28]  default/linux/amd64/17.1/systemd/clang/merged-usr (exp)
  [29]  default/linux/amd64/17.0/x32 (dev)
  [30]  default/linux/amd64/17.0/x32/systemd (exp)
  [31]  default/linux/amd64/17.0/x32/systemd/merged-usr (exp)
  [32]  default/linux/amd64/17.0/musl (dev)
  [33]  default/linux/amd64/17.0/musl/clang (exp)
  [34]  default/linux/amd64/17.0/musl/hardened (exp)
  [35]  default/linux/amd64/17.0/musl/hardened/selinux (exp)
  1. Your First Gentoo System Update
(chroot) h2Jammy / # find /var -name world
/var/lib/portage/world
(chroot) h2Jammy / # file  /var/lib/portage/world 
/var/lib/portage/world: empty

(chroot) h2nas01 / # emerge --ask --verbose --update --deep --newuse @world

These are the packages that would be merged, in order:


12) install your first package `git` 

(chroot) x8664Arch / # emerge --ask dev-vcs/git (chroot) x8664Arch / # which git /usr/bin/git


13) [Get kermel source and compile](https://www.unixmen.com/a-beginners-guide-to-install-gentoo/)

Gentoo provide several kernel sources. Please read http://www.gentoo.org/doc/en/gentoo-kernel.xml for more information.<<-- 404 error

We are going to use the gentoo-sources.  `emerge gentoo-sources` It would automatically create a symbolic link /usr/src/linux pointing to you kernel source directory in /usr/src.

(chroot) x8664Arch / # emerge sys-kernel/gentoo-sources (chroot) h2Jammy / # eselect kernel list Available kernel symlink targets: [1] linux-6.1.57-gentoo (chroot) h2Jammy / # eselect kernel set 1 (chroot) h2Jammy / # ls -l /usr/src/ total 4 lrwxrwxrwx 1 root root 19 Oct 22 08:20 linux -> linux-6.1.57-ge



13) `emerge sys-kernel/genkernel`

(chroot) h2Jammy / # emerge sys-kernel/genkernel

Calculating dependencies... done! Dependency resolution took 2.39 s.

!!! All ebuilds that could satisfy "sys-kernel/linux-firmware" have been masked. !!! One of the following masked packages is required to complete your request:

(dependency required by "sys-kernel/genkernel-4.3.6::gentoo[firmware]" [ebuild]) (dependency required by "sys-kernel/genkernel" [argument]) For more information, see the MASKED PACKAGES section in the emerge man page or refer to the Gentoo Handbook.

(chroot) h2Jammy / # emerge sys-kernel/genkernel --autounmask-write --autounmask

Calculating dependencies... done! Dependency resolution took 1.82 s.

[ebuild N ] sys-kernel/linux-firmware-20230919 USE="redistributable -compress-xz -compress-zstd -initramfs -savedconfig (-unknown-license)" [ebuild N ] sys-kernel/genkernel-4.3.6 USE="firmware (-ibm)" PYTHON_SINGLE_TARGET="python3_11 -python3_10"

The following license changes are necessary to proceed: (see "package.license" in the portage(5) man page for more details)

required by sys-kernel/genkernel-4.3.6::gentoo[firmware]

required by sys-kernel/genkernel (argument)

=sys-kernel/linux-firmware-20230919 linux-fw-redistributable

Autounmask changes successfully written.

(chroot) h2Jammy / # dispatch-conf --- /tmp/tmpp0mzc18s/0 2023-10-22 08:26:24.722193335 -0000 +++ /etc/portage/._cfg0000_package.license 2023-10-22 08:24:39.521699883 -0000 @@ -1 +1,3 @@ -/dev/null +# required by sys-kernel/genkernel-4.3.6::gentoo[firmware] +# required by sys-kernel/genkernel (argument) +=sys-kernel/linux-firmware-20230919 linux-fw-redistributable

(1 of 1) -- /etc/portage/package.license q quit, h help, n next, e edit-new, z zap-new, u use-new <-- to accept m merge, t toggle-merge, l look-merge:

(chroot) h2Jammy / # emerge sys-kernel/genkernel


> skip use `genkerbel all`

14) `make x86_64_defconfig` `time make -j 4` && `make modules-install` && `make install`\

(chroot) x8664Arch /usr/src/linux-6.1.57-gentoo # make x86_64_defconfig HOSTCC scripts/basic/fixdep HOSTCC scripts/kconfig/conf.o HOSTCC scripts/kconfig/confdata.o HOSTCC scripts/kconfig/expr.o LEX scripts/kconfig/lexer.lex.c YACC scripts/kconfig/parser.tab.[ch] HOSTCC scripts/kconfig/lexer.lex.o HOSTCC scripts/kconfig/menu.o HOSTCC scripts/kconfig/parser.tab.o HOSTCC scripts/kconfig/preprocess.o HOSTCC scripts/kconfig/symbol.o HOSTCC scripts/kconfig/util.o HOSTLD scripts/kconfig/conf

configuration written to .config


>Kernel configuration: In order to support native (U)EFI, the kernel needs to be configured with EFI support.
KERNEL Enable basic EFI boot support.  It is a deafult choice

- `make menuconfig`

Processor type and features ---> [*] EFI runtime service support (EFI=y) [ ] EFI stub support (EFI_STUB=n) [ ] EFI mixed-mode support (EFI_MIXED=n)




(chroot) x8664Arch / # cd usr/src/linux-6.1.57-gentoo/ (chroot) x8664Arch /usr/src/linux-6.1.57-gentoo # make menuconfig HOSTCC scripts/basic/fixdep UPD scripts/kconfig/mconf-cfg HOSTCC scripts/kconfig/mconf.o HOSTCC scripts/kconfig/lxdialog/checklist.o HOSTCC scripts/kconfig/lxdialog/inputbox.o HOSTCC scripts/kconfig/lxdialog/menubox.o HOSTCC scripts/kconfig/lxdialog/textbox.o HOSTCC scripts/kconfig/lxdialog/util.o HOSTCC scripts/kconfig/lxdialog/yesno.o HOSTCC scripts/kconfig/confdata.o HOSTCC scripts/kconfig/expr.o LEX scripts/kconfig/lexer.lex.c YACC scripts/kconfig/parser.tab.[ch] HOSTCC scripts/kconfig/lexer.lex.o HOSTCC scripts/kconfig/menu.o HOSTCC scripts/kconfig/parser.tab.o HOSTCC scripts/kconfig/preprocess.o HOSTCC scripts/kconfig/symbol.o HOSTCC scripts/kconfig/util.o HOSTLD scripts/kconfig/mconf

using defaults found in arch/x86/configs/x86_64_defconfig

*** End of the configuration. *** Execute 'make' to start the build or try 'make help'.

(chroot) x8664Arch /usr/src/linux-6.1.57-gentoo # make -j4 .. real 018m34.177s user 062m34.969s sys 007m29.838s

- ` make modules_install`

(chroot) h2Jammy / # ls /lib cpp gentoo libBrokenLocale.so.1 libc.so.6 libcrypt.so.1 libcrypt.so.2 libdl.so.2 libmemusage.so libnss_compat.so.2 libnss_dns.so.2 libnss_hesiod.so.2 libpcprofile.so libresolv.so.2 libthread_db.so.1 modprobe.d systemd firmware ld-linux.so.2 libanl.so.1 libc_malloc_debug.so.0 libcrypt.so.1.1.0 libcrypt.so.2.0.0 libm.so.6 libnsl.so.1 libnss_db.so.2 libnss_files.so.2 libowcrypt.so.1 libpthread.so.0 librt.so.1 libutil.so.1 sysctl.d udev

(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # make modules <-- not necessary CALL scripts/checksyscalls.sh DESCEND objtool

(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # make modules_install INSTALL /lib/modules/6.1.57-gentoo/kernel/drivers/thermal/intel/x86_pkg_temp_thermal.ko INSTALL /lib/modules/6.1.57-gentoo/kernel/fs/efivarfs/efivarfs.ko INSTALL /lib/modules/6.1.57-gentoo/kernel/net/ipv4/netfilter/iptable_nat.ko INSTALL /lib/modules/6.1.57-gentoo/kernel/net/netfilter/nf_log_syslog.ko INSTALL /lib/modules/6.1.57-gentoo/kernel/net/netfilter/xt_LOG.ko INSTALL /lib/modules/6.1.57-gentoo/kernel/net/netfilter/xt_MASQUERADE.ko INSTALL /lib/modules/6.1.57-gentoo/kernel/net/netfilter/xt_addrtype.ko INSTALL /lib/modules/6.1.57-gentoo/kernel/net/netfilter/xt_mark.ko INSTALL /lib/modules/6.1.57-gentoo/kernel/net/netfilter/xt_nat.ko DEPMOD /lib/modules/6.1.57-gentoo

---

15) `emerge sys-kernel/genkernel`

> zcat /proc/config.gz > /path/to/save/config-file

(chroot) x8664Arch /usr/src/linux-6.1.57-gentoo # emerge -av sys-kernel/genkernel

These are the packages that would be merged, in order:

Calculating dependencies... done! Dependency resolution took 11.92 s.

!!! All ebuilds that could satisfy "sys-kernel/linux-firmware" have been masked. !!! One of the following masked packages is required to complete your request:

(dependency required by "sys-kernel/genkernel-4.3.5::gentoo[firmware]" [ebuild]) (dependency required by "sys-kernel/genkernel" [argument]) For more information, see the MASKED PACKAGES section in the emerge man page or refer to the Gentoo Handbook.


nano /etc/portage/package.license

and add this line `sys-kernel/linux-firmware linux-fw-redistributable`

Save the file and proceed to the next step.

Update Portage: After creating or updating the package.license file, update Portage to recognize the changes:

`emerge --sync`

Retry Emerge: Now, attempt to emerge the `sys-kernel/genkernel` package again:

`emerge -av sys-kernel/genkernel`


  1. EFI partiton prepare /boot partiton, using UEFI
# mkfs.vfat -F 32 /dev/sdcb1

(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # mount /dev/sdb1 /boot

The EFI system partition (also called ESP) is an OS independent partition that acts as the storage place for the UEFI boot loaders, applications and drivers to be launched by the UEFI firmware. It is mandatory for UEFI boot.

(chroot) x8664Arch /usr/src/linux-6.1.57-gentoo # emerge --ask sys-fs/dosfstools
(chroot) x8664Arch /usr/src/linux-6.1.57-gentoo # mkfs.vfat /dev/sdb1
mkfs.fat 4.2 (2021-01-31)
(chroot) x8664Arch /usr/src/linux-6.1.57-gentoo # mkdir /boot/efi
(chroot) x8664Arch /usr/src/linux-6.1.57-gentoo # emerge --ask sys-boot/grub
(chroot) x8664Arch /usr/src/linux-6.1.57-gentoo # mount /dev/sdb1 /boot/efi
sda                                                                             
├─sda1 vfat     FAT32       A6B2-B8FE                                           
├─sda2 swap     1           8ddb5338-29e3-41cd-9a8d-309661a4c041                [SWAP]
└─sda3 xfs                  f8023652-925e-46ef-8d10-e6c74d620beb                
sdb                                                                             
├─sdb1 vfat     FAT32       8188-DC88                                 2G     1% /boot/efi
├─sdb2 swap     1           87986311-674c-4619-946d-3a77c7e665a9                
└─sdb3 ext4     1.0         35fb079d-4755-475e-bd03-afbb48774b94   83.3G     6% /
(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=Gentoo
Installing for x86_64-efi platform.
Installation finished. No error reported.
# emerge app-text/tree   <-- install tree command
(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # tree /boot/ -L 2
/boot/
├── System.map-6.1.57-gentoo-x86_64
├── efi
│   └── EFI
├── grub
│   ├── fonts
│   ├── grubenv
│   ├── locale
│   ├── themes
│   └── x86_64-efi
├── initramfs-6.1.57-gentoo-x86_64.img
└── vmlinuz-6.1.57-gentoo-x86_64

8 directories, 4 files

(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # tree /boot/efi/EFI/
/boot/efi/EFI/
└── Gentoo
    └── grubx64.efi

2 directories, 1 file

(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # ls -l /boot/efi/EFI/Gentoo/
total 132
-rwxr-xr-x 1 root root 135168 Oct 23 01:54 grubx64.efi

(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.1.57-gentoo-x86_64
Found initrd image: /boot/initramfs-6.1.57-gentoo-x86_64.img
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done

(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # grub-install /dev/sdb
Installing for x86_64-efi platform.
Installation finished. No error reported.

(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # tree /boot/ -L 2
/boot/
├── System.map-6.1.57-gentoo-x86_64
├── efi
│   └── EFI
├── grub
│   ├── fonts
│   ├── grub.cfg     <--- booting information
│   ├── grubenv
│   ├── locale
│   ├── themes
│   └── x86_64-efi
├── initramfs-6.1.57-gentoo-x86_64.img
└── vmlinuz-6.1.57-gentoo-x86_64

8 directories, 5 files

(chroot) h2Jammy /usr/src # emerge app-arch/zstd nano /etc/genkernel.conf `COMPRESS_INITRD_TYPE="zstd" genkernel --install initramfs

(chroot) h2Jammy /usr/src # genkernel --install initramfs --kernel-config=/usr/src/def_config 
* Gentoo Linux Genkernel; Version 4.3.6
* Using genkernel configuration from '/etc/genkernel.conf' ...
* Running with options: --install initramfs --kernel-config=/usr/src/def_config

* Working with Linux kernel 6.1.57-gentoo-x86_64 for x86_64
* Using kernel config file '/usr/src/def_config' ...

* initramfs: >> Initializing ...
*         >> Appending devices cpio data ...
*         >> Appending base_layout cpio data ...
*         >> Appending util-linux cpio data ...
*         >> Appending eudev cpio data ...
*         >> Appending auxiliary cpio data ...
*         >> Appending busybox cpio data ...
*         >> Appending modprobed cpio data ...
*         >> Appending modules cpio data ...
*                 modules: 0 modules copied. Is that correct?
*         >> Deduping cpio ...
*         >> Pre-generating initramfs' /etc/ld.so.cache ...
*         >> Compressing cpio data (.zst) ...
* 
* You will find the initramfs in '/boot/initramfs-6.1.57-gentoo-x86_64.img'.

* WARNING... WARNING... WARNING...
* Additional kernel parameters that *may* be required to boot properly:

* Do NOT report kernel bugs as genkernel bugs unless your bug
* is about the default genkernel configuration...
* 
* Make sure you have the latest ~arch genkernel before reporting bugs.
(chroot) h2Jammy /usr/src # file /boot/initramfs-6.1.57-gentoo-x86_64.img 
/boot/initramfs-6.1.57-gentoo-x86_64.img: Zstandard compressed data (v0.8+), Dictionary ID: None

grub.cfg

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="0"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_gpt
insmod ext2
set root='hd1,gpt3'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd1,gpt3 --hint-efi=hd1,gpt3 --hint-baremetal=ahci1,gpt3  35fb079d-4755-475e-bd03-afbb48774b94
else
  search --no-floppy --fs-uuid --set=root 35fb079d-4755-475e-bd03-afbb48774b94
fi
    font="/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=en_US
  insmod gettext
fi
terminal_output gfxterm
if [ x$feature_timeout_style = xy ] ; then
  set timeout_style=menu
  set timeout=5
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
  set timeout=5
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Gentoo GNU/Linux' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-35fb079d-4755-475e-bd03-afbb48774b94' {
        load_video
        insmod gzio
        insmod part_gpt
        insmod ext2
        set root='hd1,gpt3'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd1,gpt3 --hint-efi=hd1,gpt3 --hint-baremetal=ahci1,gpt3  35fb079d-4755-475e-bd03-afbb48774b94
        else
          search --no-floppy --fs-uuid --set=root 35fb079d-4755-475e-bd03-afbb48774b94
        fi
        echo    'Loading Linux 6.1.57-gentoo-x86_64 ...'
        linux   /boot/vmlinuz-6.1.57-gentoo-x86_64 root=UUID=35fb079d-4755-475e-bd03-afbb48774b94 ro  
        echo    'Loading initial ramdisk ...'
        initrd  /boot/initramfs-6.1.57-gentoo-x86_64.img
}
submenu 'Advanced options for Gentoo GNU/Linux' $menuentry_id_option 'gnulinux-advanced-35fb079d-4755-475e-bd03-afbb48774b94' {
        menuentry 'Gentoo GNU/Linux, with Linux 6.1.57-gentoo-x86_64' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.1.57-gentoo-x86_64-advanced-35fb079d-4755-475e-bd03-afbb48774b94' {
                load_video
                insmod gzio
                insmod part_gpt
                insmod ext2
                set root='hd1,gpt3'
                if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd1,gpt3 --hint-efi=hd1,gpt3 --hint-baremetal=ahci1,gpt3  35fb079d-4755-475e-bd03-afbb48774b94
                else
                  search --no-floppy --fs-uuid --set=root 35fb079d-4755-475e-bd03-afbb48774b94
                fi
                echo    'Loading Linux 6.1.57-gentoo-x86_64 ...'
                linux   /boot/vmlinuz-6.1.57-gentoo-x86_64 root=UUID=35fb079d-4755-475e-bd03-afbb48774b94 ro  
                echo    'Loading initial ramdisk ...'
                initrd  /boot/initramfs-6.1.57-gentoo-x86_64.img
        }
        menuentry 'Gentoo GNU/Linux, with Linux 6.1.57-gentoo-x86_64 (recovery mode)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.1.57-gentoo-x86_64-recovery-35fb079d-4755-475e-bd03-afbb48774b94' {
                load_video
                insmod gzio
                insmod part_gpt
                insmod ext2
                set root='hd1,gpt3'
                if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-bios=hd1,gpt3 --hint-efi=hd1,gpt3 --hint-baremetal=ahci1,gpt3  35fb079d-4755-475e-bd03-afbb48774b94
                else
                  search --no-floppy --fs-uuid --set=root 35fb079d-4755-475e-bd03-afbb48774b94
                fi
                echo    'Loading Linux 6.1.57-gentoo-x86_64 ...'
                linux   /boot/vmlinuz-6.1.57-gentoo-x86_64 root=UUID=35fb079d-4755-475e-bd03-afbb48774b94 ro single 
                echo    'Loading initial ramdisk ...'
                initrd  /boot/initramfs-6.1.57-gentoo-x86_64.img
        }
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/30_uefi-firmware ###
menuentry 'UEFI Firmware Settings' $menuentry_id_option 'uefi-firmware' {
        fwsetup
}
### END /etc/grub.d/30_uefi-firmware ###

### BEGIN /etc/grub.d/40_custom ###
# 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.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg
fi
### END /etc/grub.d/41_custom ###

  1. genkernel --install initramfs
(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo #  genkernel --install initramfs
* Gentoo Linux Genkernel; Version 4.3.6
* Using genkernel configuration from '/etc/genkernel.conf' ...
* Running with options: --install initramfs

* Working with Linux kernel 6.1.57-gentoo for x86_64
* Using kernel config file '/usr/share/genkernel/arch/x86_64/generated-config' ...

* Current kernel's LOCALVERSION is set to ''; Will ignore set --kernel-localversion value '-x86_64' because kernel was not built ...

* initramfs: >> Initializing ...
*         >> Appending devices cpio data ...
*         >> Appending base_layout cpio data ...
*         >> Appending util-linux cpio data ...
*         >> Appending eudev cpio data ...
*         >> Appending auxiliary cpio data ...
*         >> Appending busybox cpio data ...
*         >> Appending modprobed cpio data ...
*         >> Appending modules cpio data ...
*                 modules: 0 modules copied. Is that correct?
*         >> Deduping cpio ...
*         >> Pre-generating initramfs' /etc/ld.so.cache ...
*         >> Compressing cpio data (.xz) ...
xz: Reduced the number of threads from 4 to 1 to not exceed the memory usage limit of 1940 MiB
* 
* You will find the initramfs in '/boot/initramfs-6.1.57-gentoo.img'.

* WARNING... WARNING... WARNING...
* Additional kernel parameters that *may* be required to boot properly:

* Do NOT report kernel bugs as genkernel bugs unless your bug
* is about the default genkernel configuration...
* 
* Make sure you have the latest ~arch genkernel before reporting bugs.
* Failed to determine session leader; Will not try to stop child processes
(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # ls -l /boot/
total 14360
-rwxr-xr-x 1 root root 11461088 Oct 23 01:39 bzImage-6.1.57
drwxr-xr-x 3 root root     4096 Oct 23 01:54 efi
drwxr-xr-x 6 root root     4096 Oct 23 02:00 grub
-rwxr-xr-x 1 root root  3229152 Oct 23 02:23 initramfs-6.1.57-gentoo.img
(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # file /boot/initramfs-6.1.57-gentoo.img 
/boot/initramfs-6.1.57-gentoo.img: XZ compressed data, checksum NONE
  1. /etc/fstab
#LABEL=boot             /boot               ext4            defaults        1 2
UUID=8188-DC88          /boot/efi           vfat            defaults        1 2

#LABEL=root                                             /               ext4            defaults                0 1
UUID=35fb079d-4755-475e-bd03-afbb48774b94               /               ext4            defaults                0 1

#LABEL=swap                                             none            swap            sw                      0 0
UUID=87986311-674c-4619-946d-3a77c7e665a9               none            swap            sw                      0 0
#/dev/cdrom             /mnt/cdrom      auto            noauto,ro       0 0

# /dev/sdb2: UUID="87986311-674c-4619-946d-3a77c7e665a9" TYPE="swap" PARTLABEL="Linux swap" PARTUUID="b4fde5db-de26-4e2a-b19a-1af91c18e42b"
# /dev/sdb3: UUID="35fb079d-4755-475e-bd03-afbb48774b94" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="11132367-99d7-4509-81e4-bcd5f7e49522"
# /dev/sdb1: UUID="8188-DC88" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="40e78280-6bf9-472a-bd81-fe72e92e74e2"
  1. emerge -av net-misc/dhcpcd

  2. genkernel

(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # make x86_64_defconfig
  HOSTCC  scripts/basic/fixdep
  HOSTCC  scripts/kconfig/conf.o
  HOSTCC  scripts/kconfig/confdata.o
  HOSTCC  scripts/kconfig/expr.o
  LEX     scripts/kconfig/lexer.lex.c
  YACC    scripts/kconfig/parser.tab.[ch]
  HOSTCC  scripts/kconfig/lexer.lex.o
  HOSTCC  scripts/kconfig/menu.o
  HOSTCC  scripts/kconfig/parser.tab.o
  HOSTCC  scripts/kconfig/preprocess.o
  HOSTCC  scripts/kconfig/symbol.o
  HOSTCC  scripts/kconfig/util.o
  HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#
(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # cp .config ../def_config -v
'.config' -> '../def_config'
(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # genkernel all --kernel-config=/usr/src/def_config 
* Gentoo Linux Genkernel; Version 4.3.6
* Using genkernel configuration from '/etc/genkernel.conf' ...
* Running with options: all --kernel-config=/usr/src/def_config

* Working with Linux kernel 6.1.57-gentoo for x86_64
* Using kernel config file '/usr/src/def_config' ...
* 
* Note: The version above is subject to change (depends on config and status of kernel sources).

* kernel: >> Initializing ...
*         >> Running 'make mrproper' ...
*         >> Running 'make oldconfig' ...
*         >> Re-running 'make oldconfig' due to changed kernel options ...
*         >> Kernel version has changed (probably due to config change) since genkernel start:
*            We are now building Linux kernel 6.1.57-gentoo-x86_64 for x86_64 ...
*         >> Compiling 6.1.57-gentoo-x86_64 bzImage ...
*         >> Compiling 6.1.57-gentoo-x86_64 modules ...
*         >> Installing 6.1.57-gentoo-x86_64 modules (and stripping) ...
*         >> Generating module dependency data ...
*         >> Compiling out-of-tree module(s) ...
*         >> Saving config of successful build to '/etc/kernels/kernel-config-6.1.57-gentoo-x86_64' ...

* initramfs: >> Initializing ...
*         >> Appending devices cpio data ...
*         >> Appending base_layout cpio data ...
*         >> Appending util-linux cpio data ...
*         >> Appending eudev cpio data ...
*         >> Appending auxiliary cpio data ...
*         >> Appending busybox cpio data ...
*         >> Appending modprobed cpio data ...
*         >> Appending modules cpio data ...
*                 modules: 0 modules copied. Is that correct?
*         >> Deduping cpio ...
*         >> Pre-generating initramfs' /etc/ld.so.cache ...
*         >> Compressing cpio data (.xz) ...
xz: Reduced the number of threads from 4 to 1 to not exceed the memory usage limit of 1940 MiB

* Kernel compiled successfully!
* 
* --no-bootloader set; Skipping bootloader update ...
* 
* Required kernel parameter:
* 
* 	root=/dev/$ROOT
* 
* Where $ROOT is the device node for your root partition as the
* one specified in /etc/fstab

* If you require Genkernel's hardware detection features, you MUST
* tell your bootloader to use the provided initramfs file '/boot/initramfs-6.1.57-gentoo-x86_64.img'.

* WARNING... WARNING... WARNING...
* Additional kernel parameters that *may* be required to boot properly:

* Do NOT report kernel bugs as genkernel bugs unless your bug
* is about the default genkernel configuration...
* 
* Make sure you have the latest ~arch genkernel before reporting bugs.
* Failed to determine session leader; Will not try to stop child processes
(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # tree /boot/
/boot/
├── System.map-6.1.57-gentoo-x86_64
├── initramfs-6.1.57-gentoo-x86_64.img
└── vmlinuz-6.1.57-gentoo-x86_64

1 directory, 3 files
(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # file /boot/vmlinuz-6.1.57-gentoo-x86_64 
/boot/vmlinuz-6.1.57-gentoo-x86_64: Linux kernel x86 boot executable bzImage, version 6.1.57-gentoo-x86_64 (root@h2Jammy) #1 SMP PREEMPT_DYNAMIC Mon Oct 23 03:35:54 -00 2023, RO-rootFS, swap_dev 0XA, Normal VGA
(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # file /boot/initramfs-6.1.57-gentoo-x86_64.img 
/boot/initramfs-6.1.57-gentoo-x86_64.img: XZ compressed data, checksum NONE

/boot/initramfs-6.1.57-gentoo-x86_64.img: XZ compressed data, checksum NONE
(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # ls /lib/modules/
6.1.57-gentoo  6.1.57-gentoo-x86_64
(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # ls /lib/modules/6.1.57-gentoo-x86_64/
build   modules.alias      modules.builtin            modules.builtin.bin      modules.dep      modules.devname  modules.softdep  modules.symbols.bin

(chroot) h2Jammy /usr/src/linux-6.1.57-gentoo # rm -rf /lib/modules/6.1.57-gentoo


Once you've created the EFI partition, format it with the FAT32 file system. You can use the mkfs.fat command for this purpose.

Mount the EFI Partition:

Create a mount point for the EFI partition, for example: mkdir /mnt/gentoo/boot/efi
Mount the EFI partition to this directory: mount /dev/sdX1 /mnt/gentoo/boot/efi (replace /dev/sdX1 with the actual partition name)

Install Bootloader (GRUB in this example):

Chroot into your Gentoo installation: chroot /mnt/gentoo /bin/bash

Install GRUB package (if not already installed): emerge --ask sys-boot/grub

Install GRUB to the EFI partition: grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=Gentoo

Generate GRUB configuration: grub-mkconfig -o /boot/grub/grub.cfg

Configure Network (if needed):

Set up networking in the chroot environment if you need to download additional packages or updates within the chrooted environment.

Exit Chroot and Reboot:

Exit the chroot environment: exit

Unmount all mounted partitions: umount -R /mnt/gentoo

Reboot your system: reboot