GRUB2/ko

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

GRUB2GRUB version 1을 대체하는 부트로더이며, GRUB version 1은 이제 "GRUB Legacy"라고 합니다. GRUB2는 GRUB Legacy와는 달리 코드 기반이 완전히 다르며, 고급 스크립트 기능을 활용할 수 있는 새로운 쉘-유사 문법 같은 기능이 들어있습니다.

GRUB replaces the original GRUB Legacy boot loader with an entirely separate code base featuring a new shell-like syntax for advanced scripting capabilities.

한방에 접근하시려면 GRUB2 Quick Start를 보십시오.

GRUB Legacy에서 GRUB2로 옮겨가려면, GRUB2 Migration을 참고하십시오.

설치

선행 과정

기본적으로 GRUB2는 빌드 시간에 기본 플랫폼 대상을 추측합니다. make.confGRUB_PLATFORMS 변수를 설정하여 우선 적용할 수 있습니다.

파일 /etc/portage/make.confEMU, EFI, PC를 지원하도록 GRUB_PLATFORMS 변수를 설정하는 예제
GRUB_PLATFORMS="emu efi-32 efi-64 pc"

대상 CPU에 따라 다음 플랫폼을 지원합니다:

Platform Target
i386 ia64 mips mipsel powerpc sparc64 x86_64
ARC No No No Yes No No No
Coreboot Yes No No No No No 32-bit
EFI Yes Yes No No No No Yes
EMU Yes Yes Yes Yes Yes Yes Yes
IEEE 1275 (Open Firmware) Yes No No No Yes Yes 32-bit
Loongson No No No Yes No No No
Multiboot Yes No No No No No 32-bit
QEMU Yes No No No No No 32-bit
QEMU-MIPS No No Yes No No No No
PC Yes No No No No No 32-bit
참고
GRUB_PLATFORMS 변수 값을 바꿀 때마다 GRUB2 이진 파일 상태가 바뀌게 다시 이머지해야합니다. emerge 섹션 하단의 --newuse --deep 옵션을 활용했는지 확인하십시오.

amd64 프로파일에서는 기본적으로 EFI 기능 지원을 활성화합니다. BIOS 기반 시스템을 사용한다면, GRUB_PLATFORMS 변수에 "emu" 값을 넣어 불필요한 의존요소가 들어가지 않게 하십시오.

USE 플래그

USE flags for sys-boot/grub GNU GRUB boot loader

device-mapper Enable support for device-mapper from sys-fs/lvm2
doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally
efiemu Build and install the efiemu runtimes
fonts Build and install fonts for the gfxterm module
libzfs Enable support for sys-fs/zfs
mount Build and install the grub-mount utility
nls Add Native Language Support (using gettext - GNU locale utilities)
sdl Add support for Simple Direct Layer (media library)
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)
themes Build and install GRUB themes (starfield)
truetype Build and install grub-mkfont conversion utility
verify-sig Verify upstream signatures on distfiles

Emerge

GRUB2를 설치하려면 일반적인 emerge 문법을 사용하십시오:

root #emerge --ask --newuse --deep sys-boot/grub:2

추가 프로그램

추가로, os-prober 유틸리티(sys-boot/os-prober 꾸러미에 있음)를 설치하여 grub-mkconfig 명령을 실행할 때 GRUB2가 다른 운영체제도 찾을 수 있도록 하십시오. 대부분의 경우, 이런 조치로 GRUB2에서 Windows 7, 8.1, 10 및 기타 리눅스 배포판 등의 다른 운영체제를 자동으로 찾을 수 있습니다.

root #emerge --ask --newuse sys-boot/os-prober

GRUB2(그리고 추가로 sys-boot/os-prober도) 설치는 부트 로더를 자동으로 활성화하지 않습니다. 단지 이 설치 과정은 운영체제에 프로그램을 설치하는 과정일 뿐이지만, 시스템 자체에 부트 로더를 설치(하여 시스템을 부팅할 때 부트로터를 사용)하려면, 설정 부분에서 다루는 추가 과정을 거쳐야합니다.

부트 로더 설치

GRUB2 시스템 부트로더 설치는 시스템을 어떻게 부팅할것인지(BIOS냐 UEFI냐), 부트로더가 올라간 디스크에 어떻게 설치하고 분할하느냐(MBR 또는 GPT 분할 배치)에 달려있습니다.

이 게시글은 다음 상황을 다룹니다:

시스템에 맞는 설치 과정을 선택하십시오.

UEFI와 GPT

경고
Even though 64-bit x86 processors ("x86-64" or "x64") support running legacy 32-bit software, it is not possible for an EFI implementation to do the same. A 64-bit EFI will not be able to run 32-bit .efi loaders! It should be noted that some early 64-bit-capable systems, i.e. systems with an x64 processor (an x86 processor featuring AMD64 or Intel 64), used a 32-bit implementation of EFI, like some early MacBooks (Intel Core 2) and some pre-2010 Windows computers. In such cases, even though the processor is 64-bit, (U)EFI is implemented as 32-bit software making efi-32 the proper EFI target because, likewise, a 32-bit EFI cannot run 64-bit .efi loaders.
참고
If the UEFI-CSM is used, refer to BIOS with MBR or BIOS with GPT instead. CSM stands for "Compatibility Support Module" and is a BIOS emulation, making the UEFI behave like a BIOS. In the firmware setup it is often called "Legacy Mode" or "Compatibility Mode". UEFI-CSM has always been optional and was phased out on mainstream systems (such as PCs) in 2020.

UEFI용 GPT 분할

