Kernel/Aggiornamento

From Gentoo Wiki
< Kernel
Jump to:navigation Jump to:search
This page is a translated version of the page Kernel/Upgrade and the translation is 27% complete.
Outdated translations are marked like this.

Questo articolo descrive la procedura per l'aggiornamento ad una nuova versione del kernel Linux.

La generazione di un nuovo kernel dalla nuova sorgente è lo stesso processo di creazione di un kernel durante l'installazione del sistema. La differenza è che si potrebbe usare la configurazione del vecchio kernel per creare la configurazione del nuovo kernel. L'uso della vecchia configurazione permette l'utente di evitare di esplorare tutte le opzioni del kernel nuovamente (come make menuconfig)

La configurazione del kernel è salvata in un file nominato .config nella directory che contiene il kernel stesso. Un nuovo kernel potrebbe aver avuto opzioni o funzionalità aggiunte o rimosse dal vecchio kernel. La configurazione del kernel specifica se una funzionalità del kernel debba essere attivata o meno, forse integrato nel kernel, o forse costruito come moduli che possono essere caricati nel kernel in esecuzione su richiesta. Quindi il file di configurazione di un nuovo kernel potrebbe avere nuove voci di configurazioni non presenti nel vecchio kernel, e potrebbe non avere alcune voci presenti invece nel file di configurazione del vecchio kernel.

Per far fronte a tali cambiamenti del file di configurazione, il file di configurazione del vecchio kernel deve essere convertito in una configurazione utilizzabile con il nuovo. Questo articolo mostra come creare un nuovo kernel dalla nuova sorgente del kernel con la conversione del file di configurazione provenienti dal vecchio kernel.

Kernel upgrade in Gentoo involves these steps:

  1. Install the new kernel sources.
  2. Setting the symlink to the (newly installed) kernel sources.
  3. Moving to the new kernel's folder.
  4. Adjusting the .config file for the options introduced to, or removed from, the new kernel's configuration.
  5. Compiling the kernel and the initramfs.
  6. Updating the bootloader.
  7. Removing or keeping the old kernel.
Importante
It is wise to make a backup of the kernel configuration so that the previous configurations are not lost. Many users devote considerable time to figure out the best configuration for the system, and losing that information is definitely not wanted. One of the ways introduced in Copy the previous kernel configuration of this article can be used for making a backup of the configuration file.

L'aggiornamento del kernel potrebbe essere una buona idea quando delle nuove sorgenti sono state rilasciate. Le nuove sorgenti del kernel sono a volte installati durante l'aggiornamento del sistema tramite il seguente comando

root #emerge --ask --update --deep --with-bdeps=y --newuse @world

Ovviamente le sorgenti del kernel possono essere installate direttamente usando il seguente comando (si sostituisca "gentoo-sources" con qualunque versione del kernel che è in uso):

root #emerge --ask --update --deep --with-bdeps=y --newuse sys-kernel/gentoo-sources

L'installazione di nuove sorgenti del kernel non fornisce all'utente un nuovo kernel. E' necessario produrre ed installare un nuovo kernel dalla nuova sorgente e quindi riavviare il sistema per eseguire effettivamente il nuovo kernel.

Configurazione

The kernel configuration is saved in a file named .config in the directory that holds the kernel sources, a symlink is used to point to that directory.

Il link simbolico/usr/src/linux dovrebbe sempre puntare alla directory contenente la sorgente del kernel attualmente in esecuzione. Questo può essere fatto in uno dei tre dei seguenti modi:

  1. Installare la sorgente del kernel con USE="symlink"
  2. Impostare il link con eselect
  3. Aggiornare manualmente il link simbolico

Configurazione del link con eselect

Per impostare il link simbolico con eselect:

root #eselect kernel list
Available kernel symlink targets:
 [1] linux-3.14.14-gentoo *
 [2] linux-3.16.3-gentoo

Questo comando genera la lista dei kernel disponibili. L'asterisco indica quale sia la directory della sorgente selezionata.

Per cambiare la sorgente del kernel, per esempio alla seconda voce:

root #eselect kernel set 2

