Grub은 보안 부팅이 활성화된 상태에서 서명되지 않은 커널을 로드합니다.

Grub은 보안 부팅이 활성화된 상태에서 서명되지 않은 커널을 로드합니다.

저는 현재 젠투와 Windows(두 개의 다른 디스크)를 이중 부팅하고 있습니다. 저는 grub2를 사용하여 Linux 드라이브에서 부팅합니다. 거기서 Gentoo나 Windows(os-prober에 의해 추가됨) 중에서 선택할 수 있습니다.

최근에 Windows 10을 Windows 11로 업데이트했습니다. 그 후 일부 응용 프로그램은 보안 부팅이 활성화되지 않았다고 불평하기 시작했습니다. 문제는 내 마더보드(Asus z370f)의 BIOS 메뉴에서 보안 부팅 옵션이 활성화되어 있다는 것입니다. 그런 다음 보안 부팅 정책을 Other OS(이미 그랬던 것처럼) 또는 Windows UEFI(실제로 Microsoft에서 제공한 서명을 확인한 것 같습니다)로 설정할 수 있다는 것을 발견했습니다. 후자를 활성화한 후 듀얼 부팅 설정은 아무 작업도 수행하지 않았으며 빨간색 오류 메시지가 표시된 후 Windows 11로 리디렉션되었습니다.

듀얼 부팅을 복원하고 보안 부팅을 유지하기 위해 다음을 따랐습니다.Sasaki의 안전한 부팅 가이드. 자세한 세부 사항:

  • efi 키(PK, PEK, db, dbx)를 저장했습니다.
  • openssl을 사용하여 새 efi 키 만들기
  • 복합 키 생성 및 서명
  • 마더보드 키를 지우고 복합 키를 업로드하세요.

그 후 efi-readvar를 사용하여 키가 성공적으로 로드되었음을 확인했습니다. 그런 다음 새로 생성된 인증서를 사용하여 sbsign을 통해 커널 서명을 진행합니다.

sbsign --key /etc/efikeys/db.key --cert /etc/efikeys/db.crt --output /boot/vmlinuz-6.1.2.signed /boot/vmlinuz-6.1.2

이제 모든 것이 정상이 될 것 같아요. 서명되지 않은 코드를 로드하려고 하면 여전히 빨간색 오류 메시지가 표시됩니다. 잠시 동안 테이블에 머리를 부딪힌 후, 그럽 이미지에 서명을 시도했습니다.

sbsign --key /etc/efikeys/db.key --cert /etc/efikeys/db.crt --output /boot/efi/gentoo/grubx64.efi grubx64.efi.back

이제 상황은 조금 나아졌습니다. grub은 적어도 올바르게 시작됩니다. 그러나 실제로 Linux나 Windows를 부팅할 수는 없습니다. 더 많은 검색과 좌절 끝에 나는 grub이 부팅에 필요한 일부 모듈을 로드할 수 없다는 것을 깨달았습니다(서명되지 않았기 때문입니다). 그런 다음 grub-install여러 모듈을 사용했습니다 .

MODULES="all_video cat chain configfile disk echo \
    ext2 efi_gop efifwsetup efi_uga fat file font gfxmenu gettext gfxterm \
    gzio help jpeg linux ls normal part_gpt \
    reboot search test tpm video_colors video \
    gcry_sha512 gcry_rsa gcry_sha256"

grub-mkconfig -o /boot/grub/grub.cfg
grub-install --target=x86_64-efi --efi-directory=/boot --disable-shim-lock --modules="$MODULES"
mv /boot/efi/gentoo/grubx64.efi grubx64.efi.back
sbsign --key /etc/efikeys/db.key --cert /etc/efikeys/db.crt --output /boot/efi/gentoo/grubx64.efi grubx64.efi.back

이 시점에서 실제로 grub을 사용하여 Windows 11 또는 gentoo에서 부팅할 수 있으며 Windows uefi 모드에서도 보안 부팅을 할 수 있습니다. 몇 시간의 시행착오 끝에 모든 것이 제대로 작동했습니다.

