├── .gitignore
├── README.md
├── build-linux-tarball.sh
├── linux-flatpak.png
├── org.gnu.coreutils
├── coreutil-run
└── org.gnu.coreutils.yml
├── org.kernel.Linux
├── linux
├── linux-run
└── org.kernel.Linux.yml
└── org.kernel.linux.variant
├── linux
└── org.kernel.linux.yml
/.gitignore:
--------------------------------------------------------------------------------
1 | .flatpak-builder/
2 | build-dir/
3 | linux.tar
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Linux-flatpak
2 |
3 | packaging the linux kernel linux stuff as a flatpak, just because
4 |
5 | https://user-images.githubusercontent.com/60044824/172443953-37a01a4a-66d8-47af-a25f-45c811abf797.mp4
6 |
7 |
8 | # Building
9 | __this is still in deveploment, use it at your own risk!__
10 |
11 | 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
12 | 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.
13 |
14 | ### The automated way
15 | install the dependencies with
16 | ```bash
17 | sudo pacman -S base-devel wget
18 | ```
19 | then download the kernel source, preferrably from https://kernel.org, extract the tarball and apply any patches if you need any
20 |
21 | 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
22 |
23 | then just run `build-linux-tarball.sh /path/to/extracted/tarball [path to custom kernel configuration]`
24 |
25 | ### The manual way
26 |
27 | ```bash
28 | 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
29 | tar -xvf linux-5.18.2.tar.xz # extracting the kernel tarball
30 | cd linux-5.18.2
31 | 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
32 | make # build the kernel
33 | make modules # build the modules
34 | sudo make modules_install # install the modules to the right directory
35 | cd ../
36 | mkdir linux-packaged
37 | cd linux-packaged
38 | 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
39 | cp ../linux-5.18.2/System.map . # copy the System.map file to the root of the kernel tarball
40 | cp /lib/modules/5.18.2 . # copy the installed modules to the root of the kernel tarball
41 | sudo cp /lib/mkinitcpio.d/linux.preset /lib/mkinitcpio.d/5.18.2.preset
42 | ```
43 | 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`
44 | ```
45 | mkinitcpio -p 5.18.2 ./initramfs --kernelimage ./x86/boot/bzImage # generating the tarball
46 | cd ..
47 | tar -cvf linux.tar linux-packaged/
48 | ```
49 |
50 | ---
51 | Regardles of the method used, you should end up with a tarball that has this file structure:
52 | ```
53 | .
54 | ├──
55 | │ └──
56 | ├── initramfs
57 | ├── System.map
58 | └── x86
59 | └──
60 | ```
61 |
62 | If you used arch in a vm to build the kernel tarball you can use [magic-wormhole](https://github.com/magic-wormhole/magic-wormhole) to transfer the file to the actual machine you want to "flatpakboot"
63 | Then copy the generated `linux.tar` in the same directory of the other files and run the flatpak build command:
64 | `flatpak-builder --user --install --force-clean build-dir org.kernel.Linux.yml`
65 |
66 | once that's finished you can just execute `flatpak run org.kernel.Linux` and it will copy everything to the right directories.
67 |
68 | After that's done you'll just have to modify your bootloader to recognize the new kernel and initramfs
69 | You can also use the [flatpak version of rEFInd](https://github.com/axtloss/flatpaks/tree/main/com.rodsbooks.refind) that I've made (can't fully guarantee that it'll work tho)
70 |
71 | # why
72 | 1) Honestly, no idea, I was very bored and had nothing better to do.
73 | 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.
74 |
--------------------------------------------------------------------------------
/build-linux-tarball.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | if [ -z "$1" ] || [ -z "$2" ]; then
3 | echo "Usage: $0 "
4 | exit 1
5 | fi
6 | KERNEL_VERSION=$2
7 |
8 | mkdir -p ~/linux-tmp
9 | cd ~/linux-tmp
10 | cp -r $1 linux-$KERNEL_VERSION
11 | cd linux-$KERNEL_VERSION
12 | if [ -z "$3" ]; then
13 | cp $3 .config
14 | else
15 | wget https://raw.githubusercontent.com/archlinux/svntogit-packages/packages/linux/trunk/config
16 | fi
17 | make
18 | make modules
19 | echo "Executing sudo for:"
20 | echo "make modules_install"
21 | sudo make modules_install
22 | cd ../
23 | mkdir linux-packaged
24 | cd linux-packaged
25 | cp ../linux-$KERNEL_VERSION/arch/x86 .
26 | cp ../linux-$KERNEL_VERSION/System.map .
27 | cp /lib/modules/$KERNEL_VERSION .
28 | echo "Executing sudo for writing mkinitcpio config file"
29 | sudo echo "ALL_config=\"/etc/mkinitcpio.conf\"" >> /etc/mkinitcpio.d/$KERNEL_VERSION.preset
30 | sudo echo "ALL_kver=\"/boot/vmlinuz-$KERNEL_VERSION\"" >> /etc/mkinitcpio.d/$KERNEL_VERSION.preset
31 | sudo echo "PRESETS=('default' 'fallback')" >> /etc/mkinitcpio.d/$KERNEL_VERSION.preset
32 | sudo echo "default_image=\"/boot/initramfs-$KERNEL_VERSION.img\"" >> /etc/mkinitcpio.d/$KERNEL_VERSION.preset
33 | sudo echo "fallback_image=\"/boot/initramfs-$KERNEL_VERSION-fallback.img\"" >> /etc/mkinitcpio.d/$KERNEL_VERSION.preset
34 | sudo echo "fallback_options=\"-S autodetect\"" >> /etc/mkinitcpio.d/$KERNEL_VERSION.preset
35 | mkinitcpio -p $KERNEL_VERSION -g ./initramfs --kernelimage ./x86/boot/bzImage --kernelfile ./System.map
36 | cd ..
37 | tar -cvf linux.tar linux-packaged
38 | echo "Done! The linux tarball now should be at $(pwd)/linux.tar!"
--------------------------------------------------------------------------------
/linux-flatpak.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/axtloss/Linux-flatpak/d3af6359b85069f024b8542cbc567f5117cc69ce/linux-flatpak.png
--------------------------------------------------------------------------------
/org.gnu.coreutils/coreutil-run:
--------------------------------------------------------------------------------
1 | #!/usr/bin/bash
2 | if [[ "$@" == "" ]]; then
3 | echo "No command given, exiting ..."
4 | exit 1
5 | fi
6 | $@
--------------------------------------------------------------------------------
/org.gnu.coreutils/org.gnu.coreutils.yml:
--------------------------------------------------------------------------------
1 | app-id: org.gnu.coreutils
2 | runtime: org.freedesktop.Platform
3 | runtime-version: '21.08'
4 | sdk: org.freedesktop.Sdk
5 | finish-args:
6 | - --filesystem=host
7 | command: coreutil-run
8 |
9 |
10 | modules:
11 | - name: coreutils
12 | buildsystem: simple
13 | sources:
14 | - type: archive
15 | path: ./coreutils-9.1.tar.xz
16 | dest: ./coreutils
17 | - type: file
18 | path: ./coreutil-run
19 | build-commands:
20 | - ls coreutils
21 | - cd coreutils && ./configure --prefix=/app --libexecdir=/app/lib
22 | - cd coreutils && make
23 | - ls coreutils
24 | - cd coreutils && make install
25 | - install -Dm755 ./coreutil-run /app/bin/coreutil-run
26 |
--------------------------------------------------------------------------------
/org.kernel.Linux/linux:
--------------------------------------------------------------------------------
1 | #!/usr/bin/bash
2 | set -x
3 |
4 | cd $1/kernel/linux-$2/x86
5 | echo $(pwd)
6 | INSTALL_PATH=/boot
7 | LINK_PATH=/boot
8 | RELATIVE_PATH=`echo "$INSTALL_PATH/" | sed "s|^$LINK_PATH/||"`
9 | KERNEL_NAME=vmlinuz
10 | KERNEL_VERSION=$2
11 | BOOTIMAGE=boot/bzImage
12 | MAPFILE=System.map
13 | ARCH=$(uname -m)
14 |
15 | if [ -f $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION ]; then
16 | mv $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION \
17 | $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION.old;
18 | fi
19 |
20 | if [ ! -L $INSTALL_PATH/$KERNEL_NAME ]; then
21 | if [ -e $INSTALLPATH/$KERNEL_NAME ]; then
22 | mv $INSTALL_PATH/$KERNEL_NAME $INSTALL_PATH/$KERNEL_NAME.old
23 | fi
24 | fi
25 |
26 | if [ -f $INSTALL_PATH/System.map-$KERNEL_VERSION ]; then
27 | mv $INSTALL_PATH/System.map-$KERNEL_VERSION \
28 | $INSTALL_PATH/System.map-$KERNEL_VERSION.old;
29 | fi
30 |
31 | if [ ! -L $INSTALL_PATH/System.map ]; then
32 | if [ -e $INSTALLPATH/System.map ]; then
33 | mv $INSTALL_PATH/System.map $INSTALL_PATH/System.map.old
34 | fi
35 | fi
36 |
37 | ln -sf ${RELATIVE_PATH}$INSTALL_PATH/System.map-$KERNEL_VERSION $LINK_PATH/System.map
38 |
39 | cat $BOOTIMAGE > $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION
40 |
41 | cp $MAPFILE $INSTALL_PATH/System.map-$KERNEL_VERSION
42 |
43 | ln -fs ${RELATIVE_PATH}$INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION $LINK_PATH/$KERNEL_NAME
44 | ln -fs ${RELATIVE_PATH}$INSTALL_PATH/System.map-$KERNEL_VERSION $LINK_PATH/System.map
45 |
46 | echo "INSTALLED KERNEL: $KERNEL_NAME-$KERNEL_VERSION CONTINUING WITH MODULES"
47 |
48 | cd $1/kernel/linux-$KERNEL_VERSION/
49 |
50 | cp -r $KERNEL_VERSION /lib/modules/.
51 |
52 | echo "INSTALLED KERNEL MODULES, CONTINUING WITH INITRAMFS"
53 |
54 | cp initramfs /boot/initramfs-$KERNEL_VERSION.img
55 |
56 | if [ ! -f ./initramfs-fallback ]; then
57 | echo "NO INITRAMFS-FALLBACK FOUND, USING DEFAULT"
58 | cp initramfs /boot/initramfs-$KERNEL_VERSION-fallback.img
59 | else
60 | echo "FOUND INITRAMFS-FALLBACK, USING IT"
61 | cp initramfs-fallback /boot/initramfs-$KERNEL_VERSION-fallback.img
62 | fi
--------------------------------------------------------------------------------
/org.kernel.Linux/linux-run:
--------------------------------------------------------------------------------
1 | #!/usr/bin/bash
2 | set -x
3 | ls /app/lib/kernels
4 | ls /app/lib/kernels/linux-5-18-2
5 | #KERNEL_VERSION=5.18.2
6 | #mkdir -p ~/kernel
7 | #cp /app/bin/linux ~/kernel/linux-setup
8 | #cp -r /app/kernel/linux-$KERNEL_VERSION ~/kernel/linux-$KERNEL_VERSION
9 | #cd ~
10 | #HOME=$(pwd)
11 | #flatpak-spawn --host pkexec $HOME/kernel/linux-setup $HOME $KERNEL_VERSION
--------------------------------------------------------------------------------
/org.kernel.Linux/org.kernel.Linux.yml:
--------------------------------------------------------------------------------
1 | app-id: org.kernel.Linux
2 | runtime: org.freedesktop.Platform
3 | runtime-version: 21.08
4 | sdk: org.freedesktop.Sdk
5 | command: linux-run
6 | finish-args:
7 | - --filesystem=home
8 | - --socket=session-bus
9 | - --filesystem=/boot
10 | - --filesystem=/lib
11 |
12 | add-extensions:
13 | org.kernel.linux.variant:
14 | version: '5.18.2'
15 | directory: lib/kernels
16 | subdirectories: true
17 | no-autodownload: false
18 | autodelete: false
19 |
20 | modules:
21 | - name: linux
22 | buildsystem: simple
23 | sources:
24 | - type: archive
25 | path: ./linux.tar
26 | dest: ./kernel
27 | - type: file
28 | path: ./linux
29 | - type: file
30 | path: ./linux-run
31 | build-commands:
32 | - mkdir -p /app/lib/kernels
33 | - mkdir -p /app/kernel
34 | - install -Dm755 ./linux /app/bin/linux
35 | - install -Dm755 ./linux-run /app/bin/linux-run
36 | - cp -r ./kernel /app/kernel/linux-5.18.2
37 |
--------------------------------------------------------------------------------
/org.kernel.linux.variant/linux:
--------------------------------------------------------------------------------
1 | #!/usr/bin/bash
2 | set -x
3 |
4 | cd $1/kernel/linux-$2/x86
5 | echo $(pwd)
6 | INSTALL_PATH=/boot
7 | LINK_PATH=/boot
8 | RELATIVE_PATH=`echo "$INSTALL_PATH/" | sed "s|^$LINK_PATH/||"`
9 | KERNEL_NAME=vmlinuz
10 | KERNEL_VERSION=$2
11 | BOOTIMAGE=boot/bzImage
12 | MAPFILE=System.map
13 | ARCH=$(uname -m)
14 |
15 | if [ -f $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION ]; then
16 | mv $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION \
17 | $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION.old;
18 | fi
19 |
20 | if [ ! -L $INSTALL_PATH/$KERNEL_NAME ]; then
21 | if [ -e $INSTALLPATH/$KERNEL_NAME ]; then
22 | mv $INSTALL_PATH/$KERNEL_NAME $INSTALL_PATH/$KERNEL_NAME.old
23 | fi
24 | fi
25 |
26 | if [ -f $INSTALL_PATH/System.map-$KERNEL_VERSION ]; then
27 | mv $INSTALL_PATH/System.map-$KERNEL_VERSION \
28 | $INSTALL_PATH/System.map-$KERNEL_VERSION.old;
29 | fi
30 |
31 | if [ ! -L $INSTALL_PATH/System.map ]; then
32 | if [ -e $INSTALLPATH/System.map ]; then
33 | mv $INSTALL_PATH/System.map $INSTALL_PATH/System.map.old
34 | fi
35 | fi
36 |
37 | ln -sf ${RELATIVE_PATH}$INSTALL_PATH/System.map-$KERNEL_VERSION $LINK_PATH/System.map
38 |
39 | cat $BOOTIMAGE > $INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION
40 |
41 | cp $MAPFILE $INSTALL_PATH/System.map-$KERNEL_VERSION
42 |
43 | ln -fs ${RELATIVE_PATH}$INSTALL_PATH/$KERNEL_NAME-$KERNEL_VERSION $LINK_PATH/$KERNEL_NAME
44 | ln -fs ${RELATIVE_PATH}$INSTALL_PATH/System.map-$KERNEL_VERSION $LINK_PATH/System.map
45 |
46 | echo "INSTALLED KERNEL: $KERNEL_NAME-$KERNEL_VERSION CONTINUING WITH MODULES"
47 |
48 | cd $1/kernel/linux-$KERNEL_VERSION/
49 |
50 | cp -r $KERNEL_VERSION /lib/modules/.
51 |
52 | echo "INSTALLED KERNEL MODULES, CONTINUING WITH INITRAMFS"
53 |
54 | cp initramfs /boot/initramfs-$KERNEL_VERSION.img
55 |
56 | if [ ! -f ./initramfs-fallback ]; then
57 | echo "NO INITRAMFS-FALLBACK FOUND, USING DEFAULT"
58 | cp initramfs /boot/initramfs-$KERNEL_VERSION-fallback.img
59 | else
60 | echo "FOUND INITRAMFS-FALLBACK, USING IT"
61 | cp initramfs-fallback /boot/initramfs-$KERNEL_VERSION-fallback.img
62 | fi
--------------------------------------------------------------------------------
/org.kernel.linux.variant/org.kernel.linux.yml:
--------------------------------------------------------------------------------
1 | id: org.kernel.linux.variant.stable-5-18-2
2 | branch: '5.18.2'
3 | runtime: org.kernel.Linux
4 | sdk: org.freedesktop.Sdk//21.08
5 | build-extension: true
6 | appstream-compose: false
7 | modules:
8 | - name: kernel
9 | buildsystem: simple
10 | sources:
11 | - type: archive
12 | path: ./linux.tar
13 | dest: ./kernel
14 | - type: file
15 | path: ./linux
16 | build-commands:
17 | - ls /app/bin
18 | - ls /app/lib/kernels
19 | - install -Dm755 ./linux /app/lib/kernels/stable-5-18-2/linux
20 | # - install -Dm755 ./linux-run /app/lib/kernels/linux-5.18.2/linux-run
21 | - ls /app/lib/kernels/stable-5-18-2
22 | - cp -r ./kernel /app/lib/kernels/stable-5-18-2/kernel
--------------------------------------------------------------------------------