Aggiornamento manuale del link simbolico

Per impostare il link simbolico manualmente:

root #ln -sf /usr/src/linux-3.16.3-gentoo /usr/src/linux
root #ls -l /usr/src/linux
lrwxrwxrwx 1 root root 19 Oct  4 10:21 /usr/src/linux -> linux-3.16.3-gentoo

Installare la sorgente del kernel con la USE flag "symlink"

Questo implicherà che /usr/src/linux punti alla directory della sorgente del nuovo kernel.

Se necessario, il link può essere comunque modificato successivamente con uno degli altri due metodi.

Spostarsi nella nuova cartella

Ora che il link simbolico è stato modificato, cambia la directory di lavoro nella nuova cartella del kernel.

root #cd /usr/src/linux
Nota
Questo comando è ancora necessario anche se la directory di lavoro era già /usr/src/linux quando il collegamento simbolico è stato modificato. Fino a quando il nuovo collegamento simbolico non verrà effettivamente seguito, la console sarà ancora nella directory del vecchio kernel.

Adjusting the .config file for the new kernel

Copy the previous kernel configuration

La configurazione del precedente kernel necessita di essere copiata nella cartella della sorgente del nuovo kernel. Oltre alla copia di backup che è stata salvata in /root in un passaggio precedente, la vecchia configurazione può essere trovata in diversi punti:

  • Nel filesystem procfs, se l'opzione Enable access to .config through /proc/config.gz(CONFIG_IKCONFIG_PROC) è stata attivata nel kernel attualmente in esecuzione:
root #zcat /proc/config.gz > /usr/src/linux/.config
root #zcat /proc/config.gz > /usr/src/linux/.config
  • Dal vecchio kernel. Questo funziona solo quando il vecchio kernel è stato compilato con CONFIG_IKCONFIG:
root #/usr/src/linux/scripts/extract-ikconfig /path/to/old/kernel >/usr/src/linux/.config
root #/usr/src/linux/scripts/extract-ikconfig /path/to/old/kernel >/usr/src/linux/.config
  • Nella directory /boot, se la configurazione è stata precedentemente installata in questa posizione:
root #cp /boot/config-3.14.14-gentoo /usr/src/linux/.config
root #cp /boot/config-3.14.14-gentoo /usr/src/linux/.config
  • Nella directory del kernel attualmente in esecuzione:
root #cp /usr/src/linux-3.14.14-gentoo/.config /usr/src/linux/
root #cp /usr/src/linux-3.14.14-gentoo/.config /usr/src/linux/
  • Nella directory /etc/kernels/, se l'opzione SAVE_CONFIG="yes" è impostata nel file /etc/genkernel.conf e genkernel è stato utilizzato in precedenza:
root #cp /etc/kernels/kernel-config-x86_64-3.14.14-gentoo /usr/src/linux/.config
root #cp /etc/kernels/kernel-config-x86_64-3.14.14-gentoo /usr/src/linux/.config

file.config

Nota
Invoking make oldconfig and make menuconfig can be done automatically via genkernel in the build process by enabling the OLDCONFIG and MENUCONFIG parameters in /etc/genkernel.conf. If OLDCONFIG is enabled in genkernel's configuration or if it's going to be enabled by passing --oldconfig option to genkernel command, jump to the build section in this article.

Per usare la configurazione di un vecchio kernel con uno nuovo, è necessario che questa sia prima convertita. La conversione può essere effettuata eseguendo make silentoldconfig oppure, in alternativa, make olddefconfig.

make silentoldconfig

Importante
make silentoldconfig è stato rimosso a partire dalla versione 4.19 di Linux, e verrà sostituito da make syncconfig.

La seguente configurazione è come la configurazione basata su testo con make config. Per le nuove opzioni di configurazione, viene richiesta una decisione all'utente. Per esempio:

root #cd /usr/src/linux
root #make silentoldconfig
Anticipatory I/O scheduler (IOSCHED_AS) [Y/n/m/?] (NEW)

