Welcome to post 27 of my 100 day challenge. Checkout my introduction for some background.
This is post eleven of my LFCS series. This post is the second part of local system administration. For the first part click here In this part we will discuss managing fstab entries, managing the startup process and related services, and managing user processes.
This post is quite long so you might want to set a side some time to go through it properly.
Local system administration part 2
Managing fstab entries
The file /etc/fstab contains information about the various partitions and mount points on your Linux system. This is where you would add a new entry if you wanted a certain mount point to be automatically mounted at boot time. It is also where items such as swap files and swap partitions are listed. cat your /etc/fstab file to see how yours is set-up mine is below:
[mytest@Centosexamtest ~]$ cat /etc/fstab # # /etc/fstab # Created by anaconda on Wed Jan 28 08:45:44 2015 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/vg_centosexamtest-lv_root / ext4 defaults 1 1 UUID=e7918412-bf64-45f2-a8ac-0d55e6338da1 /boot ext4 defaults 1 2 /dev/mapper/vg_centosexamtest-lv_swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 # Add lines to mount /dev/sdc1 as a SWAP partition on boot /dev/sdc1 swap swap defaults 0 0 # Add new swap partition /dev/sde1 to be automounted on boot /dev/sde1 swap swap defaults 0 0
Below is a table of some of the most common options and functions you may come across when setting up or otherwise viewing your fstab file the table has been derived from the wikipedia article on fstab:
|1||Device name||You can use lsblk to find the device name.|
|2||Mount point||A directory you need to create prior to mounting.|
|3||File system type||ext2, ext3, ext4, xfs, swap, ntfs, vfat, auto.|
|4||Mount options||auto, noauto, exec, noexec, user, nouser, ro, rw, sync, async, suid, nosuid.|
|5||Dump||0 -= Do not backup. Any other number means backup.|
|6||Fsck option||0 = Do not fsck check, Any other number means check.|
The default options for mounting a drive are: rw, suid, dev, exec, auto, nouser and async
Managing the startup process and related services
The BIOS (Basic Input Output System) is the lowest level of software between the computer and peripherals. When you turn on your computer the boot process loads the BIOS and checks the integrity of your system RAM and then looks of the MBR (Master Boot Record) of your primary drive
In the Linux world this MBR will point to the GRUB (GRand Unified Bootloader) software which will give you a choice of OS to load. By default it will load the first item in the list if there is no input from the user within a certain time frame. Each line in the GRUB OS listing will have command line parameters to say which kernel, parition and drive the OS in located. When an item is selected these commands are ran and the kernel is loaded.
The kernel loads the init program as the first item. It is the first process that is launched and will be the parent of all over processes that run whilst the operating system is running. The first process that init starts is SysV which is located in /etc/inittab.
Depending on the run level that is specified certain scripts will run and start various pieces of software which will make your Linux usable. The init process is the last step after all of this, it is what goes off and starts any other system processes defined for your current runlevel.
You can display your current runlevel with the following command:
[mytest@Centosexamtest ~]$ runlevel N 3
For CentOS here is a list of the runlevels that are available. By default CentOS boots into runlevel 3.
0 — Halt
1 — Single-user text mode
2 — Not used (user-definable)
3 — Full multi-user text mode
4 — Not used (user-definable)
5 — Full multi-user graphical mode (with an X-based login screen)
6 — Reboot
You can change the runlevel by passing the appropriate number to the telinit command:
[root@Centosexamtest ~]$ telinit 5
On CentOS systems SysV init is the first process started during the boot sequence. The SysV init process is the parent process and is therefore given PID 1.
The init system is started by the kernel using a hard coded value in the kernel. At the time of writing in CentOS 7 and above SysV init has been replaced by systemd but we will not discuss systemd here as it is not part of the LFCS exam at the time.
SysV init is the traditional init system.
The config files for the SysV init system are located in /etc/rc.d. Within this directory are directories for each runlevel.
<tt class="computeroutput">init.d/ rc0.d/ rc1.d/ rc2.d/ rc3.d/ rc4.d/ rc5.d/ rc6.d/</tt>
The init.d/ directory contains the scripts used by /sbin/init when controlling services. Each of the numbered directories represent each of the 6 runlevels available.
You can see at what runlevel processes will start with the chkconfig command. Below is an excerpt from the practice VM I am running:
[mytest@Centosexamtest ~]$ chkconfig auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off blk-availability 0:off 1:on 2:on 3:on 4:on 5:on 6:off crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off ip6tables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
you can use the service utility to start these processes at any time providing you have sufficient privileges or you are the root user. Common options for the service command are: start, stop, restart, reload, status, list and show.
Here is an example of me restarting the crond service:
[root@Centosexamtest ~]# service crond restart Stopping crond: [ OK ] Starting crond: [ OK ]
Managing user processes
You can see a list of all running processes by running the top utility on the command line you can hold down shift+m to order the entries by memory usage:
An improvement over top is htop. You have to install it from your package manager as it isn’t installed by default. It is available from the rpm force repo which you can find details for how to install here.
[root@centospractice ~]# rpm -i http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm warning: /var/tmp/rpm-tmp.k62Q3a: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY [root@centospractice ~]# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt [root@centospractice ~]# yum install htop Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: centos.hyve.com * extras: mirror.econdc.com * rpmforge: mirror.nl.leaseweb.net * updates: mirror.econdc.com rpmforge | 1.9 kB 00:00 rpmforge/primary_db | 2.7 MB 00:08 Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package htop.x86_64 0:1.0.3-1.el6.rf will be installed --> Finished Dependency Resolution Dependencies Resolved ==================================================================================================== Package Arch Version Repository Size ==================================================================================================== Installing: htop x86_64 1.0.3-1.el6.rf rpmforge 87 k Transaction Summary ==================================================================================================== Install 1 Package(s) Total download size: 87 k Installed size: 209 k Is this ok [y/N]: y Downloading Packages: htop-1.0.3-1.el6.rf.x86_64.rpm | 87 kB 00:01 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Warning: RPMDB altered outside of yum. Installing : htop-1.0.3-1.el6.rf.x86_64 1/1 Verifying : htop-1.0.3-1.el6.rf.x86_64 1/1 Installed: htop.x86_64 0:1.0.3-1.el6.rf Complete!
This is what it htop looks like:
You can see that there are many more features available then with top. The RAM, CPU and Swap usage above is a very useful feature to see usage at a glance. As is the number of tasks and load average top right.
You can kill processes you have permissions over with the kill command. You can pass the -9 switch to force kill a process. You can use pkill to kill a process via it’s name and pgrep to list the process IDs for a process which you can then use kill to terminate.
I tend to use the ps (process snapshot) along with grep to find the PID for a process then use kill -9 to terminate it.
[root@centospractice ~]# ps x | grep watchdog 6 ? S 0:00 [watchdog/0] 1548 pts/0 S+ 0:00 grep watchdog [root@centospractice ~]# kill -9 6
This concludes my articles on local system administration. Check back tomorrow for my article on local security where I will be discussing accessing the root account and using sudo to manage access to the root accout.
Can you improve on any of the tips I’ve discussed here? If you can let me know in the comments.