문제는 다음 날 vmlinux-6.1.2.signed(실제 서명된 커널)뿐만 아니라 vmlinux-6.1.2(원래 서명되지 않은 커널)로도 부팅할 수 있다는 것을 알았을 때 시작되었습니다. Grub을 사용하면 서명되지 않은 커널(!)로 부팅(보안 부팅 활성화)할 수 있으며 두 커널을 모두 확인하면 메시지(!!)가 dmesg나타납니다 .Secure boot enabled

그래서 제가 현재 겪고 있는 문제는 다음과 같습니다.보안 부팅이 활성화된 경우에도 grub(및 내 uefi)이 서명되지 않은 커널을 부팅할 수 있도록 허용하는 이유는 무엇입니까?키를 추가하는 방식에 문제가 있나요? Grub에 서명하는 데 실수를 했나요?

참고: 이 과정에서는 GPG 키를 사용하지 않습니다. 저는 키 생성 및 업로드에 대한 Sasaki의 지침을 엄격히 따랐습니다. 가능하다면 gpg 키를 사용하지 않고 openssl을 사용하여 생성된 인증서만 사용하고 싶습니다.

참고 2: Grub 구성에 다음 줄을 추가하려고 시도했지만 특히 잘 작동하지 않았습니다. Grub은 .sig 파일 누락에 대해 불평하고 부팅을 거부했습니다.

set check_signatures=enfore
export check_signatures

솔직히 저는 grub에서 커널이 서명되었는지 확인하고 싶었지만 이 옵션은 gpg 서명과 관련된 것으로 보이며 grub에 추가하지 않았습니다.

참고 3: 또한 다양한 변경을 적용한 후 grub이 눈에 띄게 느려지는 것을 확인했습니다. 이전에는 시작이 거의 즉시 이루어졌지만 이제는 메뉴가 열리기 전에 잠시 "환영합니다" 메시지가 표시됩니다. 또한 콘솔은 키를 누를 때마다 지연되어 매우 느립니다. 모듈이 너무 많으면 상황이 더 나빠지는 걸까요?

/boot/grub/grub.cfg

#
# do not edit this file
#
# it is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### begin /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="advanced options for gentoo gnu/linux>gentoo gnu/linux, with linux 5.15.6-gentoo.signed"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

insmod part_gpt
insmod fat
search --no-floppy --fs-uuid --set=root e179-b0bd
if loadfont /grub/fonts/terminus18.pf2 ; then
  set gfxmode=2560x1440,auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=en_us
  insmod gettext
fi
terminal_output gfxterm
insmod part_gpt
insmod fat
search --no-floppy --fs-uuid --set=root e179-b0bd
insmod gfxmenu
loadfont ($root)/grub/themes/vimix/dejavu_sans_12.pf2
loadfont ($root)/grub/themes/vimix/dejavu_sans_14.pf2
loadfont ($root)/grub/themes/vimix/dejavu_sans_16.pf2
loadfont ($root)/grub/themes/vimix/dejavu_sans_24.pf2
loadfont ($root)/grub/themes/vimix/dejavu_sans_32.pf2
loadfont ($root)/grub/themes/vimix/dejavu_sans_48.pf2
loadfont ($root)/grub/themes/vimix/terminus-12.pf2
loadfont ($root)/grub/themes/vimix/terminus-14.pf2
loadfont ($root)/grub/themes/vimix/terminus-16.pf2
loadfont ($root)/grub/themes/vimix/terminus-18.pf2
insmod jpeg
insmod png
set theme=($root)/grub/themes/vimix/theme.txt
export theme
if [ x$feature_timeout_style = xy ] ; then
  set timeout_style=menu
  set timeout=5
# fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
  set timeout=5
fi
### end /etc/grub.d/00_header ###