La stringa "(NEW)"" alla fine della linea sottolinea che questa opzione è nuova. Nelle parentesi quadre a sinistra della stringa ci sono le possibili risposte Yes (Sì), no (o), module (modulo) oppure ? per visualizzare l'aiuto. La risposta raccomandata (default) è in maiuscolo (in questo caso Y). L'aiuto riporta spiegazioni sull'opzione o sul driver.

Sfortunatamente make silentoldconfig non mostra molte informazioni per ogni opzione, come il contesto, e qualche volta è difficoltoso dare la giusta risposta. In questo caso, la migliore strada è ricordare il nome dell'opzione e ricontrollarla successivamente tramite uno dei strumenti grafici di configurazione del kernel.

make olddefconfig

Se tutte le nuovi opzioni di configurazioni possono essere impostate con il loro valore raccomandato (default) allora è possibile usare make olddefconfig:

root #cd /usr/src/linux
root #make olddefconfig

make help

E' possibile usare make help per vedere gli altri metodi di conversione:

root #make help

Observing the difference

A diff tool can be used to compare the old and new .config files to see what options have been added:

user $diff <(sort .config) <(sort .config.old) | awk '/^<.*(=|Linux)/ { $1=""; print }'
CONFIG_64BIT_TIME=y
CONFIG_AMD_NB=y
CONFIG_ARCH_CLOCKSOURCE_INIT=y
CONFIG_ARCH_HAS_GIGANTIC_PAGE=y
CONFIG_ARCH_HAS_PTE_DEVMAP=y
CONFIG_ARCH_HAS_SET_DIRECT_MAP=y
CONFIG_ARCH_STACKWALK=y
CONFIG_ARCH_USE_MEMREMAP_PROT=y
CONFIG_BLK_PM=y
CONFIG_CC_CAN_LINK=y
CONFIG_CC_DISABLE_WARN_MAYBE_UNINITIALIZED=y
CONFIG_CC_HAS_ASM_INLINE=y
CONFIG_CC_HAS_KASAN_GENERIC=y
CONFIG_CC_HAS_WARN_MAYBE_UNINITIALIZED=y
CONFIG_CPU_SUP_AMD=y
CONFIG_CPU_SUP_HYGON=y
CONFIG_CPU_SUP_ZHAOXIN=y
CONFIG_CRYPTO_LIB_AES=y
CONFIG_CRYPTO_LIB_ARC4=y
CONFIG_CRYPTO_LIB_DES=y
CONFIG_CRYPTO_LIB_SHA256=y
CONFIG_DEBUG_MISC=y
CONFIG_DRM_I915_FORCE_PROBE=""
CONFIG_DRM_I915_SPIN_REQUEST=5
CONFIG_DRM_I915_USERFAULT_AUTOSUSPEND=250
CONFIG_DYNAMIC_EVENTS=y
CONFIG_EFI_EARLYCON=y
CONFIG_GCC_PLUGINS=y
CONFIG_GENERIC_GETTIMEOFDAY=y
CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE=y
CONFIG_HAVE_ARCH_STACKLEAK=y
CONFIG_HAVE_ASM_MODVERSIONS=y
CONFIG_HAVE_EISA=y
CONFIG_HAVE_FAST_GUP=y
CONFIG_HAVE_FUNCTION_ARG_ACCESS_API=y
CONFIG_HAVE_GENERIC_VDSO=y
CONFIG_HAVE_MOVE_PMD=y
CONFIG_HAVE_PCI=y
CONFIG_INIT_STACK_NONE=y
CONFIG_IO_URING=y
CONFIG_KASAN_STACK=1
CONFIG_LEDS_TRIGGER_AUDIO=y
CONFIG_LSM="lockdown,yama,loadpin,safesetid,integrity"
CONFIG_MMC_SDHCI_IO_ACCESSORS=y
CONFIG_NETFILTER_XT_TARGET_MASQUERADE=m
CONFIG_NET_VENDOR_GOOGLE=y
CONFIG_NET_VENDOR_MICROCHIP=y
CONFIG_NET_VENDOR_PENSANDO=y
CONFIG_NET_VENDOR_XILINX=y
CONFIG_NF_NAT=m
CONFIG_NF_NAT_MASQUERADE=y
CONFIG_NVMEM_SYSFS=y
CONFIG_OPTIMIZE_INLINING=y
CONFIG_POWER_SUPPLY_HWMON=y
CONFIG_PROC_PID_ARCH_STATUS=y
CONFIG_SKB_EXTENSIONS=y
CONFIG_SND_INTEL_NHLT=y
CONFIG_UBSAN_ALIGNMENT=y
CONFIG_UNIX_SCM=y
CONFIG_USB_AUTOSUSPEND_DELAY=2
CONFIG_X86_ACPI_CPUFREQ_CPB=y
CONFIG_X86_MCE_AMD=y
# end of Gentoo Linux
# Linux/x86 5.4.0-gentoo Kernel Configuration