GRUB2에서 UEFI GPT 부팅을 수행할 때, 시스템은 FAT 파일 시스템으로 제공하는 EFI 파티션을 보유해야 합니다.

UEFI systems boot from efi files on their EFI System Partition (ESP). The EFI System Partition can be just about any size, with implementation considerations in mind.

The EFI System Partition can contain just the bootloader, or the bootloader along with support files. Typically, /boot contains the kernel along with additional EFI support files, while /boot/efi contains the actual EFI files, which tend to be small.

참고
The EFI System Partition can be made at either /boot or /boot/efi but it tends to be simpler to just use /boot. Using /boot/efi allows files like the kernel and bootloader support files to be stored on a separate partition and filesystem or the root filesystem itself; the later requires that GRUB can access the root filesystem and read the required files, which may not always be possible (like with root filesystem encryption).

If generating a standalone EFI System Partition, under /boot/efi, a size of 128MB is reasonable, this allows multiple efi files to be stored.

참고
There is little harm in keeping backups of working efi files, which could still be booted if a new one is installed.

공간을 분할할 선택한 도구를 활용하여 저장 공간을 분할하십시오. gdisk(sys-apps/gptfdisk)와 parted (sys-block/parted) 도구는 이러한 목적에 안성맞춤입니다. gdisk 유틸리티를 사용할 때는, EF00 형식을 사용하는지 확인하십시오.

Partitioning with fdisk
참고
As described in Preparing the disks Handbook section, /boot partition is used for ESP, which is formatted as FAT32. Depending on the preferred system configuration, a separate partition for /boot may be desirable, e.g. in the case of filesystem encryption.

If using fdisk to partition the boot partition, start by opening the disk for modification, in this example /dev/sda is used:

