0

That question: Compiling and installing a kernel.org kernel to a custom volume on disk partially answers my question, however, not completely!

I have a disk with 30GB capacity. It has 2 partitions

  • 2GB partition (/dev/sda1) which contains Debian
  • 28GB partition (/dev/sda2) which is completely empty (formatted, filesystem is ext4)

I want to compile and install kernel.org kernel (https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.78.tar.xz) on /dev/sda2 and setup dual boot between my Debian and new kernel

So far:

I mounted my second partition to /mnt (i.e. mount /dev/sda2 /mnt) and created a directory /src within it (i.e. I have /mnt/src directory)

When in /mnt/src,

I downloaded the kernel and extracted it

wget --no-check-certificate https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.10.78.tar.xz
unxz -v linux-5.10.78.tar.xz
tar xvf linux-5.10.78.tar

I also installed the necessary tools to be able to compile and install the kernel

apt-get update
apt-get install build-essential libncurses-dev bison flex libssl-dev libelf-dev

When in /mnt/src/linux-5.10.78

I copied my existing Debian kernel configuration to the current directory (i.e. cp -v /boot/config-$(uname -r) .config) and then ran make olddefconfig (with the idea to use my existing configuration and provide default values for everything else). I also unchecked the Avoid speculative indirect branches in kernel option because I hit You are building kernel with non-retpoline compiler, please update your compiler.. Stop. during make.

I then ran make -j 4 again and waited for it to finish.

After that I ran INSTALL_MOD_PATH=/mnt INSTALL_PATH=/mnt/boot make modules_install to install the necessary modules, following the suggestion from the question I have linked above.

My problem is that now when I run update-initramfs it fails as it can't find a /lib/modules/5.10.78 folder. That would obviously be the case as it is under /mnt/lib/modules/5.10.78. I tried providing different root path (using the -b option) but that didn't work. I also tried chroot, however, I don't really have the necessary setup/ executables in /mnt to chroot into it.

After "fixing" above, I expect running update-grub would discover the kernel image, the root filesystem for booting it and the configuration files and setup everything so that after reboot I am provided with both booting options (Debian and the new kernel).

Any help with both update-initramfs and the actual grub configuration afterwards would be greatly appreciated! I have found links here and there but they are always very high level overview of the process.

7
  • Could you precise your aim ? At no point you used a debootstrap or other command to load the target partition with an other system. If you do it, you will be able to type chroot /mnt and be able to use update-initramfs. Note that some directory should be mounted to some of the /mnt/* (dev, sys, proc). If you don’t want an other copy of Debian, grub should manage other kernel in its /boot directory. Nov 11, 2021 at 11:32
  • @FrédéricLoyer My aim is to build a custom minimal (in terms of drivers and features) linux distribution from source and be able to use it as booting option (should allow normal usage as OS - eg hardware drivers and filesystems support). First time I am hearing about debootstrap. What does it do exactly? I haven't seen it referenced in any of the articles I have read (e.g. cyberciti.biz/tips/compiling-linux-kernel-26.html, phoenixnap.com/kb/build-linux-kernel, unix.stackexchange.com/questions/115620/…, etc).
    – festiv
    Nov 11, 2021 at 11:38
  • Deboostrap is a Debian installer which install the minimum Debian system which can have a functional apt system and can load other package afterwards. It can be useful to build container images. As a Debian system it may not be minimal is the way you think. Note : the initramfs is needed for kernel with complex booting procedure (root on RAID filesystem). For a minimal system, you don’t need it. Nov 11, 2021 at 11:53
  • initrd is needed if you need to load drivers before mounting root. Typical candidates are video and disk (raid) drivers. If you don't need to do that, it is possible to skip initrd and just jump directly into the real root.
    – user10489
    Nov 11, 2021 at 12:45
  • @FrédéricLoyer, user10489, I don't really have a hard requirement on specifics. I just want to be able to boot using the new kernel, see a terminal, have the expected unix-like filesystem structure and be able to perform the standard commands. Of course, while keeping my other, Debian, partition completely isolated. Want to be able to choose either one at boot time. Can you, by any chance, provide me with specifics on how to achieve that?
    – festiv
    Nov 11, 2021 at 14:03

1 Answer 1

0

One of the easiest way to install a minimal Debian system is debootstrap bullseye /mnt where bullseye is the release you seek, and /mnt the path where you want it to be installed.

It needs a kernel, and your procedure seems correct. Initramfs or initrd is only required for complex boot sequence : typically a root directory in a RAID array. I have none on my server and it works fine. (Note that your root filesystem type mustn’t be compiled as a module but embedded in the kernel).

You should also add an entry in your /boot/grub/grub.cfg. Typically :


menuentry "Alternate Debian , kernel 5.10.78" {
        insmod part_msdos
        insmod ext2
        set root='hd0,msdos2'
        linux   /boot/vmlinuz-5.10.78 root=/dev/sda2 ro  
}

insmod part_msdos is needed if you have an old partition scheme. On UEFI system, it should be insmod part_gpt, but I don’t know them much. insmod ext2 permits grub to read an ext2 (or ext4) file system. set root= indicates on which partition grub should search /boot/vmlinuz-5.10.78 (check the actual name : it may vary), linux indicate it should boot the kernel which follows, root=/dev/sda2 indicates your future root directory.

If you really want a more tiny alternative system, perhaps Gentoo is a better way, but I know it only by name. You should start with debootstrap.

4
  • Thanks for the answer! I feel like using debootstrap would be circumventing my initial goal which is to see how things work a bit more low level. Why do I need it to boot from my kernel image?
    – festiv
    Nov 11, 2021 at 15:34
  • You said Of course, while keeping my other, Debian, partition completely isolated. I guess the isolation you want imply installing a whole alternative system. If you just want another kernel, I see no interest to put it on /dev/sda2 and keep root on /dev/sda1. Perhaps I have not understood your intents. « Why do I need it to boot from my kernel image? ». The idea of booting on your compiled kernel is yours. And debootstrap doesn’t install a kernel, then using your compiled kernel is interesting. But you can use the kernel from /dev/sda1 with the /dev/sda2 root filesystem. Nov 11, 2021 at 15:39
  • Yes, I meant installing a whole alternative system which is really minimal (basically, after boot, provides you with a terminal, file system support, drivers for working with disks etc). Sorry for misleading you.
    – festiv
    Nov 11, 2021 at 16:00
  • A whole system seems to include the kernel, and debootstrap install the remaining of a minimal system, but minimal in a Debian way (with all things needed to add or configure other packages). This means 154 packages, 332MB for buster. You should start with this way before trying a more complex installation. Afterwards, perhaps you should have a look to Gentoo. Nov 11, 2021 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.