And which have been removed:

user $diff <(sort .config) <(sort .config.old) | awk '/^>.*(=|Linux)/ { $1=""; print }'
CONFIG_ANON_INODES=y
CONFIG_ARCH_DISCARD_MEMBLOCK=y
CONFIG_ARCH_HAS_SG_CHAIN=y
CONFIG_ARCH_HAS_ZONE_DEVICE=y
CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING=y
CONFIG_ARM_GIC_MAX_NR=1
CONFIG_AUDIT_TREE=y
CONFIG_AUDIT_WATCH=y
CONFIG_BACKLIGHT_LCD_SUPPORT=y
CONFIG_CRYPTO_WORKQUEUE=y
CONFIG_DEFAULT_CFQ=y
CONFIG_DEFAULT_IO_DELAY_TYPE=0
CONFIG_DEFAULT_IOSCHED="cfq"
CONFIG_DEFAULT_SECURITY=""
CONFIG_DMA_DIRECT_OPS=y
CONFIG_FB_BACKLIGHT=y
CONFIG_GENERIC_HWEIGHT=y
CONFIG_HAVE_DEBUG_STACKOVERFLOW=y
CONFIG_HAVE_GENERIC_GUP=y
CONFIG_HAVE_MEMBLOCK=y
CONFIG_IA32_AOUT=y
CONFIG_INET6_XFRM_MODE_BEET=y
CONFIG_INET6_XFRM_MODE_TRANSPORT=y
CONFIG_INET6_XFRM_MODE_TUNNEL=y
CONFIG_INET_XFRM_MODE_TRANSPORT=y
CONFIG_INET_XFRM_MODE_TUNNEL=y
CONFIG_IO_DELAY_TYPE_0X80=0
CONFIG_IO_DELAY_TYPE_0XED=1
CONFIG_IO_DELAY_TYPE_NONE=3
CONFIG_IO_DELAY_TYPE_UDELAY=2
CONFIG_IOSCHED_CFQ=y
CONFIG_IOSCHED_NOOP=y
CONFIG_MAY_USE_DEVLINK=y
CONFIG_NO_BOOTMEM=y
CONFIG_RWSEM_XCHGADD_ALGORITHM=y
CONFIG_X86_DEV_DMA_OPS=y
# Linux/x86 4.19.86-gentoo Kernel Configuration

Alternatively, the kernel provides a script to cleanly compare two config files even if the options have moved in the file itself:

user $/usr/src/linux/scripts/diffconfig .config.old .config

make menuconfig

The options can then be researched and changed if necessary by running:

root #make menuconfig

The menuconfig target is helpful because it safely handles kernel symbol dependency resolution.

Compilazione

Importante
Quando moduli esterni sono installati (come nvidia o zfs), è necessario eseguire make modules_prepare come descritto in sotto prima di generare il kernel. Alcuni moduli non possono essere installati o preparati prima che il kernel sia stato generato.
Importante
Non dimenticare di riconfigurare bootloader per considerare i file del nuovo kernel, e rigenerare il file initramfs se utilizzato.

Per questo passo, seguire i passi nell'articolo manual configuration.

Creazione e installazione automatizzate