### begin /etc/grub.d/10_linux ###
menuentry 'gentoo gnu/linux' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-889b06ae-8d49-4046-a1c6-42e6967862b2' {
    load_video
    set gfxpayload=keep
    insmod gzio
    insmod part_gpt
    insmod fat
    search --no-floppy --fs-uuid --set=root e179-b0bd
    echo    'loading linux 6.1.2-gentoo.signed ...'
    linux   /vmlinuz-6.1.2-gentoo.signed root=/dev/nvme1n1p3 ro vt.default_utf8=1
}
submenu 'advanced options for gentoo gnu/linux' $menuentry_id_option 'gnulinux-advanced-889b06ae-8d49-4046-a1c6-42e6967862b2' {
    menuentry 'gentoo gnu/linux, with linux 6.1.2-gentoo.signed' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.1.2-gentoo.signed-advanced-889b06ae-8d49-4046-a1c6-42e6967862b2' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod fat
        search --no-floppy --fs-uuid --set=root e179-b0bd
        echo    'loading linux 6.1.2-gentoo.signed ...'
        linux   /vmlinuz-6.1.2-gentoo.signed root=/dev/nvme1n1p3 ro  vt.default_utf8=1
    }
    menuentry 'gentoo gnu/linux, with linux 6.1.2-gentoo.signed (recovery mode)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.1.2-gentoo.signed-recovery-889b06ae-8d49-4046-a1c6-42e6967862b2' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod fat
        search --no-floppy --fs-uuid --set=root e179-b0bd
        echo    'loading linux 6.1.2-gentoo.signed ...'
        linux   /vmlinuz-6.1.2-gentoo.signed root=/dev/nvme1n1p3 ro single  }
    menuentry 'gentoo gnu/linux, with linux 6.1.2-gentoo' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.1.2-gentoo-advanced-889b06ae-8d49-4046-a1c6-42e6967862b2' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod fat
        search --no-floppy --fs-uuid --set=root e179-b0bd
        echo    'loading linux 6.1.2-gentoo ...'
        linux   /vmlinuz-6.1.2-gentoo root=/dev/nvme1n1p3 ro  vt.default_utf8=1
    }
    menuentry 'gentoo gnu/linux, with linux 6.1.2-gentoo (recovery mode)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.1.2-gentoo-recovery-889b06ae-8d49-4046-a1c6-42e6967862b2' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod fat
        search --no-floppy --fs-uuid --set=root e179-b0bd
        echo    'loading linux 6.1.2-gentoo ...'
        linux   /vmlinuz-6.1.2-gentoo root=/dev/nvme1n1p3 ro single 
    }
    menuentry 'gentoo gnu/linux, with linux 5.15.6-gentoo.signed' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.6-gentoo.signed-advanced-889b06ae-8d49-4046-a1c6-42e6967862b2' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod fat
        search --no-floppy --fs-uuid --set=root e179-b0bd
        echo    'loading linux 5.15.6-gentoo.signed ...'
        linux   /vmlinuz-5.15.6-gentoo.signed root=/dev/nvme1n1p3 ro  vt.default_utf8=1
    }
    menuentry 'gentoo gnu/linux, with linux 5.15.6-gentoo.signed (recovery mode)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.6-gentoo.signed-recovery-889b06ae-8d49-4046-a1c6-42e6967862b2' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod fat
        search --no-floppy --fs-uuid --set=root e179-b0bd
        echo    'loading linux 5.15.6-gentoo.signed ...'
        linux   /vmlinuz-5.15.6-gentoo.signed root=/dev/nvme1n1p3 ro single 
    }
    menuentry 'gentoo gnu/linux, with linux 5.15.6-gentoo' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.6-gentoo-advanced-889b06ae-8d49-4046-a1c6-42e6967862b2' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod fat
        search --no-floppy --fs-uuid --set=root e179-b0bd
        echo    'loading linux 5.15.6-gentoo ...'
        linux   /vmlinuz-5.15.6-gentoo root=/dev/nvme1n1p3 ro  vt.default_utf8=1
    }
    menuentry 'gentoo gnu/linux, with linux 5.15.6-gentoo (recovery mode)' --class gentoo --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.15.6-gentoo-recovery-889b06ae-8d49-4046-a1c6-42e6967862b2' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod fat
        search --no-floppy --fs-uuid --set=root e179-b0bd
        echo    'loading linux 5.15.6-gentoo ...'
        linux   /vmlinuz-5.15.6-gentoo root=/dev/nvme1n1p3 ro single 
    }
}

### end /etc/grub.d/10_linux ###

### begin /etc/grub.d/20_linux_xen ###
### end /etc/grub.d/20_linux_xen ###

