I executed these commands here:
Code: Select all
mkdir /usr/src/initramfs
cd /usr/src/linux
make -C /usr/src/linux/usr/ gen_init_cpio
chmod +x usr/gen_init_cpio usr/gen_initramfs_list.sh ## gen_initramfs_list.sh does not exist for some reason...
nano -w /usr/src/initramfs/initramfs_list
mkdir --parents /usr/src/initramfs/{usr,var,bin,dev,etc,lib,lib64,mnt,mnt/root,proc,root,sbin,sys}
cp --archive /dev/{null,console,tty,mapper} /usr/src/initramfs/dev/ # Need to remove sda1 archive as that is not where the system is going to be at. As for right now, everything is in chroot..
USE="static" emerge --ask --verbose sys-apps/busybox
cp --archive /bin/busybox /usr/src/initramfs/bin/busybox
USE="-udev, static" emerge --quiet sys-fs/lvm2 # This allows you to copy the lvm into the intiramfs, so it can use it
cp --archive /sbin/lvm /usr/src/initramfs/sbin/lvm
cd /usr/src/initramfs
find . -print0 | cpio --null --create --verbose --format=newc | gzip --best > /boot/custom-initramfs.cpio.gz
cd /usr/src/linux
usr/gen_init_cpio /root/initrd/initramfs_list > /boot/initramfs_static # Haven't executed this command yet as I am confused if I should or shouldn't
This is what I have for init:
Code: Select all
#!/bin/busybox sh
rescue_shell() {
echo "$@"
echo "Something went wrong. Dropping you to a shell."
busybox --install -s
exec /bin/sh
}
uuidlabel_root() {
for cmd in $(cat /proc/cmdline) ; do
case $cmd in
root=*)
type=$(echo $cmd | cut -d= -f2)
echo "Mounting rootfs"
if [ $type == "LABEL" ] || [ $type == "UUID" ] ; then
uuid=$(echo $cmd | cut -d= -f3)
mount -o ro $(findfs "$type"="$uuid") /mnt/root
else
mount -o ro $(echo $cmd | cut -d= -f2) /mnt/root
fi
;;
esac
done
}
check_filesystem() {
# most of code coming from /etc/init.d/fsck
local fsck_opts= check_extra= RC_UNAME=$(uname -s)
# FIXME : get_bootparam forcefsck
if [ -e /forcefsck ]; then
fsck_opts="$fsck_opts -f"
check_extra="(check forced)"
fi
echo "Checking local filesystem $check_extra : $1"
if [ "$RC_UNAME" = Linux ]; then
fsck_opts="$fsck_opts -C0 -T"
fi
trap : INT QUIT
# using our own fsck, not the builtin one from busybox
/sbin/fsck -p $fsck_opts $1
case $? in
0) return 0;;
1) echo "Filesystem repaired"; return 0;;
2|3) if [ "$RC_UNAME" = Linux ]; then
echo "Filesystem repaired, but reboot needed"
reboot -f
else
rescue_shell "Filesystem still have errors; manual fsck required"
fi;;
4) if [ "$RC_UNAME" = Linux ]; then
rescue_shell "Fileystem errors left uncorrected, aborting"
else
echo "Filesystem repaired, but reboot needed"
reboot
fi;;
8) echo "Operational error"; return 0;;
12) echo "fsck interrupted";;
*) echo "Filesystem couldn't be fixed";;
esac
rescue_shell
}
# temporarily mount proc and sys
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev
# Setting up the root volume that is installed in lvm
lvm vgscan --mknodes # creates /dev/mapper/control
lvm lvchange -a ly VG/root
lvm vgscan --mknodes # creates /dev/mapper/VG-root and /dev/VG/root
# mount using findfs uncomment this out because idk if i'll really need it?
#mount -o ro $(findfs UUID=2<uuid string here>) /mnt/root
#mount -o ro $(findfs UUID=<uuid string here>) /dev/mapper/gentoo-tmp
#mount -o ro $(findfs UUID=<uuid string here>) /dev/mapper/gentoo-swap
#mount -o ro $(findfs UUID=<uuid string here>) /dev/mapper/gentoo-var_log
#mount -o ro $(findfs UUID=<uuid string here>) /dev/mapper/gentoo-root
# disable kernel messages from popping onto the screen
echo 0 > /proc/sys/kernel/printk
# clear the screen
clear
# mounting rootfs on /mnt/root
uuidlabel_root || rescue_shell "Error with uuidlabel_root"
echo "All done. Switching to real root."
# clean up. The init process will remount proc sys and dev later
umount /proc
umount /sys
umount /dev
# switch to the real root and execute init
exec switch_root /mnt/root /sbin/init
And yes, I re-edited the init_list because I didn't understand why NeddySeagoon had /dev/mp-0 # I am guessing that dm stands for device mapper and the 0 is the first partition??
I also removed the mknod and made it nod for each line
Here's the re-edited version of /usr/src/initramfs/initramfs_list
Code: Select all
# directory structure
dir /proc 755 0 0
dir /usr 755 0 0
dir /bin 755 0 0
dir /sys 755 0 0
dir /var 755 0 0
dir /lib 755 0 0
dir /sbin 755 0 0
dir /lib64 755 0 0
#dir /lib32 755 0 0
dir /mnt 755 0 0
dir /mnt/root 755 0 0
dir /etc 755 0 0
dir /root 700 0 0
dir /dev 755 0 0
dir /dev/mapper 755 0 0
dir /etc/lvm 755 0 0
# dev/mmcblk and partitions
nod /dev/mmcblk0 0660 0 0 b 8 0
nod /dev/mmcblk0p1 0660 0 0 b 8 1
nod /dev/mmcblk0p2 0660 0 0 b 8 2
#nod /dev/sda4 0660 0 0 b 8 4
#nod /dev/sda5 0660 0 0 b 8 5
#nod /dev/sda6 0660 0 0 b 8 6
# dev/sdb and partitions
#nod /dev/sdb 0660 0 0 b 8 16
# ...
# dev/sdc and partitions
#nod /dev/sdc 0660 0 0 b 8 32
# all the lvm nodes I need
nod /dev/dm-0 0660 0 0 b 253 0 ## Right here is where I had /dev/gentoo/root. Basically all my lvm partitions right here.
nod /dev/dm-1 0660 0 0 b 253 1
nod /dev/dm-2 0660 0 0 b 254 2
nod /dev/dm-3 0660 0 0 b 254 3
#slink /dev/stderr /proc/self/fd/2 777 0 0
#slink /dev/stdin /proc/self/fd/0 777 0 0
#slink /dev/std/out /proc/self/fd/1 777 0 0
# busybox
file /bin/busybox /bin/busybox 755 0 0
# LVM
file /sbin/lvm.static /sbin/lvm.static 755 0 0
# libraries required by /sbin/fsck.ext4 and /sbin/fsck
slink /lib /lib64 777 0 0
file /lib64/ld-linux-aarch64.so.1 /lib64/ld-linux-aarch64.so.1 755 0 0
file /lib64/libext2fs.so.2 /lib64/libext2fs.so.2 755 0 0
file /lib64/libcom_err.so.2 /lib64/libcom_err.so.2 755 0 0
file /lib64/libpthread.so.0 /lib64/libpthread.so.0 755 0 0
file /lib64/libblkid.so.1 /lib64/libblkid.so.1 755 0 0
file /lib64/libmount.so.1 /lib64/libmount.so.1 755 0 0
file /lib64/libuuid.so.1 /lib64/libuuid.so.1 755 0 0
file /lib64/libe2p.so.2 /lib64/libe2p.so.2 755 0 0
file /lib64/libc.so.6 /lib64/libc.so.6 755 0 0
file /lib64/librt.so.1 /lib64/librt.so.1 755 0 0
file /lib64/libdl.so.2 /lib64/libdl.so.2 755 0 0
file /sbin/fsck /sbin/fsck 755 0 0
file /sbin/fsck.ext4 /sbin/fsck.ext4 755 0 0
# our init script
file /init /usr/src/initramfs/init 755 0 0
Here's my source that I am following:
https://wiki.gentoo.org/wiki/Old_Fashio ... the_initrd
https://wiki.gentoo.org/wiki/Early_Userspace_Mounting https://wiki.gentoo.org/wiki/Custom_Initramfs
I need to remove the sda1 archive and perhaps "feed" the init_list to the /boot/initramfs_static
I also did this to my lvm package:
Code: Select all
Use vgscan as shown above (simplest solution)
Mount by UUID or label instead of using /dev/VG/root. It works because findfs is happy with just /dev/dm-42
Build a LVM binary with the -udev USE flag (specifically for the initramfs only!)
Disable udev dependency by including a minimal /etc/lvm/lvm.conf in the initramfs:
All I need to is recompile my kernel, build the initramfs inside it, move the dtbs files to /boot, move the 32bit out of the way, add the lines for grub in this article:
https://wiki.gentoo.org/wiki/Custom_Initramfs
move the overlays to /boot/overlays. I was thinking about making that a symlink. Because I have more than just one kernel. I know that overlays files exists in /usr/src/<name of kernel>. And Goverp, I think that example is the similar to what I am doing I think. I'll look at it right now actually. And do I need to add more to the /dev? ----> cp --archive /dev/{null,console,tty,mapper} /usr/src/initramfs/dev/ and the article mentioned that you can keep the binaries updated and shot me here:
Code: Select all
Variations for switch_root
Some init setups require proc, sys and dev to be mounted before starting up. If you find you are having trouble with switch_root in your initramfs setup try replacing the umount command with a mount --move in your init script.
For example, replace this.
FILE /usr/src/initramfs/initumount commands
# Clean up
umount /proc
umount /sys
umount /dev
# Boot the real thing
exec switch_root /newroot /sbin/init
With this.
FILE /usr/src/initramfs/initmount --move commands
# Clean up
mount --move /proc /newroot/proc
mount --move /sys /newroot/sys
mount --move /dev /newroot/dev
# Boot the real thing
exec switch_root /newroot /sbin/init
Important
umount is used to ensure that "real" init systems, like OpenRC, start in a clean state. You should ideally use umount if it is possible in this circumstance.
Examples
See Custom_Initramfs/Examples for fully functional examples of finished /init scripts.
See also
Initramfs/Guide — covers the concepts of the initramfs as well as how to properly create and manage initramfs instances.
Early Userspace Mounting — how to build a custom minimal initramfs that checks the /usr filesystem and pre-mounts /usr. Another worth to read article about custom initramfs
External resources
Official initramfs documentation locally (less /usr/src/linux/Documentation/filesystems/ramfs-rootfs-initramfs.txt) or online at kernel.org
Linux® From Scratch - About initramfs
update your initramfs using bash
Categories:
DirtyInitramfs