You can have many installed kernels at once, and use `kernelstub` to configure which are available for booting.
## To install kernels or validate installed kernels
By default Pop!\_OS updates to the latest Pop!\_OS-approved kernel, and retains one prior kernel. To see what kernels you have installed:
```bash
apt list --installed | grep -i "linux-image"
```
At the moment, I get:
```bash
linux-image-5.13.0-7620-generic/now 5.13.0-7620.20~1634827117~21.04~874b071 amd64 [installed,local]
linux-image-5.15.5-76051505-generic/now 5.15.5-76051505.202111250933~1638201579~21.10~09f1aa7 amd64 [installed,local]
linux-image-5.15.8-76051508-generic/impish,now 5.15.8-76051508.202112141040~1639505278~21.10~0ede46a amd64 [installed,automatic]
linux-image-generic/impish,now 5.15.8.76051508.202112141040~1639505278~21.10~0ede46a amd64 [installed,automatic]
```
So I have kernels 5.13.0 build 7620, 5.15.5 build 7605150, and 5.15.8 build 76051508 installed. The last package, `linux-image-generic`, is a meta-package that has no real files but depends on the currently-latest version, according to the System76 Pop!\_OS maintainers; for me right now, that's 5.15.8-76051508. (I used the standard Pop!\_OS install on a 64-bit machine so I have the "generic" Linux kernel flavor -- it's highly likely you do too.)
You can install xanmod/other kernel packages as they normally instruct (I assume by either installing a .deb directly, or adding a specific apt repository for your kernel of choice). You might be able to install other available kernels through `apt` as well, or as I like to use when I'm troubleshooting, the `synaptic` GUI tool (shows versions, dependencies, provided files, etc.) In synaptic, you can search `linux-image generic` to show available generic kernels (`apt search` is a bit more finicky but can show you a less precise list with `apt search linux-image-5.`).
Make sure you have the package installed for the kernel you want, and the kernel should show up in the `/boot` directory as a `vmlinuz` file. This is the staging area for kernels that can be made bootable, but is not the actual location of the boot kernels. For me the kernels in `/boot` look like:
`$ ls -alh /boot/vmlinuz*`
`lrwxrwxrwx 1 root root 31 Dec 21 22:47 /boot/vmlinuz -> vmlinuz-5.15.8-76051508-generic`
`-rw------- 1 root root 9.9M Oct 21 10:38 /boot/vmlinuz-5.13.0-7620-generic`
`-rw------- 1 root root 9.9M Nov 29 10:59 /boot/vmlinuz-5.15.5-76051505-generic`
`-rw------- 1 root root 11M Dec 14 13:07 /boot/vmlinuz-5.15.8-76051508-generic`
`lrwxrwxrwx 1 root root 31 Dec 21 22:47 /boot/vmlinuz.old -> vmlinuz-5.15.5-76051505-generic`
Ignoring the `vmlinuz` and `vmlinuz.old` symlinks, that shows the three kernels I have installed. Note that these packages actually come from a Pop!\_OS repository, not directly from an Ubuntu repository. Now, I don't want the 5.13 kernel to accidentally get removed (e.g. as part of a normal kernel-package update) so I do the following to prevent removal:
`$ sudo apt-mark hold linux-image-5.13.0-7620-generic`
That will keep my preferred kernel available. Next I want to configure which kernels show up as available to boot from.
## Configure kernelstub to allow booting from additional kernels
By default in Pop!\_OS, kernelstub only shows the current kernel and one revision back -- regardless of how many kernels you have installed. I used this guide to make kernelstub aware of my 5.13 kernel:
[https://www.reddit.com/r/pop_os/comments/guej8v/tutorial_switchchangeswap_kernels/](https://www.reddit.com/r/pop_os/comments/guej8v/tutorial_switchchangeswap_kernels/)
Basically it boils down to:
- Create initrd for all kernels:
- `sudo update-initramfs -u -k all`
- Copy the desired kernel's `vmlinuz` file and `initrd.img` file from `/boot` staging area into the appropriate subfolder of `/boot/efi`
- Go to `/boot/efi/EFI/`. (Note you need to be root to even see inside `/boot/efi/`. I use `sudo -i` to open a root shell so I can navigate around.) In there is a folder named `Pop_OS-<hash-value>` where the hash-value is unique to your system (likely your disk's UUID).
- There is a small chance your EFI directory is at a different location. You can use `findmnt --real` to confirm where your EFI is located; it'll likely be the only partition with the `vfat` fstype and 500MB to 2GB in size.
- You should see `initrd.img`, `initrd.img-previous`, `vmlinuz.efi`, and `vmlinuz-previous.efi`.
- Copy your desired kernel's `vmlinuz` file and `initrd.img` file from /boot into this `Pop_OS-<hash-value>` folder as new files (use the kernel version so you don't overwrite the generically-named `initrd.img`, `initrd.img-previous`, `vmlinuz.efi`, and `vmlinuz-previous.efi`). My two new files are called `vmlinuz-5.13.0-7620-generic` and `initrd.img-5.13.0-7620-generic`.
- Use `ls -l`, `chmod`, and `chown` to ensure the new files have the same ownership and permissions as the generically-named files
- Create kernelstub entry for your desired kernel and its initial ramdisk
- Go to `/boot/efi/loader/entries/` (note you must be root to even see inside `/boot/efi`). You should see `Pop_OS-current.conf` and `Pop_OS-oldkern.conf` in that directory.
- Copy `Pop_OS-oldkern.conf` to a new file named for your desired kernel. For me that was `Pop_OS-kern-5-13.conf`, so now I have all three of those conf files in that `entries` directory.
- Modify your new conf file to point to your desired kernel. I did the `title`, `linux`, and `initrd` parameters, and left `options` alone. My new conf file looks like this (with `<hash-value>` being my disk UUID):
- `title Pop!_OS_5.13`
`linux /EFI/Pop_OS-<hash-value>/vmlinuz-5.13.0-7620-generic`
`initrd /EFI/Pop_OS-<hash-value>/initrd.img-5.13.0-7620-generic`
`options root=UUID=<hash-value> ro quiet loglevel=0 systemd.show_status=false splash`
- **OPTIONAL** Add a boot delay so that you can select your kernel without spamming the spacebar at boot time.
- As root, edit `/boot/efi/loader/loader.conf`
- Add a line with the timeout seconds parameter, e.g. for a 2-second delay: `timeout 2`
- My `loader.conf` file now looks like:
- `# cat loader.conf`
`default Pop_OS-current`
`timeout 2`
Reboot, select your preferred kernel, and you should be good to go!
## Sources
[What is the easiest way to swap installed kernel on POP\_OS!? : r/pop\_os](https://www.reddit.com/r/pop_os/comments/r07x4t/what_is_the_easiest_way_to_swap_installed_kernel/)