root #fdisk /dev/sda
Welcome to fdisk (util-linux 2.38.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

A new partition table can be created using "g":

Command (m for help):g
Created a new GPT disklabel (GUID: 4AB36B49-BAAD-D544-AC45-E3154565018D).

A new partition can be created using "n":

Command (m for help):n
 
Partition number (1-128, default 1): 1
First sector (2048-121012190, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-121012190, default 121010175): +128M
 
Created a new partition 1 of type 'Linux filesystem' and of size 128 MiB.

Once the partition is created, the ESP and Boot flags must be set, this can be done by setting the partition type to EFI System Partition. This can be accomplished with the t option, to change the partition type, and then selecting 1, which corresponds to the EFI System Partition type:

Command (m for help):t
 
Selected partition 1
Partition type or alias (type L to list all): 1
Changed type of partition 'Linux filesystem' to 'EFI System'.

Finally, the changes can be saved by running w:

Command (m for help):w
 
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

With the partition created, it must be formatted to use the FAT32 filesystem, this can be done with:

root #mkdosfs -F 32 -n efi-boot /dev/sda1
root #mkdir /boot/efi

To determine the partition uuid, or PARTUUID of the new partition, the following command can be use:

user $lsblk -o name,partuuid
lsblk -o name,partuuid
NAME         PARTUUID
sdd          
└─sd1       20f3d6cc-9781-3640-9232-0f5a8c662a60

To create a fstab entry for this partition:

파일 /etc/fstab/boot/efi 마운트 항목 추가
'"`UNIQ--pre-0000000D-QINU`"'
root #mount /boot/efi
참고
/etc/portage/make.confGRUB_PLATFORMS 변수를 설정하면 도움이 될 수 있습니다. GRUB2에서 적당한 EFI 타겟을 감지할 때 사용할 옵션을 결정하도록 도움을 줍니다. 32비트 UEFI 시스템에서는 efi-32를, 64비트 UEFI 시스템에서는 efi-64를 씁니다.
중요
GRUB2를 제대로 설치하려면 EFI 디렉터리를 반드시 마운트 해야하며, grub-install 명령을 제대로 실행하려면 efivars 커널 모듈을 불러와야합니다.

Installing GRUB for EFI

/boot 위치가 있는지 확인하시고 이 위치에서 분할 공간을 사용한다면 마운트했는지 확인하십시오:

root #mount /boot

grub-install 명령을 실행하여 관련 파일을 /boot/grub에 복사하십시오. /boot/grub에 GRUB2를 설치하며 /boot/efi/EFI/gentoo/grubx64.efi 핵심 이미지를 복사하고 부팅 항목에 추가할 efibootmgr를 호출합니다.

root #grub-install --efi-directory=/boot/efi
Installation finished. No error reported.

위 명령은 vfat 형식의 EFI 시스템 파티션(ESP)를 /boot/efi에 마운드했다 가정합니다. ESP를 /boot레 직접 마운트했다면, --efi-directory=/boot 옵션을 사용하십시오.

참고
By default, GRUB installs targeting the type of system which the command is executed on. If another system type is used, the --target option can be used to specify it.
참고
The --removable option can be used to install GRUB to /boot/EFI/BOOT/BOOTX64.EFI, potentially enhancing compatibility, as this location is often checked by default.

BIOS와 MBR

참고
시스템을 마이크로소프트 윈도우와 듀얼 부팅을 수행한다면, 시스템에 UEFI 펌웨어가 없는지 확인하십시오. 이럼에도 '기존 BIOS' 모드로 부팅한다면, 마이크로소프트 윈도우가 부팅을 거부합니다.

/boot 위치가 있는지 확인하시고 이 위치에서 분할 공간을 사용한다면 마운트했는지 확인하십시오:

root #mount /boot

grub-install 명령을 실행하여 관련 파일을 /boot/grub에 복사하십시오. PC 플랫폼에서는 주 부트 레코드(MBR)에 부팅 이미지를 설치하거나 디스크 공간의 부트 섹터에 설치합니다. 잘 동작한다면, grub-install을 실행한 다음의 출력 결과는 다음과 같습니다:

root #grub-install /dev/sda
Installation finished. No error reported.

grub-install 명령은 CPU 아키텍처와 시스템 플랫폼을 설정할 때 --target 옵션을 받아들입니다. 설정하지 않으면 grub-install에서 적당한 값을 추측하려듭니다. amd64/x86 시스템에서는 기본적으로 i386-pc 설정 값을 사용합니다. 또한 grub-install 명령에서는 GRUB2 설치 관리자에게 --boot-directory 옵션으로 GRUB2 부팅 파일을 찾을 때 살펴볼 디렉터리 값을 넘기기도 합니다. 기본 값은 현재 /boot 디렉터리지만 루트 공간을 옮기려 할 경우 쓸모있습니다.

BIOS용 MBR 분할

첫번째 분할 공간 이전에 충분한 공간을 두었는지 확인하십시오. 첫번째 2048 섹터에 최소한 1MiB 디스크 여유공간을 두어 주 부트 레코드를 넣어야 합니다. BIOS 부팅 파티션 이라는 추가 공간을 만드는 것이 좋습니다(만 추천하지는 않습니다). 이 공간은 정의할 필요만 있을 뿐, 포맷하지는 않습니다. 시스템을 GPT 분할 영역 구성으로 바꿀 때만 필요합니다. MBR로 그대로 두는 경우에는 필요하지 않습니다.

젠투 설치 절차를 따랐다면 BIOS 부팅 공간은 이미 존재합니다.

BIOS와 GPT

경고
GPT was not designed for the legacy BIOS, yet with the protective MBR it includes a provision for it. Also, dual-boot with legacy operating systems designed to be booted from MBR, which is the de facto standard on computers with a BIOS, will need to access their partitions through the MBR, which can be accomplished by creating GPT/MBR hybrid partitions. This technique, however, has specific constraints.

On a BIOS system with GPT partitioning, GRUB relies on a partition called "BIOS boot partition". This partition is not formatted with a file system, instead grub-install will copy parts of the boot loader to it. The "BIOS boot partition" is not the same partition as a /boot partition.

참고
See also What is the BIOS boot partition? in the x86 Handbook.

/boot 공간이 필요하면, /boot 공간을 마운트하고 시작하십시오:

root #mount /boot

잘 동작한다면, grub-install을 실행 출력 결과는 다음과 같습니다:

root #grub-install /dev/sda
Installation finished. No error reported.

grub-install 명령은 CPU 아키텍처와 시스템 플랫폼을 설정할 때 --target 옵션을 받아들입니다. 설정하지 않으면 grub-install에서 적당한 값을 추정합니다. amd64/x86 시스템에서는 기본적으로 i386-pc 설정 값을 사용합니다. 또한 grub-install 명령에서는 GRUB2 부팅 파일을 찾을 때 살펴볼 디렉터리를 GRUB2 설치 관리자에 알려줄 --boot-directory 옵션을 받아들이기도 합니다. 기본값은 현재 /boot 디렉터리지만 루트 공간을 옮기려 할 경우 쓸모있습니다.

grub-install also accepts a --boot-directory option to tell the GRUB installer which directory to look in for the boot files. This defaults to the current /boot but is useful when trying to move a root partition.

Dual-boot with Windows

참고
시스템을 마이크로소프트 윈도우와 듀얼 부팅을 수행한다면, 시스템에 UEFI 펌웨어가 없는지 확인하십시오. 이럼에도 '기존 BIOS' 모드로 부팅한다면, 마이크로소프트 윈도우가 부팅을 거부합니다. 또한 이전 마이크로소프트 윈도우 시스템은 GPT를 지원하지 않습니다. MBR-GPT 혼합 방식을 사용하는 방안으로 접근할 수 있는데, 이 방식으로 접근하려면 Hybrid partition tableen을 참고하십시오.
참고
Traditionally x86-PCs used a BIOS as firmware. After the switch to (U)EFI on PCs (around 2005) there used to be a BIOS emulation called 'Compatibility Support Module' (CSM), PCs were therefore still compatible with existing operating systems. On mainstream PCs the EFI-CSM has been phased out since 2020. Even before 2020 some (U)EFI implementations, such as servers, lacked the CSM completely. 'Legacy BIOS mode' is therefore no longer available on modern UEFI systems. UEFI in its native boot mode demands the GUID Partition Table (GPT), a pre-installed operating system will therefore already be using a GPT partitioning scheme.

An already installed Windows will refuse to boot when the boot mode or the partitioning scheme is changed. Also, older Windows systems don't support GPT (or EFI) at all, demanding that a BIOS or the EFI-CSM along with an MBR must be used. If Windows supports EFI it can be re-installed in the native UEFI mode and the GPT partitioning scheme, as well as Linux; see section UEFI with GPT.

Hybrid partitioning between GPT and MBR creates both a valid GPT partition table and a valid MBR partition table at the same time, but limits the total number of hybrid partitions to four because of the four primary partition limit of the MBR. Since the ESP (the EFI System Partition holding the EFI bootloaders) takes up one partition this leaves only three shared partitions between MBR and GPT. When one partition is used for Windows and one for Linux, there is only one additional hybrid partition possible, like a separate Linux /boot partition or a shared data partition between the two operating systems.

경고
Normally, a GPT partition table will always also create an MBR partition table which holds only one partition spanning over the whole disk. This will ensure that older software doesn't mistake the disk as 'empty'. The MBR with its protective partition is therefore called a 'protecive MBR' and is part of the GPT specification. By defining hybrid partitions, this protective feature of the GPT is sacrificed! Legacy software will no longer see used space when analyzing the hybrid MBR. Software that is unaware of the GPT and only sees the MBR may mistake undefined disk space as unused and empty space. Data written outside the defined MBR partitions may cause data loss to the underlying GPT partitions!

If there are two physical disks available to the system, a great solution is to have one disk use the GPT and the other the MBR partitioning scheme. Normally, the Windows installation uses only one partition as 'system partition' and 'boot partition', called 'drive C:'. When in BIOS mode the initial partition for booting, the 'system partition', must be an MBR partition. This applies to every Windows version since Windows XP and includes Windows 10. Since Windows Vista (actually Windows XP x64 Edition) the Microsoft operating system supports accessing GPT partitions. The solution is to relocate the 'system partition' part of an installation to the MBR partitioned disk, and convert the 'boot partition' (the one containing \WINDOWS) into a GPT partitioned disk. Windows can thereafter access all the GPT partitions on the one disk, and will continue to use the MBR partitions (or hybrid partitions) on the disk containing the 'system partition'. The Windows installation (containing \WINDOWS) would be a GPT partition, even when booted in BIOS mode. Windows 11 no longer supports BIOS/CSM/MBR mode.

BIOS용 GPT 분할

GPT 파티션 테이블이 시스템에 있을 경우, EF02 형식(EF00 형식의 EFI 시스템 파티션(ESP)와는 다름)의 작은 BIOS 부트 파티션이 있어야합니다. 충분한 1MiB 공간이 있어야 동작할 텐데, 2-4MiB 설정 값이 안전한 선택입니다. BIOS 부트 파티션은 부트로더 스테이지 2를 유지합니다. BIOS 부트 파티션은 파일 시스템으로 포맷할 필요가 없습니다. grub-install 명령이 기존 파일시스템을 다른 어떤 자체 파일 시스템으로 덮어씁니다.

중요
/boot에 마운트한 일반 공간과 BIOS 부트 파티션이 동일하지 않습니다. /boot 경로와 BIOS 부팅 공간은 다른 공간이며, 개별적으로 다루어야합니다. BIOS 부트 파티션은 일반 공간처럼 시스템에 마운트하면 안됩니다(예: /etc/fstab에 정의하면 안됩니다). /boot 공간은 문제없이 마운트할 수 있으며, /etc/fstab 파일에 나타날 수 있습니다.

디스크 공간을 BIOS 파티션으로 만들려면 parted (sys-block/parted) 도구를 활용하여 다음을 입력하십시오(1 값을 BIOS 부팅 파티션으로 표시할 공간의 번호로 바꾸십시오!):

(parted)set 1 bios_grub on

sys-apps/gptfdiskcgdisk 유틸리티에서는 공간 형식을 0xEF02로 설정하고 레이블을 gptbios로 설정하시면 됩니다.

EFI 시스템 파티션은 필요하지 않지만, 나중에 시스템 마더보드를 UEFI 보드로 업그레이드 했을 때, BIOS 부트 파티션이 EFI 시스템 파티션으로 변환하기에 크기가 충분한 지 확인할 때 민감할 수 있습니다.

다음 내용은 gdisk 유틸리티에서 GPT 방식으로 디스크 공간 분할을 수행하여 BIOS 부트 [0xEF02] 파티션과 EFI [0xEF00] 파티션으로 나눈 후, p 키를 눌렀을 때의 출력 화면입니다:

root #gdisk /dev/sdc
GPT fdisk (gdisk) version 0.8.1
 
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present
 
Found valid GPT with protective MBR; using GPT.
 
Command (? for help): p
Disk /dev/sdc: 976773168 sectors, 465.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): AA369F4D-37A4-4C0D-A357-DC24B99A6337
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
 
Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048       828377087   395.0 GiB   8E00  Linux LVM
   2       828377088       891291647   30.0 GiB    0700  Microsoft basic data
   3       891291648       975177727   40.0 GiB    0700  Microsoft basic data
   4       975177728       976754687   770.0 MiB   8300  Linux filesystem
   5       976754688       976756735   1024.0 KiB  EF02  BIOS boot partition
   6       976756736       976773134   8.0 MiB     EF00  EFI System
 
