/Linux-flatpak

packaging the linux system stuff as a flatpak, just because

Primary LanguageShell

Linux-flatpak

packaging the linux kernel linux stuff as a flatpak, just because
Screencast.from.06-07-2022.07.09.15.PM.mp4

Building

this is still in deveploment, use it at your own risk!

Currently the linux tarball used can only be built on arch system due to the mkinitcpio tool that is only available on arch(-based) distros first you have to build the kernel, to do that download the kernel source of the version you want to build and extract it and configure the kernel to what you want it to be, in my experience the arch default config worked the best and will be used in this guide.

The automated way

install the dependencies with

sudo pacman -S base-devel wget

then download the kernel source, preferrably from https://kernel.org, extract the tarball and apply any patches if you need any

then, if you want, generate a custom kernel configuration or get a premade one, if none is made then the default arch configuration will be used

then just run build-linux-tarball.sh /path/to/extracted/tarball <kernel-version> [path to custom kernel configuration]

The manual way

wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.18.2.tar.xz #we grab the kernel source of linux-5.18.2 from kernel.org
tar -xvf linux-5.18.2.tar.xz # extracting the kernel tarball
cd linux-5.18.2
wget https://raw.githubusercontent.com/archlinux/svntogit-packages/packages/linux/trunk/config # downloading the arch config, skip this part if you have a custom kernel config
make # build the kernel
make modules # build the modules
sudo make modules_install # install the modules to the right directory
cd ../
mkdir linux-packaged
cd linux-packaged
cp ../linux-5.18.2/arch/x86 . # we copy the x86 build directory of the kernel source tree, this is the default for x86_64
cp ../linux-5.18.2/System.map . # copy the System.map file to the root of the kernel tarball
cp /lib/modules/5.18.2 . # copy the installed modules to the root of the kernel tarball
sudo cp /lib/mkinitcpio.d/linux.preset /lib/mkinitcpio.d/5.18.2.preset

then open the file /lib/mkinitcpio.d/5.18.2.preset with your text editor of choice and replace every occurance of linux with 5.18.2

mkinitcpio -p 5.18.2 ./initramfs --kernelimage ./x86/boot/bzImage # generating the tarball
cd ..
tar -cvf linux.tar linux-packaged/

Regardles of the method used, you should end up with a tarball that has this file structure:

.
├── <kernel-version>
│   └── <module stuff>
├── initramfs
├── System.map
└── x86
    └── <kernel stuff>

If you used arch in a vm to build the kernel tarball you can use magic-wormhole to transfer the file to the actual machine you want to "flatpakboot" Then copy the generated linux.tar in the same directory of the other files and run the flatpak build command: flatpak-builder --user --install --force-clean build-dir org.kernel.Linux.yml

once that's finished you can just execute flatpak run org.kernel.Linux and it will copy everything to the right directories.

After that's done you'll just have to modify your bootloader to recognize the new kernel and initramfs You can also use the flatpak version of rEFInd that I've made (can't fully guarantee that it'll work tho)

why

  1. Honestly, no idea, I was very bored and had nothing better to do.
  2. I want to be able to only have some base stuff and flatpak installed through the system package manager, the rest as a flatpak. For example during the arch installation process I want to do pacstrap flatpak base and nothing else, then install everything else using flatpak.