
OS: Ubuntu 20.04.3 LTS
Kernel: Linux 5.13.0-27-generic
Architecture: x86-64


/boot
├── efi
│ └── EFI
│ ├── BOOT
│ │ └── BOOTAA64.EFI
│ └── ubuntu
│ ├── grubaa64.efi <- 부트로더 파일
│ └── grub.cfg <- 부트로더 설정 파일
└── grub
└── grub.cfg <- 위의 부트로더 설정 파일에 담긴 uuid, root(hd?,gpt?) 를 읽어서 로드함
└── arm64-efi
└── *.mod <- grub에서 탑재하는 모듈들
/boot/grub/grub.cfg 이다./boot/efi/EFI/ubuntu/grub.cfg: 부트로더 설정 파일
/boot/grub/grub.cfg : 실제 boot될 때 읽어오는 grub 설정 파일
/boot/grub/arm64-efi(본인 컴 아키텍처): 탑재가능한 grub mod 파일들
/etc/'defaults'/grub 파일을 수정하는 식으로 해야한다./boot/grub/grub.cfg에서 menuentry를 읽어온다.$ awk -F\' '/menuentry / {print $2}' /boot/grub/grub.cfg 
/etc/default/grub에 GRUB_DEFAULT=saved 설정$ sudo vi /etc/default/grub

GRUB_DEFAULT=0이 아니여야 이 파일이 적용됨Advanced options for Ubuntu > Ubuntu, with Linux 5.13.0-25-generic5.13.0-25커널을 사용할 것임

$ grep submenu /boot/grub/grub.cfg, $ grep gnulinux /boot/grub/grub.cfg
'>' 로 연결
gnulinux-advanced-732910d6-ddae-4a95-ab9e-9f5c9edc555a>gnulinux-5.13.0-25-generic-advanced-732910d6-ddae-4a95-ab9e-9f5c9edc555a
/etc/default/grub에 아래와 같이 설정
sudo update-grub로 /etc/default/grub 내용을 /boot/grub/grub.cfg에 적용$ sudo update-grub

$ grub-set-default [OPTION] MENU_ENTRY
/etc/default/grub에 GRUB_DEFAULT=saved 설정GRUB_DEFAULT=0만 아니면 grub.cfg를 /etc/default/grub로서 열 수 있음




mount -o rw,remount /
ls /home

passwd <username>
/etc/default/grub
$ grub-mkconfiggrub-mkconfig 기능grub-mkconfig를 통해 GRUB 환경 설정 파일인 <grub_name>.cfg 파일을 만들 수 있다.40_custom, 41_custom 스크립트를 custom setting하여 custom grub를 만들어낸다.grub-mkconfig 명령을 사용한다.$ sudo apt install grub-common$ sudo grub-mkconfig -o /boot/grub/grub.cfg 명령$ sudo grub-mkconfig -o /boot/grub/grub.cfg/etc/default/grub가 자동으로 input으로 먹힌다.

