Booting up the system in rescue mode (runlevel 1) ------------------------------------------------- https://www.linuxtechi.com/boot-ubuntu-20-04-rescue-emergency-mode/ Sometimes we need to start into runlevel 1 (single user mode). This is needed in the following situations: a) the system won't start and presents a "kernel panic" message b) we corrupted the /etc/fstab file and the system waits to mount some filesystem described there, but fails because the file is corrupted and the information for the mount is incomplete c) the filesystem needs checking because of bad sectors and we need to unmount it How to go into the runlevel 1: At system startup we press the escape key until some menu appears. It is the booting menu. From it we could select which kernel to start. Some problems from the set above, like variant a) is easy solved by just selecting the appropriate kernel to start, if the default one is not working. For the other ( b) and c) ) we would edit the command (press "e" on the correct line from the boot menu). Then detailed information appars and we need to add something to the end of line described below. The trick with using "init=/bin/bash" will also be used as a workarround for the situation that we forgot the root password, because like this we won't be asked to give the administrator (root) password to be able to operate in this runlevel. Write this text at the end of the line that begins with linux .... vmlinuz... : rw init=/bin/bash If somehow we need to remount (after booting in single user mode) to a read-write filesystem we can do that with the command: mount / -o remount,rw Reasons for which we might want to go into singel user mode runlevel. 1) Fix the filesystem of bad clusters or bad sectors unmount / fsck / 2) Edit the fstab file to correct it (if we manage to break some lines of it into 2 lines) if the system hangs at bootup because of it nano -w /etc/fstab Changing the runlevel in Ubuntu ------------------------------- https://www.answertopia.com/ubuntu/managing-ubuntu-systemd-units/ poweroff.target - equivalent with runlevel 0 rescue.target - equivalent with runlevel 1 multi-user.target - equivalent with runlevel 3 graphical.target - equivalent with runlevel 5 reboot.target - equivalent with runlevel 6 Switching the runlevel (live) ----------------------------- 1) Using the telinit command telinit where is O-6 numbers or s, S, q, Q, u (see below for explanation) E.g. telinit 1 can also be used to switch to runlevel 1 2) Using systemctl isolate command: systemctl isolate multi-user.target This switches back to the runlevel 3. Making and cheking whether a service starts on a certain runlevel (not solved yet) ----------------------------------------------------------------- https://linuxconfig.org/how-to-start-service-on-boot-on-ubuntu-20-04 https://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet Systemd Short primer of commands and actions -------------------------------------------- https://www.linuxbabe.com/command-line/systemd-services-run-levels-logs How to see what services are active and running ----------------------------------------------- systemctl list-units --type=service --state=active systemctl list-unit-files --type=service --state=enabled Starting and restarting the system (Ubuntu systemd variant) ----------------------------------------------------------- The system startup is mainly the same that for normal Linux systems, however systemd is used as the parent of all the other processes (the process with PID 1). The staps are best described in the following documentation: https://www.tecmint.com/linux-boot-process/ Starting and restarting the system (CentOS init variant) ======================================================== At system powerup the following steps are performed: - BIOS tests the system, searches and initializes the peripherical equipments, then searches the disc from which the system will start - BIOS verifyes the boot sector (MBR), loads the contents into RAM then gives the control to it - MBR reads the boot loader (LILO or GRUB) and runs it - the boot loader reads the kernel image and gives the control to it - the OS kernel identifies the equipments used in the system then searches for the init program in the /sbin folder. This program is run after the root filesystem (/) was mounted in read-only mode - the init process becomes the parent of all the processes that will be executed. It continues with the boot process in the following steps: a) executes the script /etc/rc.d/rc.sysinit, that: - verifies the integrity of the root filesystem, calling fsck - verifies the integrity of the other filesystems specified in the file /etc/fstab - remount the root FS in RW mode - mounts the local filesystems - initializes the virtual memory - initializes the system clock - executes rc.serial to initialize the special serial ports b) reads the configurations from the file /etc/inittab, that describes each runlevel and sets the default runlevel as being N. This level is known from a line of this file that looks like the one in the example below: id:3:initdefault This particular example sets 3 as the default runlevel. c) The scripts from the default runlevel (in our case N=3) are executed /etc/rc.d/rcN.d where N is the run level d) runs the script /etc/rc.d/rc.local, that performs the local initializations ------------------------------------------------------------------------------------- Runlevels: 0 the halt state (stop) = the state in which the system can be safely stoped 1 the single user level = in this state is mounted only the root filesystem (/), the network is not activated, the services are not started. It is used when faults in the (file)system appear. 2 the normal state of the system, without NFS (multi user without NFS) 3 the normal system state (multiuser) in CLI mode (Command Line Interface) 4 not used 5 the normala system state with X windows 6 the restart (reboot) state Changing the runlevel can be acomplished with the program /sbin/telinit parameter where parameter is one of the characters 0,1,2,3,4,5,6: changes the runlevel a,b,c: processes the entries from these levels q,Q: rereads /etc/inittab s,S: switches to single-user mode u,U: reruns init ------------------------------------------------------------------------------------- The file /etc/inittab --------------------- este fisierul de configurare al programului /sbin/init si contine intrari care definesc actiunile sistemului pentru fiecare nivel de executie. Intrarile au formatul eticheta:lista_de_stari:actiune:proces De cautat in manual semnificatia actiunilor wait, respawn, once, boot, initdefault, ondemand, ctrlaltdel Ubuntu (systemd) version for the /etc/inittab file -------------------------------------------------- sudo systemctl set-default multi-user.target That will make a symbolic link (a shortcut) called default.target which will point to the multi-user.target (runlevel 3) Enable a service ---------------- To enable a service, e.g. the cron service we can use sudo systemctl enable cron This will create a symbolic link: /etc/systemd/system/multi-user.target.wants/cron.service pointing to the cron service that is located here: /lib/systemd/system/cron.service Ubuntu: vezi systemd! ----- ----- ------- ------------------------------------------------------------------------------------- Fisierele de initializare rc ---------------------------- Atunci cand nivelul de executie se schimba, init apeleaza scriptul /etc/rc.d/rc (vezi mai sus, punctul c)) Acest script executa toate scripturile aflate intr-un director de tipul /etc/rc.d/rcN.d unde N=0, 1, ..., 6 corespunde unuia dintre nivelurile de executie. De exemplu pentru nivelul 3 de executie, continutul directorului /etc/rc.d/rc3.d este K05innd K35dhcpd K65krb5kdc S06reconfig S60lpd K09junkbuster K35vncserver K70aep1000 S08ip6tables S60nfs K12mysqld K40mars-nwe K70bcm5820 S08ipchains S80sendmail K15httpd K45arpwatch K74ntpd S08iptables S85gpm K15postgresql K45named K74ups S09isdn S90crond K16rarpd K45smartd K74ypserv S10network S90xfs K20bootparamd K46radvd K74ypxfrd S12syslog S91smb K20iscsi K50netdump K75gated S13portmap S95anacron K20netdump-server K50snmpd K84bgpd S17keytable S95atd K20rstatd K50snmptrapd K84ospf6d S20random S97rhnsd K20rusersd K50tux K84ospfd S24pcmcia S98wine K20rwalld K54pxe K84ripd S25netfs S99local K20rwhod K55routed K84ripngd S26apmd S99usermin K24irda K61ldap K85zebra S27ypbind S99webmin K25squid K65identd K86nfslock S28autofs K28amd K65kadmin K90isicom S55sshd K34yppasswdd K65kprop K99microcode_ctl S56rawdevices K35atalk K65krb524 S05kudzu S56xinetd Exista scripturi marcate cu K (de la kill) si scripturi marcate cu S (de la start). Cele marcate cu K opresc programele corespunzatoare. De exemplu K61ldap opreste programul ldap ,adica executa /etc/init.d/ldap stop Cele marcate cu S pornesc programul corespunzator. De exemplu, S55sshd porneste programul ssh, adica executa /etc/init.d/sshd start service ldap stop service sshd start service sshd status Numerele care apar dupa K sau S determina ordinea in care se executa aceste comenzi. Ati dedus probabil deja ca toate scripturile din acest director sunt de fapt sunt de fapt link-uri (scurtaturi) catre scripturi din directorul /etc/init.d O consecinta a acestui fapt este ca putem stabili care script sa porneasca si care nu pe un anumit nivel de executie, redenumind link-ul din directoul /etc/rc.d/rcN.d. De exemplu daca dorim sa nu mai porneasca sshd pe nivelul de executie 3 putem da mv /etc/rc.d/rc3.d/S55sshd /etc/rc.d/rc3.d/K55sshd Nu e prea elegant sa procedam in acest fel, dar e posibil. 2) O alta modalitate de a spune care programe sa porneasca si care nu pe un anumit nivel de executie este cu programul serviceconf din interfata grafica 3) O a treia modalitate de a face acest lucru este cu utilitarul in mod text ntsysv De exemplu: a) ntsysv (fara parametri) configureaza nivelul curent de executie b) ntsysv --level 35 configureaza nivelele de executie 3 si 5 4) O a patra modalitate de a specifica programele care sa porneasca pe fiecare dintre nivelele de executie este cu comanda chkconfig De exemplu: a) chkconfig --level 345 postgresql on seteaza serviciul postgresql sa porneasca automat pe nivelele de executie 3, 4 si 5 b) chkconfig postgresql off face ca postgresql sa fie oprit doar pe nivelul de executie curent (de fapt pe 2, 3, 4 si 5) c) chkconfig --help afiseaza help-ul pentru utilizarea comenzii d) chkconfig --list or chkconfig afiseaza fiecare serviciu si starea sa pentru fiecare nivel de executie e) chkconfig --add serviciu1 adauga serviciul "serviciu1" la lista serviciilor inregistrate f) chkconfig --del serviciu1 sterge serviciul "serviciu1" de pe lista serviciilor inregistrate g) daca nu specific nivelul de executie atunci este vorba despre nivelul de executie curent. h) serviciile pornite cu chkconfig vor porni automat si dupa resetarea sistemului i) chkconfig --level 45 postgesql off 5) Pornirea manuala a serviciilor se face cu comanda /etc/init.d/serviciu start unde serviciu este unul dintre serviciile inregistrate. Acesta pornire nu este persistenta, la resetarea sistemului serviciul "serviciu1" va trebui repornit manual. ------------------------------------------------------------------------------------- Tiparirea la imprimanta ======================= lprd demonul de imprimare lpr adauga un print job lpq afiseaza sarcinile din coada de tiparire lprm sterge o sarcina din coada de tiparire lpc interfata pentru administrarea sistemului de tiparire Meniul System -> Printer Configuration Pentru configurare in mod text avem printconf-tui