Command (? for help): 
참고
fdisk 명령을 사용할 때, GPT 공간을 설정할 경우 0x 16진수 접두부는 입력하지 않아도 됩니다.

동일한 설정을 활용하여, parted 유틸리티에서 약간 다른 문법으로 출력하겠습니다:

root #parted /dev/sdc
GNU Parted 3.0
Using /dev/sdc
(parted) print
...
Sector size (logical/physical): 512B/512B
Partition Table: gpt
  
Number  Start   End    Size    File system  Name                  Flags
 1      1049kB  424GB  424GB                Linux LVM             lvm
 2      424GB   456GB  32.2GB               Microsoft basic data
 3      456GB   499GB  42.9GB               Microsoft basic data
 4      499GB   500GB  807MB   ext2         Linux filesystem
 5      500GB   500GB  1049kB               BIOS boot partition   bios_grub
 6      500GB   500GB  8396kB               EFI System            boot
  
(parted)

gdisk 에서 공간을 분할하는 것은 fdisk 공간 분할 유틸리티를 사용해본 사용자들에게는 이미 익숙하기 때문에 간단합니다. gdisk를 시작한 후 초기 메뉴에서 n(새로 만들기)를 입력한 후, (필요하다면) 시작, 끝 섹터를 입력하고, 공간 형식을 EFI 시스템 파티션으로 만들기 위해 EF00로 입력하십시오.

