View previous topic :: View next topic |
Author |
Message |
raddaqii Tux's lil' helper
Joined: 27 Mar 2005 Posts: 110 Location: Berlin, Old Europe
|
Posted: Sat Jul 23, 2016 8:24 am Post subject: Best way to update kernel? |
|
|
Just to get things in order.. to upgrade the kernel I usually do the following on my home machine:
* emerge whatever new version comes with a portage sync, e.g. emerge =sys-kernel/gentoo-sources-4.6.2
* eselect kernel list
* eselect kernel set <number of new version>
* cd /usr/src/linux && cp ../linux-<previous-version>/.config .oldconfig
* make oldconfig <- keep enter pressed to answer all questions with the default if no hardware has changed
* make menuconfig <- optional, if I need features I hadn't enabled before
* make && make modules_prepare && make modules && make modules_install && make install <- this I keep in a bash-oneliner in /usr/local/bin/make-oneliner
* copy and update given line like modules_4_4_1_gentoo="vboxdrv vboxnetflt vboxnetadp vboxvideo" in etc/conf.d/modules
* grub2-mkconfig <- now this command fails as in "runs, but does not generate a grub2 entry for the most recent kernel", I so manually enter stuff into /boot/grub/grub.conf
* from time to time (usually when /boot runs full) I do eclean-kernel -n 4 or somesuch
* reboot
Now that seems inefficient, and it might be about time I update that process I've been following the last decade or so.
What are your suggestions? Since there hardly is a canonical way, how do you upgrade your kernel? _________________ --
Gentoo from 2004.3
Oh, took a new home in the fediverse: find me in the stream on pluspora.com: https://pluspora.com/tags/gentoo |
|
Back to top |
|
|
raddaqii Tux's lil' helper
Joined: 27 Mar 2005 Posts: 110 Location: Berlin, Old Europe
|
Posted: Sat Jul 23, 2016 8:37 am Post subject: |
|
|
So I just found a range of useful options in /usr/src/linux/'s make help:
Quote: |
...
Configuration targets:
config - Update current config utilising a line-oriented program
nconfig - Update current config utilising a ncurses menu based
program
menuconfig - Update current config utilising a menu based program
...
oldconfig - Update current config utilising a provided .config as base
localmodconfig - Update current config disabling modules not loaded
localyesconfig - Update current config converting local mods to core
silentoldconfig - Same as oldconfig, but quietly, additionally update deps
defconfig - New config with default from ARCH supplied defconfig
savedefconfig - Save current config as ./defconfig (minimal config)
allnoconfig - New config where all options are answered with no
allyesconfig - New config where all options are accepted with yes
allmodconfig - New config selecting modules when possible
alldefconfig - New config with all symbols set to default
randconfig - New config with random answer to all options
listnewconfig - List new options
olddefconfig - Same as silentoldconfig but sets new symbols to their
default value
kvmconfig - Enable additional options for kvm guest kernel support
xenconfig - Enable additional options for xen dom0 and guest kernel support
tinyconfig - Configure the tiniest possible kernel
...
|
So it seems for my one-liner there is a minor upgrade in order to save some manual steps. Also these stackoverflow thread here and here have nice answers. _________________ --
Gentoo from 2004.3
Oh, took a new home in the fediverse: find me in the stream on pluspora.com: https://pluspora.com/tags/gentoo |
|
Back to top |
|
|
The Doctor Moderator
Joined: 27 Jul 2010 Posts: 2678
|
Posted: Sat Jul 23, 2016 8:38 am Post subject: |
|
|
The only real problem I see is accepting all the defaults. 99% of those are just adding worthless bloat since most new hardware options will default to "Yes" which is clearly not what you want and most of the other new stuff is similarly useless. _________________ First things first, but not necessarily in that order.
Apologies if I take a while to respond. I'm currently working on the dematerialization circuit for my blue box. |
|
Back to top |
|
|
Cyker Veteran
Joined: 15 Jun 2006 Posts: 1746
|
Posted: Sat Jul 23, 2016 10:38 am Post subject: |
|
|
Mine is vaguely something like
emerge new kernel
make mrproper
copy /usr/src/linux/.config /usr/src/<newkernel>
eselect kernel <newkernel>
make oldconfig
make menuconfig
mount /boot
make
make firmware_install
make modules_install
make install
grub2-mkconfig > /boot/grub/grub.cfg
umount /boot |
|
Back to top |
|
|
jonathan183 Guru
Joined: 13 Dec 2011 Posts: 318
|
Posted: Sat Jul 23, 2016 2:30 pm Post subject: Re: Best way to update kernel? |
|
|
raddaqii wrote: | What are your suggestions? Since there hardly is a canonical way, how do you upgrade your kernel? |
I don't know the best way ... this works for me ...
Create a user who can build and install the kernel only, setup sudo so the user is able to change ownership and install modules etc. Script I use for building the kernel below for a desktop PC which does not require initramfs:
Code: | ### Script to compile kernel - with the sequence
### ============================================
### check linux symlink information using eselect output
### change ownwership to kernel_builder_user (to allow regular user kernel compile)
### if new option used then
### run make mrproper to clear kernel compile information
### copy .config from previous kernels (stored in /usr/src/)
### then for new or recompile options continue with
### run make oldconfig prompts for new features settings
### run make menuconfig or make nconfig to configure kernel
### run make and make modules to compile kernel and modules
### run make modules_install to install modules
### copy kernel to become new kernel-current
### re-emerge xf86-input-evdev to ensure X mouse and keyboard input work
### Script requires:- kernel_builder user with entries to allow sudo of chown, make modules_install,
### and emerge. It also requires an existing /usr/src/.config and /boot/kernel-current
### owned by the kernel_build_user.
### sudoers entries can be specific for chown,make, and emerge to just combinations
### used in the script ... no need for chown any_thing_you_want ;-)
### definitions needed for script kernel_builder_user
kernel_builder_user=kernel_builder
### use ./kernel-compile.sh new to run mrproper and copy .config
### use ./kernel-compile.sh recompile to skip mrproper and copy .config steps
### use ./kernel-compile.sh with no option for help
if [ "$1" = "" ] || [ "$1" = "help" ] || [ "$1" = "h" ]
then
# hit Enter too early or forgot to add option
echo Script file $0 help information
echo '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
echo
echo This script allows compile of kernel by user $kernel_builder_user
echo
echo use $0 new ' when compiling a fresh kernel (which uses mrproper and copies an existing .config from /usr/src/)'
echo use $0 ' to display this help'
echo use $0 recompile ' to recompile kernel (skipping mrproper and copying .config from /usr/src/ steps)'
echo
elif [ "$1" = "new" ] || [ "$1" = "recompile" ]
then
# do for compile cases
echo The script allows compile of kernel by user $kernel_builder_user
echo '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
echo Check config file and kernel-current exist and are owned by $kernel_builder_user
echo
ls /usr/src/.config /boot/kernel-current -l
### check linux symlink
echo
eselect kernel list
echo
echo 'Also check output of eselect is correct for symlink - Press Enter to continue OR Ctrl-c to abandon'
read
echo 'Changing to kernel source folder ...'
cd /usr/src/linux
if [ "$1" = "new" ]
then
### clear source tree and chown to user kernel_builder_user
echo
echo 'Next clear old kernel compile info (erases .config in linux source directory) - Press Enter to continue OR Ctrl-c to abandon'
read
sudo chown $kernel_builder_user /usr/src/linux/* -R
sudo chown $kernel_builder_user /usr/src/linux
echo
echo Running make mrproper ...
make mrproper
# for debug of mrproper use ... make mrproper -d >> debug-info-mrproper
### copy config from /usr/src
echo
echo 'Copying kernel config to source folder from previous kernels ...'
sudo cp -p /usr/src/.config /usr/src/linux/
fi
### configure the kernel
echo 'Configure the kernel - running oldconfig and then menuconfig or nconfig'
echo
echo 'Running make oldconfig ...'
make silentoldconfig
echo
echo 'Running make menuconfig or make nconfig...'
# use either make menuconfig or make nconfig on the next line
make nconfig
# for debug of menuconfig use ... make menuconfig -d >> debug-info-menuconfig
# could probably use | tee have not played with this much. But could use
# tail -f /usr/src/linux/debug-info-menuconfig to check output in another console.
# for nconfig use ... make nconfig
# for gconfig (need to run in X) use ... make gconfig
# for xconfig (need to run in X) use ... make xconfig
### check ready to compile the kernel and modules
echo 'Next compile the kernel and modules (overwrites previous image in linux source directory) - Press Enter to continue OR Ctrl-c to abandon'
read
# dont think this step is needed ... sudo chown $kernel_builder_user /usr/src/linux/* -R
# compile the kernel and modules
echo 'Running make and make modules ...'
# make && make modules
make 1> kernel_compile_messages.txt 2> kernel_compile_error_messages.txt && make modules 1>> kernel_compile_messages.txt 2>> kernel_compile_error_messages.txt
### check if ready then compile the kernel and copy it to kernel-current
echo 'Next install kernel modules and copy latest image to /boot/kernel-current - Press Enter OR Ctrl-c to abandon'
read
echo
echo 'Install kernel modules ...'
sudo make modules_install 1>> kernel_compile_messages.txt 2>> kernel_compile_error_messages.txt
echo
echo 'Copy kernel image to kernel-current ...'
cp arch/x86_64/boot/bzImage /boot/kernel-current
### check kernel image date is correct
echo
echo 'Check kernel image file date is correct - should have todays data and be a reasonable size file'
ls /boot -l
### if using nvidia drivers re-emerge them
#echo Next re-emerge nvidia drivers - Press Enter to continue OR Ctrl-c to abandon
#read
#sudo emerge -av nvidia-drivers
#echo
#echo 'Re-emerging xf86-input-evdev to make sure X mouse and keyboard inputs work correctly ...'
#sudo emerge -av xf86-input-evdev
fi
### end of kernel compile script |
Ed: On a laptop with encrypted root (no separate boot) and secureboot enabled I use a separate script to create the initramfs using genkernel and a separate script to sign the kernel with my key. I manually copy a working kernel to provide a backup copy in case the newly built kernel does not boot. |
|
Back to top |
|
|
Hu Moderator
Joined: 06 Mar 2007 Posts: 21593
|
Posted: Sat Jul 23, 2016 4:07 pm Post subject: |
|
|
I like make oldnoconfig instead of make oldconfig. It automatically answers No to every new question, while reusing answers to any questions that match the existing configuration. It saves me from holding down enter. As The Doctor hints, most new choices should be answered No unless you know you need them.
[Edit: as pointed out below, make oldnoconfig is documented to work differently from how I thought it did based on its name. I take comfort in knowing that many other people trusted that it did what its name said it did.]
Last edited by Hu on Sat Jul 23, 2016 9:54 pm; edited 1 time in total |
|
Back to top |
|
|
jonathan183 Guru
Joined: 13 Dec 2011 Posts: 318
|
Posted: Sat Jul 23, 2016 8:18 pm Post subject: |
|
|
Hu wrote: | I like make oldnoconfig instead of make oldconfig. It automatically answers No to every new question, while reusing answers to any questions that match the existing configuration. It saves me from holding down enter. As The Doctor hints, most new choices should be answered No unless you know you need them. |
I had not even spotted oldnoconfig in the README file ... I think for the moment I'll stick with silentoldconfig but good to know the option exists
Ed: it looks as though it produces the same output as olddefconfig ... which matches comments which appear when I tried running Code: | grep -r oldnoconfig /usr/src/linux | |
|
Back to top |
|
|
Ant P. Watchman
Joined: 18 Apr 2009 Posts: 6920
|
Posted: Sun Jul 24, 2016 5:14 am Post subject: Re: Best way to update kernel? |
|
|
raddaqii wrote: | What are your suggestions? Since there hardly is a canonical way, how do you upgrade your kernel? |
Using a manual git clone and lilo:
Code: | cd /usr/src/linux
git pull --ff-only
make oldconfig #usually answer no and go back with make nconfig if I see anything interesting
make -j$(nproc)
su -c 'make modules_install install' |
|
|
Back to top |
|
|
raddaqii Tux's lil' helper
Joined: 27 Mar 2005 Posts: 110 Location: Berlin, Old Europe
|
Posted: Mon Jul 25, 2016 4:03 pm Post subject: |
|
|
A fine plethora of how to do it! :D
Apparently jonathan183 figured it out, oldnoconfig produces the same output as olddefconfig.
Code: |
# make oldnoconfig
scripts/kconfig/conf --olddefconfig Kconfig
#
# configuration written to .config
#
|
And skipping quite a few versions on this laptop that does produce a kernel that won't even boot, I get a stacktrace instead -_- - needs more investigation really, and manual intervention. _________________ --
Gentoo from 2004.3
Oh, took a new home in the fediverse: find me in the stream on pluspora.com: https://pluspora.com/tags/gentoo |
|
Back to top |
|
|
sheep204 n00b
Joined: 28 Dec 2005 Posts: 31
|
|
Back to top |
|
|
mv Watchman
Joined: 20 Apr 2005 Posts: 6747
|
Posted: Tue Aug 23, 2016 8:28 am Post subject: |
|
|
If you have a separate KBUILD_OUTPUT (which I recommend anyway for security reasons: You don't want to compile your kernel with root permissions ) and you don't change it between kernels, there is no need to copy any .config. You can then also use the sys-kernel/kernel script from the mv overlay. It does not deal with initrds yet, since there was no need for it so far.
In order to check for changes in the configuration, usually I save the new configuration after "make nconfig" and then use kccmp. After this, I read what some new options mean (and perhaps check why some options have changed "automagically"); quite often, I deactivate some of the new which have a "yes"/"modules", though not always... |
|
Back to top |
|
|
Tony0945 Watchman
Joined: 25 Jul 2006 Posts: 5127 Location: Illinois, USA
|
Posted: Tue Aug 23, 2016 1:31 pm Post subject: |
|
|
Code: | #!
cd /usr/src/linux
zcat /proc/config.gz >.config
# At this point we should compare kernel versions and make oldconfig if the base version has updated
make oldconfig
make menuconfig && make -j7 && make -j7 modules_install && make -j7 install && echo "Don't forget to update boot loader menu"
|
Adjust -j7 as required. Requires the config stored in kernel options, CONFIG_IKCONFIG=y and CONFIG_IKCONFIG_PROC=y
This avoids wondering where you placed the config for the current running kernel. |
|
Back to top |
|
|
raddaqii Tux's lil' helper
Joined: 27 Mar 2005 Posts: 110 Location: Berlin, Old Europe
|
Posted: Mon Sep 05, 2016 10:04 am Post subject: |
|
|
+1 for not having to wonder where you placed that last kernel's .config, and +1 for the built-in reminder to update that boot config. _________________ --
Gentoo from 2004.3
Oh, took a new home in the fediverse: find me in the stream on pluspora.com: https://pluspora.com/tags/gentoo |
|
Back to top |
|
|
proteusx Guru
Joined: 21 Jan 2008 Posts: 338
|
Posted: Mon Sep 05, 2016 10:11 pm Post subject: |
|
|
This is how I update my kernel for many years.
Code: | eselect kernel <whatever>
cd /usr/src/linux
zcat /proc/config.gz > .config && make oldconfig && make && make modules_install && emerge @module-rebuild |
And I am good to go.
Notes:
- "make oldconfig" will ask me if the new kernel has any features not present in the old kernel.
- I use grub legacy. No need to update the loader.
- bzImage and System.map are symlinked to /boot/ so I do not have to copy anything.
Code: |
ll /boot
lrwxrwxrwx 1 root 1 Nov 1 2015 boot -> ./
lrwxrwxrwx 1 root 36 Nov 1 2015 bzImage -> /usr/src/linux/arch/x86/boot/bzImage
drwxr-xr-x 2 root 4.0K Aug 21 11:50 grub/
lrwxrwxrwx 1 root 25 Feb 8 2016 System.map -> /usr/src/linux/System.map
|
My grub.conf
Code: | default 0
timeout 10
title=Gentoo x64
root (hd0,0)
kernel /boot/bzImage root=/dev/sda1 ro nouveau.modeset=1 |
|
|
Back to top |
|
|
Syl20 l33t
Joined: 04 Aug 2005 Posts: 619 Location: France
|
Posted: Tue Sep 06, 2016 9:45 am Post subject: |
|
|
You can add "make install", to avoid setting symlinks to /usr/src (if /boot and/or /usr are on distinct FS, your method doesn't work).
If you added some symlinks to the current kernel, they are updated, so you don't need to modify your grub config :
Code: | # ll /boot
total 27M
drwxr-xr-x 3 root root 4,0K 18 mai 21:07 .
drwxr-xr-x 21 root root 4,0K 12 avril 14:43 ..
-rw-r--r-- 1 root root 0 16 août 08:40 .keep
lrwxrwxrwx 1 root root 32 18 mai 21:07 System.map -> System.map-4.4.8-hardened-r1-gnu
lrwxrwxrwx 1 root root 29 7 avril 19:49 System.map.old -> System.map-4.4.2-hardened-gnu
-rw------- 1 root root 2,2M 7 avril 19:49 System.map-4.4.2-hardened-gnu
-rw------- 1 root root 2,2M 7 avril 19:44 System.map-4.4.2-hardened-gnu.old
-rw------- 1 root root 2,2M 18 mai 21:07 System.map-4.4.8-hardened-r1-gnu
-rw------- 1 root root 72K 7 avril 19:49 config-4.4.2-hardened-gnu
-rw------- 1 root root 72K 7 avril 19:44 config-4.4.2-hardened-gnu.old
-rw------- 1 root root 72K 18 mai 21:07 config-4.4.8-hardened-r1-gnu
drwxr-xr-x 6 root root 4,0K 7 avril 19:48 grub
drwxr-xr-x 6 root root 4,0K 4 avril 20:32 memtest86plus
lrwxrwxrwx 1 root root 29 18 mai 21:07 vmlinuz -> vmlinuz-4.4.8-hardened-r1-gnu
lrwxrwxrwx 1 root root 26 7 avril 19:49 vmlinuz.old -> vmlinuz-4.4.2-hardened-gnu
-rw------- 1 root root 4,5M 7 avril 19:49 vmlinuz-4.4.2-hardened-gnu
-rw------- 1 root root 4,5M 7 avril 19:44 vmlinuz-4.4.2-hardened-gnu.old
-rw------- 1 root root 4,6M 18 mai 21:07 vmlinuz-4.4.8-hardened-r1-gnu
# cat /boot/grub/grub.cfg
(snip)
menuentry 'Gentoo' {
echo 'Chargement de vmlinuz...'
linux /boot/vmlinuz root=/dev/sda5 ro
}
menuentry 'Gentoo single' {
echo 'Chargement de vmlinuz...'
linux /boot/vmlinuz root=/dev/sda5 ro single
}
menuentry 'Gentoo version precedente' {
echo 'Chargement de vmlinuz.old...'
linux /boot/vmlinuz.old root=/dev/sda5 ro
}
menuentry "Memtest86+" {
linux16 /boot/memtest86plus/memtest
} |
|
|
Back to top |
|
|
proteusx Guru
Joined: 21 Jan 2008 Posts: 338
|
Posted: Tue Sep 06, 2016 11:54 am Post subject: |
|
|
Syl20 wrote: | You can add "make install", to avoid setting symlinks to /usr/src (if /boot and/or /usr are on distinct FS, your method doesn't work). |
I never trusted kernel's "make install"; I cannot remember why.
Never said my method would work in every situation.
In my setup always have one root partition and /home is usually a different drive.
Syl20 wrote: | If you added some symlinks to the current kernel, they are updated, so you don't need to modify your grub config :
| I do not need to modify grub.conf either. The symlink to bzImage follows the /usr/src/linux symlink as set by eselect.
I cannot stand grub2. Too bloody complicated. Though I know you can make it behave like grub1 as you have done.
EDIT. Typos |
|
Back to top |
|
|
Roman_Gruber Advocate
Joined: 03 Oct 2006 Posts: 3846 Location: Austro Bavaria
|
Posted: Tue Sep 06, 2016 3:01 pm Post subject: |
|
|
well to speed up things, written down without verificatin, please check manpage of man
Code: | make --jobs 8 && make --jobs 8 modules_install |
regarding grub2. these auto mass destruction scripts make grub2 complicated. I moderately removed a lot of lint from linux mint grub2 installation here, which I use since a year without updating grub2. Too lazy to check if every premade line is really that needed. I saw others here who reduced it down to a very small config file
Quote: | I use grub legacy. No need to update the loader. |
Same for grub2. Except the part which is the title and the name of the kernel itself, so I can distinguish it. Thats not really needed when you are lazy and would replace the file always, which I do not recommend.
when I swap drives / or just the uefi bios has an error, I have to reinstall grub2 because uefi forgets everything, tahts a design flaw. So that implies you may be on a box with mbr, lucky you. |
|
Back to top |
|
|
raddaqii Tux's lil' helper
Joined: 27 Mar 2005 Posts: 110 Location: Berlin, Old Europe
|
Posted: Wed May 09, 2018 10:15 am Post subject: |
|
|
FWIW, while still having machines around where I handle kernel configs explicitly, on recent builds I feel I have levelled up following Sakakis EFI Install Guide and grown to like having parts of all this managed by tools like genup, buildkernel. It is considerable less hassle, and I get to call buildkernel --menuconfig if I need to. _________________ --
Gentoo from 2004.3
Oh, took a new home in the fediverse: find me in the stream on pluspora.com: https://pluspora.com/tags/gentoo |
|
Back to top |
|
|
ericbish n00b
Joined: 27 Apr 2018 Posts: 29
|
Posted: Wed May 09, 2018 6:55 pm Post subject: |
|
|
Well, if you are looking for "easiest", it's pretty hard to beat:
cd /etc/kernels
cp <current-kernel-config> <new-kernel-config>
cd /usr/src/
rm linux && ln -s <new-kernel> linux (this can also be automated if you so choose)
genkernel all (or if you use lvm: genkernel --lvm all, or if you want to edit the kernel config add a --menuconfig, or xconfig, or whatever you like here as well, lots of options for this line)
grub-mkconfig -o /boot/grub/grub.cfg (for most systems, if you use efi or something, hit the grub wiki)
lots of other ways to do it, but the above is pretty easy
Every once in a blue moon, you might have an issue with something not correctly supported between kernel configs, or need to modify due to new options......but I'll say that updating to new kernels by copying my old /etc/kernels config to the new kernel has worked without issue for many many years. |
|
Back to top |
|
|
The Main Man Veteran
Joined: 27 Nov 2014 Posts: 1165 Location: /run/user/1000
|
Posted: Wed May 09, 2018 11:32 pm Post subject: |
|
|
I'm using 'make olddefconfig' , always figured that it can't be just new hardware that's new in that new kernel (options wise), there are probably some other options in there and if it was intended for some option to be set then that 'olddefconfig' would do that, yeah new hardware would also be added but I can go through that once in a while and deselect those. I never went through looking at all new items and answering Y or N to each, so I'm not sure if the bulk of it is just new hardware. |
|
Back to top |
|
|
|