Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Examendoelen in dit hoofdstuk
- Een systeem altijd in een gekozen target laten opstarten
- De bootloader van het systeem aanpassen
Understand systemd targets
A target is a group of units that brings the system to a state. At boot, systemd starts the default target and everything it needs.
| Target | Use |
|---|---|
graphical.target | Desktop login (includes multi-user) |
multi-user.target | Normal server, text login, network, services |
rescue.target | Repair: single user, root login, few services, file systems mounted |
emergency.target | Minimal: root file system read-only, almost nothing started |
poweroff.target, reboot.target | Turn off / restart |
Look inside a target
A target unit file has little content. The real list of services comes from wants: links in TARGET.target.wants/ folders.
systemctl cat multi-user.target
ls /etc/systemd/system/multi-user.target.wants/
systemctl list-dependencies multi-user.target | head -20[Unit]
Description=Multi-User System
Documentation=man:systemd.special(7)
Requires=basic.target
Conflicts=rescue.service rescue.target
After=basic.target rescue.service rescue.target
AllowIsolate=yesNotitie
AllowIsolate=yes means you can switch to this target with isolate. Only targets that are a full system state have it.
Understand wants
systemctl enable does nothing more than create a link in the .wants folder of the target named in the [Install] section (WantedBy=).
Switch to another target now
systemctl isolate TARGET starts that target and stops everything that is not part of it. Use it to go to text mode or rescue mode without a reboot.
Set the default target
The default target is a link /etc/systemd/system/default.target. set-default changes it.
systemctl get-default
graphical.target
systemctl set-default multi-user.target
Removed '/etc/systemd/system/default.target'.
Created symlink '/etc/systemd/system/default.target' → '/usr/lib/systemd/system/multi-user.target'.Examentip
"The system must boot into text mode" = systemctl set-default multi-user.target. Check after a reboot with systemctl get-default.
Understand GRUB 2
GRUB 2 is the first program after the firmware (BIOS or UEFI). It shows the boot menu, loads the kernel and the initramfs, and passes the kernel command line.
- RHEL uses BLS (Boot Loader Specification): one small file per kernel in
/boot/loader/entries/. - The main config
grub.cfgis generated — do not edit it by hand. - At the boot menu, press
eto edit an entry for one boot only,Ctrl+Xto boot it.
Know the GRUB 2 configuration files
You change settings in /etc/default/grub (defaults for all kernels) or with grubby (per kernel). grub2-mkconfig writes the generated config.
| File | Purpose |
|---|---|
/etc/default/grub | Your settings: timeout, default kernel options (GRUB_CMDLINE_LINUX) |
/etc/grub.d/ | Scripts that build grub.cfg |
/boot/grub2/grub.cfg | Generated config (BIOS and UEFI on RHEL 9+/10) |
/boot/loader/entries/*.conf | One entry per kernel (BLS) |
/boot/efi/EFI/redhat/grub.cfg | On UEFI: small stub that points to /boot/grub2/grub.cfg |
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=trueChange the default boot options
Add or remove kernel options for all kernels with grubby, or edit /etc/default/grub and regenerate the config.
- Change options with grubby (applies to the BLS entries right away).
- Or change the timeout or the default command line in
/etc/default/gruband regenerate. When you changedGRUB_CMDLINE_LINUX, add--update-bls-cmdline, or the kernel entries keep their old options.vim /etc/default/grub grub2-mkconfig -o /boot/grub2/grub.cfg grub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdline - Choose the default kernel.
Examentip
Tasks like "remove rhgb and quiet" or "set the boot timeout to 10 seconds" need GRUB changes. After /etc/default/grub changes, always run grub2-mkconfig -o /boot/grub2/grub.cfg (with --update-bls-cmdline for command line changes) — or use grubby, which changes the entries directly. Check with cat /proc/cmdline after a reboot.
Op het werk
Protect the boot menu with a password so nobody at the console can edit kernel options: grub2-setpassword.
Remember the main points
The most important facts of this chapter, in short.
- A target is a system state:
multi-user.target(text, network),graphical.target(desktop),rescue.target,emergency.target. systemctl get-defaultshows andsystemctl set-default NAMEsets the target for the next boots.systemctl isolate NAMEchanges to another target now (only targets withAllowIsolate=yes).- Wants in
/etc/systemd/system/TARGET.wants/decide which units a target starts (made bysystemctl enable). - GRUB 2 starts the kernel; default settings are in
/etc/default/grub, boot entries are BLS files in/boot/loader/entries/. - Change kernel options for all kernels with
grubby --update-kernel=ALL --args="…"(or--remove-args), or edit/etc/default/gruband rungrub2-mkconfig -o /boot/grub2/grub.cfg --update-bls-cmdline. - At the GRUB menu press e to change the kernel line one time; Ctrl+X boots it.
Learn the key terms
The words of this chapter in simple English.
| Term | Meaning |
|---|---|
| Target | A group of units for one system state. |
| Default target | The target the system boots into. |
| Isolate | Stop everything not needed and start a target. |
| Wants | A soft dependency: start this too if you can. |
| GRUB 2 | The boot loader of RHEL. |
| BLS | Boot Loader Specification: one small file per boot entry. |
| Kernel argument | An option given to the kernel at boot, like quiet or rd.break. |
| grubby | A tool to change boot entries and kernel arguments. |
Check what you learned
Think about the answer first, then open it.
1How do you make the system always boot into text mode?
2How do you switch to the desktop now, without a reboot?
3Which target is the smallest one that still mounts the file systems?
rescue.target (emergency.target mounts only / read-only).
4How do you remove rhgb quiet from all kernels?
5How do you change the GRUB timeout to 10 seconds?
Set GRUB_TIMEOUT=10 in /etc/default/grub, then grub2-mkconfig -o /boot/grub2/grub.cfg.
6How do you add a kernel option for only one boot?
Press e at the GRUB menu, add it to the linux line, press Ctrl+X.
7Which command shows the current default kernel?
8Where are the boot entries of RHEL 10?
In /boot/loader/entries/ (BLS files).