젠투 설치 절차를 이미 따른 사용자라면 이미 적당한 공간 분할 설정을 끝냈을겁니다.

Open Firmware (IEEE 1275) on PowerPC

Install on encrypted partition

If the whole disk is encrypted, including /boot, extra steps need to be taken, to allow GRUB to decrypt and mount the device.

The device-mapper USE flag needs to be set when emerging thee GRUB package. Then the sys-fs/cryptsetup package needs to be installed. The partition needs to be encrypted as luks1 partition type.

After installing GRUB on the device, depending on the way the kernel is setup, initramfs might need to be modified in order for the system to boot completely. If a distribution kernel is installed, Dracut will be installed on the system as well and can be used to finish the configuration.

설정

GRUB2 설정에 중요한 두가지 부분이 있습니다:

주 설정 파일

grub-mkconfig 스크립트는 grub 설정을 만들 때 사용합니다. /etc/grub.d/*에 있는 설정 파일과 /etc/default/grub 설정 파일에서 함께 사용하여 최종적으로 GRUB2 자체에서 사용하는 유일한 설정 파일 /boot/grub/grub.cfg를 만듭니다.

파일 형식 편집 필요? 설명
/usr/sbin/grub-mkconfig POSIX 쉘 스크립트 No sys-boot/grub:2 꾸러미의 일부로 설치합니다. 아래 설명한 파일을 설정한 후 이 스크립트를 실행하여 /boot/grub/grub.cfg 파일을 만듭니다.
/boot/grub/grub.cfg GRUB2 쉘 스크립트 No grub-mkconfig에서 만든 파일입니다. 이 파일은 GRUB2의 내장 스크립트 해석기로 처리하며 모든 POSIX 명령 또는 문법을 지원할 필요가 없습니다. 지원 기능에 대해서는 GRUB 설명서의 스크립팅 참고서 를 참고하십시오. 이 파일을 수정하면 다음에 grub-mkconfig를 더 이상 실행할 수 없음을 참고하십시오.
/etc/grub.d/* POSIX 쉘 스크립트 Maybe 실행 비트 세트를 지닌 /etc/grub.d/* 에 있는 각 스크립트는 순차적으로 처리하며, 표준 출력 결과는 최종적으로 /boot/grub/grub.cfg 파일(또는 grub-mkconfig 명령의 -o 옵션에 설정한 파일)을 구성하려 합칩니다. 이 스크립트는 현재 시스템 쉘을 활용하기 때문에 어떤 지원 문법이라도 활용할 수 있습니다. 이상적으로 POSIX 호환 스크립트여야하며 출력 결과 스크립트는 GRUB2 해석기 문법에 맞아야 합니다. 스크립트 동작을 멈추거나 추가해야 할 때가 있습니다. 예를 들면, 자동으로 만들 수 없는 메뉴 항목을 추가할 경우입니다.
/boot/grub/custom.cfg GRUB2 쉘 스크립트 Maybe /etc/grub.d/41_custom 스크립트가 있을 경우 부팅할 때 이 파일을 참조하여 읽습니다. 이 파일은 추가 항목 및 명령을 추가하는 곳이며, grub.cfg 파일을 다시 만들 필요가 없습니다.
/etc/default/grub POSIX 쉘 스크립트 Yes 대부분 이 파일은 직접 수정해야 하는 유일한 파일입니다. 주로 동작하는 설정 파일을 /etc/grub.d에 만들기 위해 주로 스크립트에서 변수값 할당에 활용합니다. 지원 변수는 GRUB 설정 변수 또는 공식 참고서를 참고하십시오.

| /usr/sbin/grub-mkconfig || POSIX shell script || style="background-color: #F2DEDE; color: black; vertical-align: middle; text-align: left; " class="cell-no" | No || Installed as part of the sys-boot/grub:2 package. Run this script to generate /boot/grub/grub.cfg after configuring the files described below. |-

| /boot/grub/grub.cfg || GRUB shell script || style="background-color: #F2DEDE; color: black; vertical-align: middle; text-align: left; " class="cell-no" | No || The file generated by grub-mkconfig. This file is evaluated by GRUB's built-in script interpreter and doesn't necessarily support all POSIX commands or syntax. See the scripting reference in the GRUB manual for supported features. Be aware that modifications to this file won't persist to the next time grub-mkconfig is run. |-

| /etc/grub.d/* || POSIX shell scripts || style="background: #FFF176; color: black; vertical-align: middle; text-align: left; " class="cell-partial" | Maybe || Each script under /etc/grub.d/* that has its execute bit set is evaluated in sequence, and the stdout is concatenated to form the final /boot/grub/grub.cfg (or whatever file is given to the grub-mkconfig -o option). These scripts use the current system shell and therefore can use any supported syntax. Ideally they should be POSIX-compatible scripts, and the output script must be compatible with the GRUB interpreter. It may be necessary to disable or add scripts. For instance, to add menu items that couldn't be automatically generated. |-

| /boot/grub/custom.cfg || GRUB shell script || style="background: #FFF176; color: black; vertical-align: middle; text-align: left; " class="cell-partial" | Maybe || The /etc/grub.d/41_custom script will reference this file to be read in at boot time if it exists. This file provides a place to add additional entries or commands and does not require regeneration of the main grub.cfg file. |-

| /etc/default/grub || POSIX shell script || style="background-color: #DFF0D8; color: black; vertical-align: middle; text-align: left; " class="cell-yes" | Yes || In most cases this is the only file that should be modified directly. It is mainly used to assign variables used by the scripts in /etc/grub.d to generate a working configuration file. See GRUB configuration variables or the official reference for supported variables. |-

|}

GRUB2는 관리자가 부팅 옵션 설정을 (GRUB LegacyLILO 처럼) 직접 관리할 필요가 없습니다. 대신 grub-mkconfig 명령으로 자체 설정 파일(/boot/grub/grub.cfg)을 만들 수 있습니다. 이 유틸리티는 /etc/grub.d/ 의 스크립트와 /etc/default/grub 설정을 활용합니다.

경고
grub-mkconfig 유틸리티는 소프트웨어 RAID를 사용중이라면 제대로 동작하지 않습니다. /etc/grub.d/에서 직접 스크립트를 설정해야 하며, 설정하지 않으면 설치하고 나서는 시스템이 부팅할 수 없는 상태로 남습니다.

하나 이상의 설정을 수정한 후, grub-mkconfig 유틸리티에 -o 옵션을 붙여 /boot/grub/grub.cfg 출력 파일(GRUB2 기본 출력 위치)을 가리켜 실행하십시오:

root #grub-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.3.0-gentoo
done

grub-mkconfig 유틸리티를 호출할 때마다 새 설정 파일을 만듭니다.

경고
grub-mkconfig 가 찾은 항목을 알려주지 않으면 어떤 항목도 없는거나 마찬가집니다. 이 경우 GRUB2 은 시스템을 다시 시작할 때 부팅 선택 항목을 제공하지 않아 일이 까다로워질 수 있으며, 문제를 해결하는데 시간을 까먹습니다. 시스템을 다시 시작하기 전에 기대하던대로 출력이 나오는지 확인하십시오.

설정 매개 변수

/etc/default/grub에 있는 다음 변수는 GRUB2를 동작하도록 설정하는 일반적인 변수입니다:

변수 설명 기본값
GRUB_DEFAULT 부팅 과정에서 선택할 기본 메뉴 항목을 정의합니다. 인덱스 번호, 메뉴 제목, 또는 "saved"가 값이 될 수 있습니다. 첫번째로 발견한 항목이 기본값입니다.
GRUB_TIMEOUT 기본 메뉴 항목으로 부팅하기 전 (초 단위로) 기다립니다. 0 값 설정은 바로 부팅을 의미하며, -1 은 사용자의 입력이 들어오기 전까지 계속 기다림을 의미합니다. 기본값은 5초입니다.
GRUB_CMDLINE_LINUX 모든 리눅스 메뉴 항목의 커널 명령 줄에 전달할 매개변수입니다. 이를 테면, 최대 절전 기능을 지원하려면, GRUB_CMDLINE_LINUX="resume=/dev/sdXY" 줄을 추가하고 /dev/sdXY 부분에는 스왑 파티션을 넣습니다.
GRUB_CMDLINE_LINUX_DEFAULT 비 복구 리눅스 메뉴 항목의 커널 명령줄에 전달할 매개변수입니다.
GRUB_DEVICE 초기 루트 장치(예: 커널의 root= 매개 변수) 입니다. grub-mkconfig 명령의 루트 장치 자동 감지 결과 설정을 덮어쓰려면 이 항목을 설정하십시오. 예를 들어, GRUB_DEVICE=/dev/ram0 설정은 커널 명령 줄에서 root=/dev/ram0 로 설정하도록 강제합니다.

| GRUB_DEFAULT | Defines the default menu entry selected on boot. May be a numeric index, a menu title, or "saved". | Defaults to first detected entry. |-

| GRUB_TIMEOUT | Delay (in seconds) before booting default menu entry. Set to 0 to boot immediately or -1 to wait indefinitely. | The default is 5 seconds. |-

| GRUB_CMDLINE_LINUX | Parameters to be passed on the kernel command line for all Linux menu entries. For instance, to support hibernation, users will need to add GRUB_CMDLINE_LINUX="resume=/dev/sdXY" with /dev/sdXY being the swap partition. | |-

| GRUB_CMDLINE_LINUX_DEFAULT | Parameters to be passed on the kernel command line for non-recovery Linux menu entries. | |-

| GRUB_DEVICE | The initial root device (i.e. the kernel's root= parameter). Set this to override the grub-mkconfig command's root device auto-detection. For example, GRUB_DEVICE=/dev/ram0 will force root=/dev/ram0 to be used in the kernel command line. | |-

|}

좀 더 완벽한 내용은 GRUB 설정 변수en 하위 페이지를 참고하십시오.

매개변수를 수정했으면, grub-mkconfig 명령으로 GRUB2 설정 파일을 다시 만드십시오.

설정 스크립트 활성화/활성 해제

/etc/grub.d/ 디렉터리에는 grub-mkconfig에서 grub.cfg 파일을 만들때 사용하는 스크립트가 있습니다. 기본적으로 이 디렉터리의 내용은 다음과 비슷해야 합니다:

user $ls /etc/grub.d/
00_header  10_linux  20_linux_xen  30_os-prober  40_custom  41_custom README

GRUB2는 실행하도록 표시한 설치 스크립트를 사용(기본적으로 이미 다 갖춰져 있음)합니다. 일부 스크립트의 사용 여부를 해제하려면, chmod 명령을 사용하여 간단하게 스크립트 파일 권한의 실행 비트를 제거하십시오. 다음 예제에서는 모든 스크립트 중 00_header10_linux 스크립트의 실행 여부를 비활성화합니다:

root #chmod -x /etc/grub.d/{20_linux_xen,30_os-prober,40_custom,41_custom}

스크립트를 수정한 후(또는 실행 비트를 제거한 후), grub-mkconfig 명령으로 GRUB 설정 파일을 다시 만드십시오.

설정 스크립트 다루기

일부 기능이나 GRUB2 기능은 설정 스크립트를 수정할 때 살펴볼 수 있습니다. 예를 들어 FreeBSD와 듀얼 뷰팅을 하려 할 때, 기능이 동작하도록 하려면 다음 처리 절차가 필요합니다.

/etc/grub.d/40_custom 스크립트를 다음 내용으로 바꾸십시오:

파일 /etc/grub.d/40_custom듀얼 부팅 추가
'"`UNIQ--pre-0000001E-QINU`"'

/dev/sda1 또는 (hd0,1)은 FreeBSD가 있는 공간입니다. 일반 UFS 설치를 FreeBSD 공간 용도로 사용한다면 /dev/sda1 은 컨테이너(논리 공간)가 됩니다. 컨테이너에는 스왑 공간과 루트 공간이 있습니다. ls -la /etc/grub.d/40_custom를 실행하여 40_custom 스크립트가 실행 가능한지 확인하십시오. 만약 실행 비트를 설정하지 않았다면 chmod u+x 40_custom 명령으로 설정하십시오.

참고
GRUB Legacy의 분할 영역 번호 부여에 익숙한 사용자는 GRUB2의 분할 영역 시작 번호가 0이 아닌 1임을 숙지해야 합니다.

다음 grub-install 명령으로 GRUB2를 설치하고 GRUB2의 설정 파일을 업데이트하십시오:

root #grub-install /dev/sda
root #grub-mkconfig -o /boot/grub/grub.cfg

외부 기능

GRUB2는 강력한 부트로더로 만들어주는 수많은 기능이 있습니다. 다음과 같은 기능을 지원합니다:

  • UEFI 플랫폼에서 부팅.
  • GPT 방식으로 공간을 나눈 드라이브에서 MBR 혼합 방식을 사용하지 않는 부팅(MBR 혼합 방식은 호환성, 이식성 측면에서 원하는 대로 활성화할 수 있음).
  • btrfs로 포맷한 /boot 공간 부팅.
  • btrfs RAID 셋에서 마운트 설정을 하지 않고도 initramfs 없이 바로 부팅.
  • (LVM2 와 같은) 논리 볼륨 관리자에서 바로 부팅.
  • DM-RAID 지원 부팅(RAID 0, 1, 4, 5, 6, 9, 10).
  • 암호화 장치(LUKS) 부팅.

일부 몇가지 기능을 자세히 설명하도록 하겠습니다.

체인 로딩

GRUB2에서는 GRUB Legacy에 비하면 확실히 체인 로딩 모드가 바뀌었습니다. 다른 부트 로더를 체인 로딩하려면, chainloader 옵션을 사용하십시오.

파일 /etc/grub.d/40_custom다른 부트로더 체인 로딩
'"`UNIQ--pre-00000021-QINU`"'

체인 로딩에 대한 더 많은 내용은 체인 로딩en 하위 페이지를 살펴보십시오.

Password protection of GRUB menu

To secure GRUB so it is not possible for anyone to change boot parameters or use the command line, add a user/password combination to GRUB's configuration files. The program grub-mkpasswd-pbkdf2 generates password hashes for GRUBː

user $grub-mkpasswd-pbkdf2
Password:
Reenter password:
</div>

<div lang="en" dir="ltr" class="mw-content-ltr">
PBKDF2 hash of your password is grub.pbkdf2.sha512.10000.9CA4611006FE96BC77A...

Then, add the following toː

파일 /etc/grub.d/35_auth:
# Grub user
echo 'set superusers="<username>"'
# Grub password
echo 'password_pbkdf2 <username> <password-hash>'

The above may lock all Grub menu entries, even the default entry. In that case, to allow users to boot some menu entries without a password, see Securing the grub boot loader.

The permissions for the file need to be properly set before doing grub-mkconfig:

root #chmod 755 /etc/grub.d/35_auth

프레임버퍼 화면 사용

GRUB2에서 framebuffer 그래픽 화면을 사용하려면 GRUB에 truetype USE 플래그를 활성화 한 상태에서 다시 이머지하십시오. 글꼴 변환 유틸리티와 함께 기본 트루타입 글꼴을 설치합니다.

root #emerge --ask --newuse sys-boot/grub:2

/etc/default/grub에 있는 기본 GRUB2 설정 파일 설정을 진행하십시오. 예를 들면:

파일 /etc/default/grub프레임버퍼 설정
# Set resolution and color depth
GRUB_GFXMODE=1366x768x32
 
# Keep resolution when loading the kernel
GRUB_GFXPAYLOAD_LINUX=keep
 
# Set a background image
GRUB_BACKGROUND="/boot/grub/bg.png"
 
# Use a custom font, converted using grub-mkfont utility
GRUB_FONT="/boot/grub/fonts/roboto.pf2"

HiDPI displays

On modern displays with high DPI ("HiDPI"), e.g. UHD (3840x2160), the standard font will look very small. If you like to have the same font as the kernel, Terminus can be used, which resembles a BIOS built-in textmode font.

To select this font in-kernel, CONFIG_FONT_TER16x32 has to be enabled.

커널 Kernel compiled-in fonts
Library routines  --->
      [*] Select compiled-in fonts
      [*] Terminus 16x32 font (not supported by all drivers)

The same font is available as media-fonts/terminus-font, which can then be used for GRUB as well.

root #emerge --ask media-fonts/terminus-font
root #grub-mkfont -s 32 -o /boot/grub/fonts/terminus32b.pf2 /usr/share/fonts/terminus/ter-u32b.otb

In the above example the filename chosen for grub-mkfont output is terminus32b.pf2. The font's path has to be accessible to GRUB during boot, so it should reside in the same mount point as GRUB does; this example uses /boot/grub/fonts. The font then has to be set as GRUB_FONT in /etc/default/grub in order to be used.

파일 /etc/default/grubFramebuffer related settings
# Use a custom font, converted using grub-mkfont utility
GRUB_FONT="/boot/grub/fonts/terminus32b.pf2"

Updating the GRUB configuration file grub.cfg will then activate the configuration with the new font.

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

문제 해결

GRUB 문제 해결 내용을 찾아보려면 문제 해결en 하위 게시글을 참고하십시오.

대부분의 문제는 공간 배치를 올바르게 처리했는지 확인하여 해결할 수 있습니다. 디스크의 첫번째 공간 이전에 충분한 공간을 두었는지 확인하거나, 추가적으로 BIOS 부트 파티션이 존재하는지 확인하십시오. 또한 grub-mkconfig 명령으로 /boot/grub/grub.cfg 파일을 제대로 만들었거나, 개별 메뉴 항목을 제대로 만들었는지 검증하십시오.

os-prober not running

When running the grub-mkconfig command, os-prober is not running as expected, even though it is installed:

root #grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.11.14-gentoo-x86_64
Found initrd image: /boot/amd-uc.img /boot/initramfs-5.11.14-gentoo-x86_64.img
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done

This can be corrected by setting the GRUB_DISABLE_OS_PROBER variable to false in /etc/default/grub file.

파일 /etc/default/grub
GRUB_DISABLE_OS_PROBER=false

Upon the next run, grub-mkconfig should find additional bootable partitions:

root #grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.11.14-gentoo-x86_64
Found initrd image: /boot/amd-uc.img /boot/initramfs-5.11.14-gentoo-x86_64.img
Warning: os-prober will be executed to detect other bootable partitions.
It's output will be used to detect bootable binaries on them and create new boot entries.
Found Windows Boot Manager on /dev/nvme0n1p2@/efi/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for UEFI Firmware Settings ...
done

Motherboard firmware not finding the .EFI file

Some especially older (pre-2020) motherboards from certain manufacturers seem to only support one location for the .EFI file in the EFI System Partition (ESP): the fallback or removable media path. If this seems to be the case, simply move GRUB's default file to the /efi/boot/ location. First, make sure the ESP is mounted. Presuming the ESP is mounted at /boot/efi (as suggested in the Handbook), execute:

root #mkdir -p /boot/efi/efi/boot
root #cp /boot/efi/efi/gentoo/grubx64.efi /boot/efi/efi/boot/bootx64.efi

On a 32-bit EFI implementation use bootia32.efi instead:

root #cp /boot/efi/efi/gentoo/grubia32.efi /boot/efi/efi/boot/bootia32.efi

The removable parameter can be used with grub-install command to generate this file automatically:

root #grub-install --efi-directory=/boot/efi --removable
Installation finished. No error reported.

This should aid the motherboard firmware in loading the GRUB executable. Reboot the system to see if the firmware now correctly loads GRUB.

chroot 환경의 os-prober와 UEFI

sys-boot/os-prober 유틸리티는 마이크로소프트 윈도우 같은 대안 설치 운영체제를 찾는데 사용합니다. 제대로 활용하려면 EFI 시스템 분할 영역 시험을 목적으로 환경 설정에 들어있는 udev 정보를 찾아봐야합니다.

이 명령을실 행하여 필요한 파일을 호스트 환경에 제시하십시오(예제에서는 핸드북에서와 같이 젠투를 /mnt/gentoo 디렉터리에 마운트했습니다):

root #mkdir -p /mnt/gentoo/run/udev
root #mount -o bind /run/udev /mnt/gentoo/run/udev
root #mount --make-rslave /mnt/gentoo/run/udev

Installing a new kernel

Whenever a new kernel is installed, GRUB must be reconfigured to recognize it. This can be done using grub-mkconfig, as shown below, or can be done manually.

참고
Make sure the /boot partition is mounted for this step.
root #grub-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/kernel-3.3.8-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-3.3.8-gentoo
Found linux image: /boot/kernel-3.2.12-gentoo
Found initrd image: /boot/initramfs-genkernel-x86_64-3.2.12-gentoo
done

Note that GRUB only needs to be reconfigured, not reinstalled to the boot drive's Master Boot Record (MBR). On the other hand, when GRUB itself has been upgraded it does need to be reinstalled on the boot drive, but usually does not need to be reconfigured.

Automatic GRUB reconfiguration

If the package sys-kernel/installkernel-gentoo is installed and the USE flag grub is set, then on every installation of a kernel, grub-mkconfig will run automatically.

추가 참조

  • 체인 로딩 에서는 GRUB2에서 다른 부트로더로 부팅하는 방법을 설명합니다. 듀얼 부팅 시스템을 꾸리거나 GRUB2에서 ISO 파일을 설정해야 할 경우에 읽어보셔야 합니다.
  • 고급 저장 장치 에서는 소프트웨어 RAID, 논리 볼륨, 암호화 파일 시스템과 같은 좀 더 고급 기술을 사용한 저장장치를 사용하는 경우, GRUB2를 설치하고 사용할 때 필요한 단계를 문서화했습니다.
  • 설정 변수에서는 /etc/default/grub 파일 같은 곳에서 사용하는 GRUB2 설정 변수의 완전한 목록을 문서화했습니다.
  • 문제 해결에서는 일반적인 GRUB2 오류의 목록을 (해결책과 함께) 나타냅니다.
  • 혼합형 분할 테이블

외부 자료

더 많은 정보는 다음 링크를 보십시오:

References