grub2-mkconfig 명령어를 사용할 것!/etc/grub.d
40_custom과 41_custom을 제공한다.40_custom: 편집할 수 있는 스크립트.. 이지만, 아마도 가장 언정성이 떨어질 것.
41_custom: 더 간단하다. GRUB가 시작될 때, custom.cfg를 로딩하는 명령이다.
설정 파일을 직접 편집하는 두 가지 옵션은 많이 사용되지 않는다.
우분투는 메모리 테스터 부트 옵션(memtest86+)를 설정에 추가한다.
/boot/grub//etc/grub.d/etc/default/grub 에 저장/boot/grub/grub.cfg 에 포함된 정보를 빌드한다gparted와 같은 툴들로 생성할 수 있다.bios_grub 플래그로 식별된다.efi/microsoft, efi/apple, efi/grub와 같은 서브 디렉토리를 보유하고 있다..efi확장자를 가지며, 이 서브 디렉토리들 중 하나에 다른 지원 파일들과 같이있다.$ grub-installgrub2-common$ sudo apt install grub2-common# grub-install [OPTION...] [OPTION] [INSTALL_DEVICE]
Option:
--compress=no|xz|gz|lzo
compress GRUB files [optional]
--dtb=FILE
embed a specific DTB
-d, --directory=DIR
use images and modules under DIR [default=/usr/lib/grub/<platform>]
--fonts=FONTS
install FONTS [default=unicode]
-k, --pubkey=FILE
embed FILE as public key for signatrue checking
--locale-directory=DIR use translations under DIR
[default=/usr/share/locale]
--locales=LOCALES
install only LOCALES [default=all]
--modules=MODULES
pre-load specified modules MODULES
--themes=THEMES
install THEMES [default=starfield]
-v, --verbose
print verbose messages.
--allow-floppy
make the drive also bootable as floppy (default for fdX devices). May break on some
BIOSes.
--boot-directory=DIR
install GRUB images under the directory DIR/grub instead of the boot/grub directory
--bootloader-id=ID
the ID of bootloader. This option is only available on EFI and Macs.
--core-compress=xz|none|auto
choose the compression to use for core image
--disk-module=MODULE
disk module to use (biosdisk or native). This option is only available on BIOS
target.
--efi-directory=DIR
use DIR as the EFI System Partition root.
--force
install even if problems are detected
--force-file-id
use identifier file even if UUID is available
--label-bgcolor=COLOR
use COLOR for label background
--label-color=COLOR
use COLOR for label
--label-font=FILE
use FILE as font for label
--macppc-directory=DIR use DIR for PPC MAC install.
--no-bootsector
do not install bootsector
--no-extra-removable
Do not install bootloader code to the removable media path. This option is only
available on EFI.
--no-nvram
don't update the `boot-device'/`Boot*' NVRAM variables. This option is only
available on EFI and IEEE1275 targets.
--no-rs-codes
Do not apply any reed-solomon codes when embedding core.img. This option is only
available on x86 BIOS targets.
--no-uefi-secure-boot
do not install an image usable with UEFI Secure Boot, even if the system was
currently started using it. This option is only available on EFI.
--product-version=STRING
use STRING as product version
--recheck
delete device map if it already exists
--removable
the installation device is removable. This option is only available on EFI.
-s, --skip-fs-probe
do not probe for filesystems in DEVICE
--target=TARGET
install GRUB for TARGET platform [default=i386-pc]; available targets:
arm-coreboot, arm-efi, arm-uboot, arm64-efi, i386-coreboot, i386-efi,
i386-ieee1275, i386-multiboot, i386-pc, i386-qemu, i386-xen, i386-xen_pvh,
ia64-efi, mips-arc, mips-qemu_mips, mipsel-arc, mipsel-loongson, mipsel-qemu_mips,
powerpc-ieee1275, riscv32-efi, riscv64-efi, sparc64-ieee1275, x86_64-efi,
x86_64-xen
--uefi-secure-boot
install an image usable with UEFI Secure Boot. This option is only available on
EFI and if the grub-efi-amd64-signed package is installed.
-?, --help
give this help list
--usage
give a short usage message
-V, --version
print program version
Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.
INSTALL_DEVICE must be system device filename. grub-install copies GRUB images into boot/grub. On some platforms, it may also install GRUB into the boot sector.
/dev/sdc/dev/sdc1/mnt/mnt/boot/grub$ sudo grub-install --boot-directory=/mnt/boot /dev/sdc
efibootmgr 명령을 사용해, 펌웨어어에 부트 로더를 알려주는 작업을 해야한다.$ sudo grub-install --efi-directory=<efi_dir> --bootloader-id=<name>
<efi_dir>: 현재 시스템에서 'UEFI' 디렉터리가 있는 장소다. (보통은 /boot/efi/efi)/boot/efi에 마운트 되기 때문<name>efilinux를 근거로하는) 완전히 새로운 부트로더이다.체인 로딩을 하려면, GRUB 설정에서 새로운 메뉴를 생성해야 한다. 다음은 디스크의 세 번째 파티션 상에 윈도우즈를 설치하는 것에 대한 예제이다.
menuentry "Windows" {
insmod chain
insmod ntfs
set root=(hd0,3)
chainloader +1
}
chainloader +1: 첫 번째 섹터에 있는 것이 무엇이든, 그것을 로딩하라고 지시하는 것파일을 직접 로드할 수 도있다. 다음은 io.sys MS-DOS 로더를 로딩하는 설정이다.
menuentry "DOS" {
insmode chain
insmod fat
set root=(hd0,3)
chainloader /io.sys
}
shift 키를 잠시 누르고 있으면, GRUB가 뜬다.
e키를 누르면, 디폴트 부트 옵션에 대한 부트로더 설정 명령들을 확인한다.
GRUB 내부 명령이다.insmod 명령을 갖고 있으며, 리눅스 커널과는 완전히 별개이다.root=hd0,gpt2'로 set된다. (GRUB 전용 장치이다)hd0으로 지정하고 그 뒤부터는 hd1.. 로 지정한다. 즉, hd0은 유동 적이고 모든 파티션에서 UUID를 찾는다.
linux /boot/vmlinuz-5.4.0-66-generic root=UUID ...가 있다.linux='load할 리눅스 커널 이미지 위치', GRUB는 이 이미지 파일을 'GRUB의 root'에서 로드root=UUID.... ro로 rootfs를 UUID로 설정하며, ro 옵션으로 마운트한다.quiet, splash 등 옵션을 줄 수 있다./dev/sda2)/proc/cmdline)-1.jpg)
initrd /boot/initrd.img-5.4.0-66-generic
Ctrl + c를 누르면, GRUB cmd 라인에 들어갈 수 있다.
ls 명령을 입력하면, (proc) (hd0) (hd0,gpt2) (hd0,gpt1) ...proc 디바이스, 파일 시스템과 hd0, gptX라는 suffix가 붙는다. 이는 hd0이 gpt파티션 테이블을 사용한다는 말이다.
ls -l 명령은 좀 더 자세히 보여준다.proc, Filesystem: procfshd0,gpt2, Filesystem: ext*, UUID= (/dev/sdb2)hd0,gpt1, Filesystem: fat, UUID= (/dev/sda1)
root= hd0,gpt2 로 설정되어 있음ls ($root) = root 변수의 자세한 내용ls ($root)/= root 변수내 있는 파일들ls는 GRUB의 ls명령임ls ($root)/boot 에는 커널 이미지가 있다.
set 명령을 사용하면, 현재 GRUB의 변수들이 출력된다.
prefix 변수에는 $(root)/boot/grub로 셋 되어 있다.GNU/Linuxfind /vmlinuz 같은 것으로 찾을 수 있다.grub> kernel /vmlinuz root=/dev/hda1 [Kernel Parameters]
grub> initrd /initrd
grub> boot