È possibile compilare e installare automaticamente il kernel appena installato utilizzando gli hook di Portage. Sebbene siano possibili anche altri approcci, quanto segue è basato sul pacchetto genkernel e gentoo-sources. Richiede i seguenti prerequisiti:

  1. genkernel all è in grado di compilare e installare il kernel a cui il link simbolico /usr/src/linux punta a $BOOTDIR e al bootloader.
  2. Il use flag symlink è impostata per l'ebuild del kernel.

Se questi sono soddisfatti, installa semplicemente l'hook di Portage post_pkg_postinst come mostrato di seguito.

FILE /etc/portage/env/sys-kernel/gentoo-sourcesHook di portage per la compilazione e l'installazione automatizzate del kernel
post_pkg_postinst() {
	CURRENT_KV=$(uname -r)
	# Check to see if genkernel has been run previously for the running kernel and use that config
	if [[ -f "${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" ]] ; then
		genkernel --kernel-config="${EROOT}/etc/kernels/kernel-config-${CURRENT_KV}" all
	elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then # Use latest kernel config from current kernel
		genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
	elif [[ -f /proc/config.gz ]] ; then # Use known running good kernel
		zcat /proc/config.gz >> "${EROOT}/tmp/genkernel.config"
		genkernel --kernel-config="${EROOT}/tmp/genkernel.config" all
		rm "${EROOT}/tmp/genkernel.config"
	else # No valid configs known
		genkernel all
	fi
}

Reinstallare moduli kernel esterni

Nota
Il passaggio module_prepare non è richiesto se si compila un intero kernel poiché questa funzione viene eseguita come parte del processo standard.

Ogni modulo esterno, come moduli kernel binari binary, necessitano di essere rigenerati per ogni nuovo kernel. Se il kernel non stato ancora generato, è necessario prima prepararlo per la generazione dei moduli esterni:

root #make modules_prepare

I pacchetti che contengono moduli kernel possono essere ricompilati usando il set @module-rebuild:

root #emerge --ask @module-rebuild

Risoluzione dei problemi di generazione

Quando si stanno sperimentando problemi durante la ricompilazione del kernel corrente, è potrebbe essere d'aiuto sanificare la sorgente del kernel. Ci si assicuri prima di creare un backup del file .config dato che l'operazione lo elminerà. Ci si assicuri inoltre di non usare suffissi come .bak o ~ dato che make distclean eliminerà anche questi.

root #cp .config /usr/src/kernel_config_bk
root #make distclean
root #mv /usr/src/kernel_config_bk .config

Update the bootloader

The upgraded and built kernel needs to be set up and eventually a bootloader or boot item updated, see Kernel/Configuration. Users of Grub can use the method below, users of other bootloaders must consult the Handbook.

After making sure /boot partition is mounted,

Using grub-mkconfig

The following command can be executed for updating GRUB's configuration file:

root #grub-mkconfig -o /boot/grub/grub.cfg

Using systemd-boot-gen to update systemd-boot UEFI configuration

Attenzione
Installing from cargo, the Rust package manager, should be done at one's own risk. The Gentoo project cannot verify what is built from it and could contain security risks particularly at the bootloader level. This could mean installing a rootkit if compromised. Proceed with the following section with caution.

Manual installation of systemd-boot-gen:

user $cargo install systemd-boot-gen

Copy the kernel parameters to /etc/default/cmdline, the file should contain:

FILE /etc/default/cmdline
CMDLINE="<kernel command line parameters>"

And run it using root privileges:

user $sudo ~/.cargo/bin/systemd-boot-gen

This will generate the boot configuration in /boot/loader/entries/ for all the available /boot/vmlinuz-* that have a matching /boot/initramfs-*.

Keeping or removing the old kernel

Keeping the old kernel sources

Kernel sources will eventually become unsupported. Some packages require the current sources to build. To protect the new sources from being removed by a depclean, it can be added to the world file (/var/lib/portage/world) by:

root #emerge --noreplace sys-kernel/gentoo-sources:newsource.version.here

Old sources that are no longer supported can be removed from the world file by:

root #emerge --deselect sys-kernel/gentoo-sources:unwanted.version.here

Rimozione

Si veda l'articolo Rimozione del kernel.

Vedere anche

Risorse esterne