Kernel/Upgrade
이 글은 새 커널(kernel)로 업그레이드 하는 과정을 설명합니다.
새 소스 코드에서 새 커널을 만드는 과정은 기본적으로 시스템을 설치할 때 커널을 만드는 과정과 동일합니다. 다른 점이 있다면 이전 커널로부터 새 커널에서 쓸 설정을 가져올 수 있다는 점입니다. 이전 설정을 사용하면 모든 커널 옵션을 전반적으로(make menuconfig와 비슷) 다시 설정하지 않아도 됩니다.
커널의 설정은 커널 소스 코드가 담긴 디렉터리에 .config 파일로 저장합니다. 새 커널은 이전 커널에서는 없는 새 옵션이나 기능을 가지고 있거나 이전 커널에서 더 이상 지니고 있지 않을 기능 또는 옵션이 빠져있습니다. 커널 설정은 커널의 기능 또는 옵션을 활성화 할 지 말 지를 지정하고 커널이 넣고 빌드할 건지 모듈로 빌드하여 커널 실행 과정에서 요청하면 불러올 건지를 결정합니다. 따라서 새 커널의 설정 파일은 이전 커널의 설정에 없는 설정 파일의 새 항목을 지니고 있고 이전 커널의 설정 파일에 있던 항목이 더 이상 없을 수도 있습니다.
바뀐 설정 파일을 다루려면, 이전 커널의 설정 파일을 새 설정에서 사용할 수 있는 설정으로 변환해야합니다. 이 글에서는 이전 커널의 설정을 새 커널에 맞게 변환하고, 새 커널 소스 코드로 커널을 만드는 방법을 보여드리겠습니다.
Kernel upgrade in Gentoo involves these steps:
- Install the new kernel sources.
- Setting the symlink to the (newly installed) kernel sources.
- Moving to the new kernel's folder.
- Adjusting the .config file for the options introduced to, or removed from, the new kernel's configuration.
- Compiling the kernel and the initramfs.
- Updating the bootloader.
- Removing or keeping the old kernel.
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.
새 커널 설치 및 활용
새 커널 소스를 설치했을 때 커널 업그레이드를 하는 것이 좋습니다. 새 커널 소스는 가끔 {{{1}}} 명령을 실행하거나, 직접 설치할 경우에 설치됩니다.
root #
emerge --ask --update --deep --with-bdeps=y --newuse @world
Of course, they can be installed directly using the next command (replace gentoo-sources with whatever version of the kernel that is in-use):
root #
emerge --ask --update --deep --with-bdeps=y --newuse sys-kernel/gentoo-sources
새 커널 소스 설치 과정은 사용자에게 새 커널을 제공하는 과정이 아닙니다. 새 소스 코드로부터 새 커널을 만들어 설치한 다음 시스템을 다시 부팅하여 새 커널을 활성화해야합니다.
Set symlink to new kernel sources
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.
/usr/src/linux 심볼릭 링크는 언제든 현재 사용하는 커널 소스를 가리킵니다. 다음 세가지 방법 중 하나로 끝낼 수 있습니다:
USE="symlink"
USE 플래그를 활용하여 커널 소스 설치- eselect로 링크 설정
- 직접 심볼릭 링크 업데이트
eselect로 링크 설정
eselect로 심볼릭 링크를 설정하려면:
root #
eselect kernel list
Available kernel symlink targets: [1] linux-3.14.14-gentoo * [2] linux-3.16.3-gentoo
이 명령의 결과에서 존재하는 커널 소스코드 목록을 출력합니다. 애스터리스크(*)는 선택한 소스 코드를 나타냅니다.
커널 소스를 (예를 들어 두번째 항목 처럼)바꾸려면 다음 명령을 실행하십시오:
root #
eselect kernel set 2
심볼릭 링크 직접 업데이트
심볼릭 링크를 직접 설정하려면:
root #
ln -sf /usr/src/linux-3.16.3 /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
symlink USE 플래그로 커널 소스 설치하기
이 과정은 /usr/src/linux 심볼릭 링크가 새로 설치한 커널 소스코드를 가리키도록 합니다.
필요하다면, 두가지 방식 중 한가지 방법으로 고칠 수 있습니다.
Moving to the new kernel folder
Now that the symbolic link has been modified, change the working directory to the new kernel folder.
user $
cd /usr/src/linux
This command is still necessary even if the working directory was already /usr/src/linux when the symlink was modified. Until the new symlink is actually followed, the console will still be in the old kernel's directory.
Adjusting the .config file for the new kernel
Copy the previous kernel configuration
이전 커널의 설정을 새 커널의 설정으로 복사해야 합니다. 이전 커널의 설정은 다음 여러 곳에서 찾을 수 있습니다:
- procfs 파일 시스템에서 현재 커널로부터 Enable access to .config through /proc/config.gz 옵션을 활성화 했다면:
root #
zcat /proc/config.gz > /usr/src/linux/.config
root #
zcat /proc/config.gz > /usr/src/linux/.config
- From the old kernel. This will only work when the old kernel was compiled with CONFIG_IKCONFIG:
root #
/usr/src/linux/scripts/extract-ikconfig /path/to/old/kernel >/usr/src/linux/.config
- /boot 디렉터리에 설정 파일을 설치했다면:
root #
cp /boot/config-3.14.14-gentoo /usr/src/linux/.config
root #
cp /boot/config-3.14.14-gentoo /usr/src/linux/.config
- 현재 동작 중인 커널의 디렉터리에서:
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/
- In the /etc/kernels/ directory, if
SAVE_CONFIG="yes"
is set in /etc/genkernel.conf and genkernel was previously used:
root #
cp /etc/kernels/kernel-config-x86_64-3.14.14-gentoo /usr/src/linux/.config
새 커널 설정
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.
이전 커널의 설정을 새 커널에서 활용하려면 변환해야합니다. 이 변환 과정은 make silentoldconfig 또는 make olddefconfig 명령을 실행하여 처리할 수 있습니다.
make silentoldconfig
make syncconfig has become an internal implementation detail; make oldconfig should be used when possible. The make silentoldconfig target has been removed as of Linux version 4.19 and higher.
다음 설정은 make config로 텍스트 기반 설정처럼 진행할 수 있습니다. 새 설정 옵션에 대한 선택권을 줍니다. 예를 들면:
root #
cd /usr/src/linux
root #
make silentoldconfig
Anticipatory I/O scheduler (IOSCHED_AS) [Y/n/m/?] (NEW)
줄 마지막에 (NEW) 문자열은 이 옵션이 새로 들어왔음을 의미하는 표시입니다. 각괄호 안에 남길 수 있는 답을 남기십시오. Yes, No, module 이 있으며, 도움말을 보기 위한 ?가 있습니다. 대문자 답변을 추천합니다(여기서는 Y 입니다). 도움말에서는 옵션 또는 드라이버에 대해 설명합니다.
안타깝게도 make silentoldconfig은 각각의 옵션에 대한 더 많은 정보를 - 도움말 옆에 - 상황 설명 처럼 보여주지 않으므로, 올바른 대답을 주기는 가끔은 어렵습니다. 이런 경우 진행하는 가장 좋은 방법은 그래픽 커널 설정 도구중 하나를 통해 옵션 이름을 기억한 다음 내용을 바꾸는 것입니다.
make olddefconfig
대화식 진행을 원치 않는다면(어떤 질문도 하지 않음), make olddefconfig를 활용하십시오:
root #
cd /usr/src/linux
root #
make olddefconfig
make help
Use make help to see other conversion methods available:
user $
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
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.
빌드
외부 커널 모듈을 설치했다면(nvidia 또는 zfs의 경우), 커널을 빌드하기 전에 하단에서 설명한 바와 같이 make modules_prepare 명령을 실행할 필요가 있습니다. 일부 모듈은 커널을 빌드하기 전에 설치하거나 준비할 수 없습니다.
새 커널 파일 이름에 맞게 부트로더를 다시 설정하는 절차를 잊지 마시고, initramfs는 이미 사용중인 경우에도 마찬가지로 다시 빌드하십시오.
이 단계에서 다음 단계는 직접 설정하기 글에 있습니다.
Automated build and installation
It is possible to automatically build and install the newly emerged kernel using Portage hooks. While other approaches are also possible, the following is based on genkernel and gentoo-sources package. It requires the following prerequisites:
- genkernel all is able to build and install the kernel to which the /usr/src/linux symlink points into
$BOOTDIR
and the bootloader. - The
symlink
use flag is set for the kernel ebuild.
If those are fulfilled, simply install a post_pkg_postinst
Portage hook as shown below.
/etc/portage/env/sys-kernel/gentoo-sources
Automated kernel build and installation portage hookpost_pkg_postinst() {
# Eselect the new kernel or genkernel will build the current one
eselect kernel set linux-"${KV}"
CURRENT_KV=$(uname -r)
# Check 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
# Use latest kernel config from current kernel
elif [[ -f "${EROOT}/usr/src/linux-${CURRENT_KV}/.config" ]] ; then
genkernel --kernel-config="${EROOT}/usr/src/linux-${CURRENT_KV}/.config" all
# Use known running good kernel
elif [[ -f /proc/config.gz ]] ; then
zcat /proc/config.gz >> "${EROOT}/tmp/genkernel.config"
genkernel --kernel-config="${EROOT}/tmp/genkernel.config" all
rm "${EROOT}/tmp/genkernel.config"
# No valid configs known, compile a clean one
else
genkernel all
fi
}
외부 커널 모듈 다시 설치
The modules_prepare step is not required if building an entire kernel as this function is done as part of the standard process.
이진 커널 모듈 같은 어떤 외부 커널 모듈은 각각의 새 커널에 대해 다시 빌드해야 할 대가 있습니다. 아직 커널을 빌드하지 않았다면 외부 커널 모듈을 빌드하기 위해 우선 준비해야합니다:
root #
make modules_prepare
@module-rebuild 셋을 사용하여 꾸러미를 다시 빌드할 수 있습니다:
root #
emerge --ask @module-rebuild
빌드 문제 해결
현재 커널을 다시 하는 동안 빌드에 문제가 있음을 경험했을 경우 커널 소스를 정리하는데 도움이 필요합니다. 동작중에 .config 파일을 제거하므로 먼저 백업했는지 확인하십시오. 백업에 .bak 또는 ~ 접미사를 사용하면 make distclean에서 지우므로 사용하지 마십시오.
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
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:
/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
오래된 커널 제거
커널 제거 글을 보십시오.
See also
- Genkernel — 커널과 initramfs 빌드를 자동화할 때 사용하기 위해 젠투에서 만든 도구입니다.
- Dracut — an initramfs infrastructure and aims to have as little as possible hard-coded into the initramfs.
- Kernel/Configuration
- Updating GRUB to a new kernel