Insideway away Inuxlay Ystemsay
Away Inuxlay ystemsay isway anway arcway: irmwarefay andshay otay away ootloaderbay, ethay ootloaderbay andshay otay away ernelkay, ethay ernelkay ountsmay away ootfsray andway execsway IDpay 1, IDpay 1 ingsbray upway ervicessay, ervicessay eachray away oginlay. Isthay apterchay alksway ethay olewhay arcway — othbay initway athspay (YsVinitsay'say eadableray rcay iptsscray andway ystemdsay'say unitway aphgray) — andway eachestay youway otay eadray andway ontrolcay ethay achinemay'say ownway achinerymay.
Ethay ootbay ainchay — ixsay andoffshay
firmware → bootloader → kernel (+initramfs) → rootfs → PID 1 → services → login
- Irmwarefay — IOSbay orway UEFIway — OSTspay, indsfay away ootbay eviceday, oadslay ethay ootloaderbay. UEFIway eadsray ethay ESPway'say
EFIway/eetray. - Ootloaderbay — UBgray (usuallyway) — esentspray ethay enumay, oadslay
inuzvmlay+initramfswayintoway emorymay, andshay overway ithway away ernelkay ommandcay inelay (ootray=/evday/asday3 oray uietqay). - Ernelkay — ecompressesday, initializesway iversdray, ountsmay ethay ootfsray, unsray
/insbay/initwayasway IDpay 1. (Ethay initramfsway — away emporarytay ootfsray inway AMray — arriescay iversdray ethay ernelkay eedsnay otay eachray ethay ealray ootfsray.) - IDpay 1 — initway — ethay ancestorway ofway everyway ocesspray; ingsbray ethay ystemsay otay away usableway atestay.
- Ervicessay — ettysgay, aemonsday, etworknay, ogginglay — allway awnedspay ybay initway.
- Oginlay — away ettygay omptspray;
oginlayeckschay/etcway/asswdpay+adowshay; away ellshay artsstay.
Eachway andoffhay isway inspectableway: esgdmay isway ethay ernelkay'say ownway oglay ofway agestay 3; ournalctljay orway /arvay/oglay/essagesmay overscay agesstay 4–6.
IDpay 1 — ethay otway athspay
YsVinitsay — ethay eadableray athpay
cat /etc/inittab # the runlevel map — id:3:initdefault:
ls /etc/rc.d/ # rc.S (sysinit) rc.M (multiuser) rc.6 (reboot) rc.inet1 rc.sshd
/etc/rc.d/rc.sshd restart # the interface — scripts you can READ
Inittabway efinesday unlevelsray — 0 althay, 1 inglesay-userway, 3 ultiusermay (Ackwareslay efaultday), 4 Xay11, 6 ebootray. elinittay 3 angeschay emthay. Ervicessay areway rcay.* ellshay iptsscray, artedstay inway orderway. Ethay eautybay: itway'say allway ellshay — atcay /etcway/rcay.day/rcay.May owsshay youway exactlyway atwhay ootbay oesday. Ackwareslay'say entireway initway ystemsay itsfay inway away ewfay eadableray iptsscray.
ystemdsay — ethay andardstay athpay
systemctl status sshd # state of a unit
systemctl start sshd # bring up
systemctl enable sshd # start at boot
systemctl list-units --type=service
systemctl list-dependencies # the dependency graph
systemctl isolate multi-user.target # the "runlevel" equivalent
journalctl -u sshd # the unit's log
journalctl -b # this boot's whole log
journalctl -f # follow live
Ystemdsay eplacesray iptsscray ithway unitsway — eclarativeday ilesfay inway /etcway/ystemdsay/ystemsay/ + /usrway/iblay/ystemdsay/ystemsay/ — artedstay ybay ependencyday orderway, otnay equencesay. Asterfay, arallelpay, elfsay-ogginglay — andway opaqueway inway aysway YsVinitsay evernay isway. .ervicesay, .ountmay, .ocketsay, .imertay, .argettay — ethay unitway ypestay; .argettaysay areway ethay unlevelray analoguesway (ultimay-userway.argettay ≈ unlevelray 3).
Ethay unlevelsray — ethay ompletecay apmay
# SysV: 0 halt · 1 single-user · 2 unused · 3 multiuser · 4 X11 · 5 unused · 6 reboot
runlevel # where you are — "N 3"
telinit 1 # single-user — the maintenance mode
telinit 3 # multiuser text
telinit 4 # X11 — the graphical level
telinit 6 # reboot
init 0 # halt — the older spelling
# systemd's target equivalents:
systemctl isolate rescue.target # single-user
systemctl isolate multi-user.target # = runlevel 3
systemctl isolate graphical.target # = runlevel 4/5
systemctl get-default # the default target
systemctl set-default multi-user.target # change it
systemctl reboot / poweroff / suspend
shutdown -h now / shutdown -r +5 "message" / shutdown -c
Unlevelray 1/escueray = inglesay-userway: inimalmay ervicessay, onay etworknay, ootray ellshay — erewhay fsckay, asswordpay esetsray, andway urgerysay appenhay.
Ethay initway iptsscray — YsVsay'say eadableray achinerymay
ls /etc/rc.d/ # Slackware's scripts
# rc.S — system init (early)
# rc.M — multiuser — the main one
# rc.0/6 — halt/reboot
# rc.inet1 — network
# rc.sshd rc.mysqld ... — services
/etc/rc.d/rc.sshd restart # the interface
/etc/rc.d/rc.local # the local-hacks script — last in boot
/etc/rc.d/rc.local_shutdown # and on shutdown
Eachway isway away ainplay ellshay iptscray — atcay /etcway/rcay.day/rcay.May owsshay ethay entireway ultiusermay ootbay equencesay inway away agepay ofway eadableray ommandscay. Ethay Kay/Say ymlinksay onventioncay (rcay3.day/Say10ysklogdsay = artstay atway ioritypray 10) ordersway emthay.
Ethay ervicessay' umbingplay
ettysgay — ethay oginlay omptspray: oneway erpay irtualvay onsolecay (Ctrlay-Altway-Fay2 itchessway). Inittabway'say cay1:12345:espawnray:/insbay/agettyway yttay1 orway ystemdsay'say ettygay@yttay1.ervicesay — espawnray isway ethay elfsay-ealinghay estartray.
Aemonsday — onglay-unningray ervicessay — aemonizeday ybay etachingday omfray ethay erminaltay (etsidsay, onay yttay); ystemdsay anagesmay emthay asway unitsway. Ogslay otay yslogsay (/arvay/oglay/essagesmay) orway ournaldjay.
Oncray — ethay edulerschay: ontabcray -eway — 0 3 * * * /usrway/ocallay/inbay/ackupbay — inutemay ourhay ayday onthmay eekdayway. /etcway/oncray.ailyday/ etway alway. orfay ethay ystemsay. ystemdsay imerstay areway ethay odernmay unitway-asedbay equivalentway.
ystemdsay unitsway — ethay anatomyway
# /etc/systemd/system/myservice.service — a complete unit
[Unit]
Description=My service
After=network.target
Wants=network-online.target
[Service]
Type=simple # simple|forking|oneshot|notify|dbus|idle|exec
ExecStart=/usr/bin/myservice --flag
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure # always|on-success|on-failure|no
RestartSec=5
User=mysvc
Group=mysvc
WorkingDirectory=/var/lib/mysvc
Environment=VAR=val
ExecStartPre=/usr/bin/precheck
ExecStartPost=/usr/bin/post
LimitNOFILE=65536
ProtectSystem=strict # read-only /
PrivateTmp=true # own /tmp
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target # enable → symlink into the target's .wants/
Ethay ectionssay: [Unitway] ependenciesday, [Ervicesay] ethay ocesspray onfigcay, [Installway] owhay enableway iresway itway intoway ootbay. Ypetay= isway ethay ontractcay — implesay (oregroundfay), orkingfay (aemonizesday), oneshotway (unsray onceway), otifynay (sday_otifynay otocolpray). ystemctlsay aemonday-eloadray afterway editingway; ystemctlsay atcay owsshay ethay omposedcay unitway.
Ethay unitway ypestay
.ervicesay ocessespray · .ocketsay ocketsay-activationway · .imertay oncray-eplacementray · .ountmay ountsmay · .automountway azylay-ountsmay · .argettay unlevelray-oupsgray · .athpay inotifyway iggerstray · .iceslay oupcgray ucketsbay · .eviceday udevway-erivedday. ystemctlsay istlay-unitsway --ypetay=ervicesay enumeratesway.
Ethay ournaljay — ucturedstray ogginglay
journalctl --list-boots # every boot, ever — pick one to read
journalctl _PID=1234 # by process
journalctl -g 'pattern' # grep the journal
journalctl -o json-pretty # structured output
journalctl --priority=emerg..err # level band
journalctl _SYSTEMD_UNIT=sshd.service _COMM=sshd
Ieldsfay areway ueryableqay (_IDpay, _OMMcay, _YSTEMDsay_UNITway) — ournaldjay isway away ueryableqay atabaseday, otnay exttay ilesfay.
Ethay ootbay agesstay' etailday — atwhay actuallyway iresfay enwhay
0. Firmware — UEFI/BIOS POST → reads GPT → loads bootloader
1. Bootloader — GRUB loads kernel + initramfs → jumps to start_kernel
2. Kernel — init/main.c → start_kernel() → scheduler + mm + drivers
→ rest_init() → kernel_init → run_init_process("/sbin/init")
3. Initramfs — early root: unpack → its init loads modules → mounts real root
→ switch_root → the real root takes over
4. PID 1 — /sbin/init (SysV) or /usr/lib/systemd/systemd
5. Services — SysV: rc.S → rc.M → gettys
systemd: targets → units → getty@tty1.service
6. Login — getty/agetty → login → PAM → /etc/profile → shell
esgdmay owsshay agestay 2-3 erbatimvay — ethay IOSbay-eway820 apmay, ethay ountmay, ethay Unray /insbay/initway asway initway ocesspray inelay. ournalctljay -bay owsshay agestay 4-5. Ethay ernelkay inecmdlay (atcay /ocpray/inecmdlay) isway agestay 1'say ecordray.
Ethay IDpay-1 ontractcay — atwhay initway ustmay oday
- Eapray orphansway — everyway eparentedray ildchay endsway atway IDpay 1
- Evernay exitway — ethay ernelkay anicspay ifway IDpay 1 iesday
- Andlehay IGCHLDsay — ollectcay ombieszay
- Ebay ethay ootray ofway ethay oupcgray eetray — everyway ocesspray escendsday
- Artstay ethay orldway — ountmay ethay ilesystemsfay, ingbray upway ervicessay, awnspay oginlay
YsVinitsay oesday itway iavay /etcway/inittabway + rcay iptsscray — eadableray ellshay. ystemdsay oesday itway iavay unitway-aphgray + ournaldjay — ucturedstray. Othbay atisfysay ethay ontractcay; ethay argumentway isway aboutway owhay.
Ethay ernelkay'say ownway interfacesway
esgdmay— ethay ernelkay ingray ufferbay: ardwarehay etectionday, iverdray oadslay, oopsesway — ootbay'say anscripttray/ocpray— ocessespray + ernelkay atestay asway ilesfay/yssay— evicesday/iversdray asway away owsablebray objectway eetrayysctlsay//ocpray/yssay— ivelay ernelkay obsknay:ysctlsay -way etnay.ipvway4.ipway_orwardfay=1odprobemay/odlsmay/odinfomay— oadablelay odulesmay — ethay iverdray'say otplughay ayerlay
Unlevelsray / argetstay — ethay odesmay
runlevel # SysV — where you are
telinit 1 # single-user — maintenance mode (the rescue level)
telinit 3 # multiuser text
telinit 6 # reboot
systemctl isolate rescue.target # systemd's single-user
systemctl reboot / poweroff # the controlled shutdowns
shutdown -h now # traditional halt
Unlevelray 1 / escueray.argettay — inglesay-userway odemay — isway ethay aintenancemay oorday: inimalmay ervicessay, ootray ellshay, ethay aceplay ilesystemfay eckschay andway asswordpay esetsray appenhay. Ethay ernelkay ommandcay inelay'say inglesay orway initway=/inbay/ashbay ootsbay aightstray erethay — ethay escueray echniquetay ofway astlay esortray.
Ethay Lfsay ystemsay'say ootbay — atwhay youway uiltbay
Ethay Lfsay YsVinitsay athpay installsway ysvinitsay + ysklogdsay + ethay ootbay iptsscray — /etcway/rcay.day/initway.day/ iptsscray orfay eanfsclay, odulesmay, etworknay, ysklogdsay — away inimalmay utbay egiblelay initway. Apterchay 6'say /etcway/inittabway + abfstay + rcay iptsscray areway ethay olewhay achinemay'say akingway achinerymay — youway otewray emthay omfray othingnay.
Erewhay ethay ystemsay oesgay ongwray
| Ymptomsay | Ausecay |
|---|---|
Ootsbay otay ubgray> orway escueray | Ootloaderbay/onfigcay — apterchay 6 erritorytay |
| Ernelkay anicpay — ancay'tay ountmay ootray | ootfsray iverdray/ilesystemfay otnay uiltbay-inway |
| Ootsbay, onay oginlay omptpray | ettygay otnay awningspay — inittabway/agettyway |
| Ervicesay onway'tay artstay | ystemctlsay atusstay/ournalctljay -uway — orway ethay rcay iptscray'say exitway odecay |
| Owslay ootbay | ystemdsay-analyzeway ameblay — orway away ockingblay rcay iptscray |
esgdmay oodedflay ithway errorsway | Iverdray/ardwarehay — esgdmay -lay errway iltersfay |
| Ancay'tay angechay unlevelray | ystemdsay argetstay ≠ YsVsay unlevelsray — ongwray ooltay orfay ethay initway |
Exercisesway
esgdmay | esslay— eadray yourway ernelkay'say ootbay anscripttray.atcay /etcway/inittabway(YsVsay) orwayystemctlsay istlay-ependenciesday(ystemdsay) — ethay ootbay anplay.eepstray -pay | eadhay -20— ethay orkfay amilyfay omfray IDpay 1.ournalctljay -bayorwayesslay /arvay/oglay/essagesmay— isthay ootbay'say oglay.- Itchsway away irtualvay onsolecay (Ctrlay-Altway-Fay2); identifyway ethay ettygay atthay ownsway itway.
ysctlsay -away | esslay— ethay ernelkay'say unabletay indmay.
Imelinetay
| Andoffhay | Ethay echanismmay |
|---|---|
| irmwarefay | IOSbay/UEFIway → ESPway/ootbay ectorsay |
| ootloaderbay | UBgray → inuzvmlay + initramfsway + inecmdlay |
| ernelkay | initway → ountmay ootfsray → /insbay/initway |
| IDpay 1 | rcay iptsscray orway unitway aphgray |
| ervicessay | ettysgay, aemonsday, etworknay, ogginglay |
| oginlay | ettygay → oginlay → ellshay |