Operate running systems Flashcards
To reboot the system
# reboot # systemctl reboot # shutdown -r now # init 6 #telinit 6
To shutdown the system
# halt # systemctl halt # shutdown -h now # init 0 #telinit 0
To switch off the system
# poweroff # systemctl poweroff
To suspend the system
systemctl suspend
To put the system into hibernation
systemctl hibernate
To put the system into hibernation and suspend it
systemctl hybrid-sleep
using systemd
systemctl rescue: to move to single user mode/maintenance level with mounted local file systems,
systemctl emergency: to move to single user mode/maintenance with only /root mounted file system,
systemctl isolate multi-user.target: to move to multi-user level without graphical interface (equivalent to previous run level 3),
systemctl isolate graphical.target: to move to multi-user level with graphical interface (equivalent to previous run level 5),
systemctl set-default graphical.target: to set the default run level to multi-user graphical mode,
systemctl get-default: to get the default run level.
Interupt boot process
In RHEL 7, the procedure to get access to a system during the boot process and modify the root password has changed because of the adoption of systemd.
At the beginning of the boot process, at the GRUB 2 menu, type the e key to edit.
Then, go to the kernel line, remove the rhgb quiet options and add the following string at the end:
init=/bin/sh
Press Ctrl+x to resume the boot process.
When the shell prompt appears, load the SELinux policy: # /usr/sbin/load_policy -i
Then, mount the / partition as read/write: # mount -o remount,rw /
Change the root password: # passwd Changing password for user root.
Mount the / partition as read-only: # mount -o remount,ro /
To get an instantaneous image of a server activity (use ‘virt-top‘ on a KVM hypervisor), type:
top
To get details about processes, type:
ps -edf
To start a process (here script.sh) with a low priority, type:
nice -n 10 ./script.sh
To change the priority (here +5) of an already running process, get its PID (Process ID) through top or ps (here 789) and type:
renice +5 789
alternatively # renice +5 `pgrep script.sh`
To kill the process, get its PID through top or ps (here 789) and type:
kill -9 789
alternatively # pkill script.sh
To display details about IO activities, type:
iostat
To show network card activities, type:
netstat -i
To display socket activities, type:
netstat -a
To get details about virtual memory activities (memory, swap, run queue, cpu usage, etc) every 5 second, type:
vmstat 5
To get a full report of a server activity, type:
sar -A
ystemd primary task is to manage the boot process and provides informations about it.
To get the boot process duration, type:
systemd-analyze
To get the time spent by each task during the boot process, type:
systemd-analyze blame
In addition, Systemd handles the system event log, a syslog daemon is not mandatory any more.
To get the content of the Systemd journal, type:
journalctl
To get all the events related to the crond process in the journal, type:
journalctl /sbin/crond
Note: You can replace /sbin/crond by which crond
.
To get all the events since the last boot, type:
journalctl -b
To get all the events that appeared today in the journal, type:
journalctl –since=today
To get all the events with a syslog priority of err, type:
journalctl -p err
To get the 10 last events and wait for any new one (like tail -f /var/log/messages), type:
journalctl -f
With KVM, to access the virtual machine’s console under X Window, type:
virt-manager
if you aren’t under X Window, how to access the virtual machine’s console
If you aren’t under X Window, there is another way to access a virtual machine’s console: you can go through a serial console.
On the virtual machine, add ‘console=ttyS0‘ at the end of the kernel lines in the /boot/grub2/grub.cfg file: # grubby --update-kernel=ALL --args="console=ttyS0"
Note: Alternatively, you can edit the /etc/default/grub file, add ‘console=ttyS0‘ to the GRUB_CMDLINE_LINUX variable and execute ‘# grub2-mkconfig -o /boot/grub2/grub.cfg‘.
Now, reboot the virtual machine:
With KVM, connect to the virtual machine’s console (here vm.example.com):
virsh console vm.example.com
Connect to the physical host and shut down your virtual machine
virsh destroy vm.example.com
Define where the virtual machine image file is located (by default in the /var/lib/libvirt/images directory with a name like vm.example.com.img):
virsh dumpxml | grep “source file=”
Map your virtual machine image file into the host environment (-a for add and -v for verbose):
kpartx -av /var/lib/libvirt/images/vm.example.com.img
From the previous display, you know that you’ve got two partitions (in fact /boot and /, distinguishable by their respective size). You need to mount the /boot partition to be able to change the grub configuration: # mount /dev/mapper/loop0p1 /mnt
Then, edit the /mnt/grub2/grub.cfg file and add ‘console=ttyS0‘ at the end of every line containing /vmlinuz (the linux kernel). Unmount the partition: # umount /mnt
Unmap the virtual machine image file (-d for delete and -v for verbose): # kpartx -dv /var/lib/libvirt/images/vm.example.com.img
Restart your virtual machine:
virsh start vm.example.com
Connect to your virtual machine console:
virsh console vm.example.com
Virsh VM commands
To start a virtual machine # virsh start vm.example.com
To stop a virtual machine # virsh shutdown vm.example.com
To stop immediately a virtual machine # virsh destroy vm.example.com
To delete a virtual machine # virsh undefine vm.example.com
To reboot a virtual machine # virsh reboot vm.example.com
To display configuration information # virsh dominfo vm.example.com
To get the list of all the virtual machines, type: # virsh list --all
Start, stop, and check the status of network services.
To start a network service (here httpd), type: # systemctl start httpd
To stop a network service (here httpd), type: # systemctl stop httpd
To check if a network service (here httpd) is running, type: # systemctl is-active httpd
To check the status of a network service (here httpd), type: # systemctl status httpd
Securely transfer files between systems.
To transfer the local file to a remote host # scp file root@centos:file
Note: By default, the file is put into the user’s home directory but it is possible to give a complete path.
To copy all the files from a specified directory, type: # scp /etc/ssh/* root@centos:/tmp
Note: If directories appear in the list created by the *, there are not transferred: you get a “not a regular file” error (use the tar command to transfer directories).
Transfer of a remote file
Locally, to transfer the file, type: # scp root@centos:/tmp/rem rem
init
- init is the first process (PID 1)
- All other processes are child process from init
- /sbin/init
- configuration files for init|upstart are in /etc/init
/etc/rc.d/rcx.d
check which scripts are run in different run level. Replace x for 0 - 6
Cancel schedule shutdown
shutdown -c
top command options
use the h key while in top to see all the commands that you can use with it. The q key will quit top. To change the nice value while in top, press the r key, to renice a process, then enter the pid of a process, then the renice value we want the process to have
nice value
Nice values range from negative 20 to 19 (-20,19) with negative 20 being the highest nice value and 19 being the lowest nice value. The nigher the number the less cpu time a process gets. The default value that a process get when it starts is zero
XML configured files for KVM are stored in
/etc/libvirt/qemu/name-of-guest.xml
hard disk files for KVM are stored in
/var/lib/libvirt/images
view virtual guests processes
ps -aux | grep qemu
/var/log/audit/audit.log
- messages from selinux subsystems
- contains AVC(Access Vector Cache) messages
Boot Process
- Bios initializes
- Bootloader is then called by the Bios
- Bootloader loads the first kernel image
- Kernel then mounts file systems and starts the appropriate system services.
- The system services finish starting up, and a login screen is presented