### begin /etc/grub.d/30_os-prober ###
menuentry 'windows boot manager (on /dev/nvme0n1p1)' --class windows --class os $menuentry_id_option 'osprober-efi-3e17-e3b9' {
    insmod part_gpt
    insmod fat
    search --no-floppy --fs-uuid --set=root 3e17-e3b9
    chainloader /efi/microsoft/boot/bootmgfw.efi
}
### end /etc/grub.d/30_os-prober ###

### begin /etc/grub.d/30_uefi-firmware ###
menuentry 'uefi firmware settings' $menuentry_id_option 'uefi-firmware' {
    fwsetup
}
### end /etc/grub.d/30_uefi-firmware ###

### begin /etc/grub.d/40_custom ###
# this file provides an easy way to add custom menu entries.  simply type the
# menu entries you want to add after this comment.  be careful not to change
# the 'exec tail' line above.

#set check_signatures=enforce
#export check_signatures
### end /etc/grub.d/40_custom ###

### begin /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg
fi
### end /etc/grub.d/41_custom ###

/etc/default/grub

# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
#
# To populate all changes in this file you need to regenerate your
# grub configuration file afterwards:
#     'grub-mkconfig -o /boot/grub/grub.cfg'
#
# See the grub info page for documentation on possible variables and
# their associated values.

GRUB_DISTRIBUTOR="Gentoo"

# Default menu entry
#GRUB_DEFAULT=0

# Boot the default entry this many seconds after the menu is displayed
GRUB_TIMEOUT=5
#GRUB_TIMEOUT_STYLE=menu

# Append parameters to the linux kernel command line
#GRUB_CMDLINE_LINUX=""
#
# Examples:
#
# Boot with network interface renaming disabled
# GRUB_CMDLINE_LINUX="net.ifnames=0"
#
# Boot with systemd instead of sysvinit (openrc)
# GRUB_CMDLINE_LINUX="init=/usr/lib/systemd/systemd"

# Append parameters to the linux kernel command line for non-recovery entries
#GRUB_CMDLINE_LINUX_DEFAULT=""

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# The resolution used on graphical terminal.
# Note that you can use only modes which your graphic card supports via VBE.
# You can see them in real GRUB with the command `vbeinfo'.
GRUB_GFXMODE=2560x1440,auto

# Set to 'text' to force the Linux kernel to boot in normal text
# mode, 'keep' to preserve the graphics mode set using
# 'GRUB_GFXMODE', 'WIDTHxHEIGHT'['xDEPTH'] to set a particular
# graphics mode, or a sequence of these separated by commas or
# semicolons to try several modes in sequence.
#GRUB_GFXPAYLOAD_LINUX=

# Path to theme spec txt file.
# The starfield is by default provided with use truetype.
# NOTE: when enabling custom theme, ensure you have required font/etc.
GRUB_THEME="/boot/grub/themes/vimix/theme.txt"

# Background image used on graphical terminal.
# Can be in various bitmap formats.
#GRUB_BACKGROUND="/boot/grub/mybackground.png"

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to kernel
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY=true

# Uncomment to disable generation of the submenu and put all choices on
# the top-level menu.
# Besides the visual affect of no sub menu, this makes navigation of the
# menu easier for a user who can't see the screen.
#GRUB_DISABLE_SUBMENU=y

# Uncomment to play a tone when the main menu is displayed.
# This is useful, for example, to allow users who can't see the screen
# to know when they can make a choice on the menu.
#GRUB_INIT_TUNE="60 800 1"

GRUB_DEFAULT="Advanced options for Gentoo GNU/Linux>Gentoo GNU/Linux, with Linux 5.15.6-gentoo.signed"
# EDITED
GRUB_TERMINAL_OUTPUT="gfxterm"
GRUB_FONT=/boot/grub/fonts/Terminus18.pf2 
GRUB_GFXMODE=2560x1440,auto
GRUB_GFXPAYLOAD_LINUX=keep
GRUB_DISABLE_OS_PROBER=n
GRUB_CMDLINE_LINUX_DEFAULT="vt.default_utf8=1"

관련 정보