Master Linux Boot: From GRUB to systemd on CentOS 5/6/7
This guide explains the complete boot sequence of CentOS 5, 6, and 7, covering GRUB stages, initrd, rc scripts, chkconfig, and the transition to systemd with its units, targets, and systemctl commands, providing practical commands and configuration examples.
grub and boot
CentOS 5/6 boot process
GRUB
CentOS 7 boot process
CentOS 5/6 Boot Process
initrd / initramfs
Usually stored in the /boot directory as files ending with .img, initrd is a small root filesystem image containing essential modules needed before the kernel can mount the real root filesystem.
rc
In the inittab file there is a line si::sysinit:/etc/rc.d/rc.sysinit which passes the run‑level value to the rc script.
Below is the core part of the rc script:
# Main two loops:
for i in /etc/rc$runlevel.d/K* ; do
subsys=${i#/etc/rc$runlevel.d/K??}
[ -f /var/lock/subsys/$subsys -o -f /var/lock/subsys/$subsys.init ] || continue
check_runlevel "$i" || continue
[ -n "$UPSTART" ] && initctl emit --quiet stopping JOB=$subsys
$i stop
[ -n "$UPSTART" ] && initctl emit --quiet stopped JOB=$subsys
done
for i in /etc/rc$runlevel.d/S* ; do
subsys=${i#/etc/rc$runlevel.d/S??}
[ -f /var/lock/subsys/$subsys ] && continue
[ -f /var/lock/subsys/$subsys.init ] && continue
check_runlevel "$i" || continue
if [ "$do_confirm" = "yes" ]; then
confirm $subsys
rc=$?
if [ "$rc" = "1" ]; then
continue
elif [ "$rc" = "2" ]; then
do_confirm="no"
fi
fi
update_boot_stage "$subsys"
[ -n "$UPSTART" ] && initctl emit --quiet starting JOB=$subsys
if [ "$subsys" = "halt" -o "$subsys" = "reboot" ]; then
export LC_ALL=C
exec $i start
fi
$i start
[ -n "$UPSTART" ] && initctl emit --quiet started JOB=$subsys
doneThe script selects the appropriate run‑level, then stops services prefixed with K and starts those prefixed with S.
chkconfig updates the services enabled for each run‑level.
chkconfig [--add | --del] name # add or delete a service
chkconfig --list name # list service status per run‑level
chkconfig [--level levels] [--type type] [--no-redirect] name <on|off|reset|resetpriorities> # set service state for a specific run‑levelGRUB
After BIOS reads the boot order, the MBR (first 446 bytes) contains the boot loader, which in CentOS is typically GRUB.
GRUB consists of three stages: stage1 (in the MBR), stage1.5 (usually in /boot), and stage2 (the full loader).
GRUB configuration file: /boot/grub/grub.conf (or /boot/grub/menu.lst as a symlink).
default=0 # default boot entry (0 = first)
timeout=5 # wait time in seconds
splashimage=(hd0,6)/boot/grub/splash.xpm.gz
hiddenmenu # hide the menu
title Fedora Core (2.6.11-1.1369_FC4)
root (hd0,6)
kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/
initrd /boot/initrd-2.6.11-1.1369_FC4.img
title WinXP
rootnoverify (hd0,0)
chainloader +1Manual boot commands in GRUB:
grub> find /PATH # locate a path
grub> root (hd0,1) # set root device
grub> kernel /vmlinux... ro # specify kernel
grub> initrd /initrd...img # specify initramfs
grub> boot # start bootingGRUB installation and repair:
grub-install --root-directory=/boot /dev/sda # write stage1 to MBRIn the GRUB console:
grub> chroot /mnt/sysimage # mount real rootfs
grub> root (hd0,1) # set boot partition
grub> setup (hd0) # write stage1 to MBRCentOS 7 Boot Process
CentOS 7 replaces the traditional init with systemd, which also manages daemons and provides many new features.
Parallel service startup with dependency ordering
On‑demand activation
Snapshot and state restoration
Cgroup resource limits
Parallel service startup and dependency
systemd groups services into units (e.g., .service, .mount, .socket, .device, .swap, .path, .target, .timer) and starts them according to declared dependencies.
On‑demand activation
Unlike init, which starts all enabled services at boot, systemd activates services only when they are needed, improving boot speed and resource usage.
Snapshot and state restoration
systemd can save the current system state as a snapshot and restore it later.
Targets
systemd replaces SysV run‑levels with targets, offering finer granularity.
SysV runlevel systemd target description
0 runlevel0.target, poweroff.target halt
1, s, single runlevel1.target, rescue.target single‑user mode
2, 4 runlevel2.target, runlevel4.target, multi-user.target multi‑user (no GUI)
3 runlevel3.target, multi-user.target multi‑user (no GUI)
5 runlevel5.target, graphical.target multi‑user with GUI
6 runlevel6.target, reboot.target reboot
emergency emergency.target emergency shellsystemd startup diagram
systemctl commands
Common systemctl usage:
systemctl show [NAME.unittype] # show status or list
systemctl status [NAME.unittype] # detailed status
systemctl list-units [--type TYPE] [--all]
systemctl list-unit-files --type TYPE [--all]
systemctl start [NAME.unittype]
systemctl stop [NAME.unittype]
systemctl restart [NAME.unittype]
systemctl reload [NAME.unittype]
systemctl enable [NAME.unittype]
systemctl disable [NAME.unittype]
systemctl isolate [NAME.target]
systemctl get-default
systemctl set-default [NAME.target]
systemctl snapshot
systemctl hibernate
systemctl suspend
systemctl hybrid-sleep
systemctl reboot
systemctl haltsystemd unit files
/etc/systemd/system.conf # systemd configuration file
/lib/systemd/system/NAME.UNIT # unit files location
/etc/systemd/system/NAME.UNIT.wants # services wanted by a target
# Example of /etc/systemd/system/ directory listing
[root@xiao ~]# ll /etc/systemd/system/
total 32
drwxr-xr-x. 2 root root 4096 Nov 21 2014 basic.target.wants
lrwxrwxrwx. 1 root root 37 Nov 21 2014 default.target -> /lib/systemd/system/multi-user.target
drwxr-xr-x. 2 root root 4096 Nov 21 2014 default.target.wants
drwxr-xr-x. 2 root root 4096 Nov 21 2014 getty.target.wants
drwxr-xr-x. 2 root root 4096 Apr 8 14:29 multi-user.target.wants
drwxr-xr-x. 2 root root 4096 Nov 21 2014 printer.target.wants
drwxr-xr-x. 2 root root 4096 Nov 21 2014 sockets.target.wants
drwxr-xr-x. 2 root root 4096 Mar 22 17:48 sysinit.target.wants
drwxr-xr-x. 2 root root 4096 Nov 21 2014 system-update.target.wants
# Switch default target manually
[root@xiao system]# rm -f default.target
[root@xiao system]# ln -s /lib/systemd/system/graphical.target default.targetSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
