linux Part 9

Package Management and Principles

Processes and Process Data
Any time you have a running program this is called a process.
Log files record what a program is actually doing, especially those processes that are being run in the background.

Package management varies between distributions but have certain principles that are the same between all distributions.

Packages are single files, Linux packages unlike windows packages are not installers.
Linux packages are going to rely on other package managers to do the work of installing.

Think of packages like a compressed folder, that contain all the files you need. Each package is going to have dependency information you need, this is going to indicate to the packet manager exactly what other packages you will need to make the package / software run properly.

We have packages that contain version information, so the packaging software can tell which of the 2 versions you have, maybe the most recent, because you may want to install the most recent software.

Packages contain architecture information to identify the CPU or processor type, Linux software is compiled for a specific processor you are using such as intel or AMD or if you are using a RISC processor that is going to be different, you have to have the right package for the right architecture

Binary packages

Binary packages are executable programs, these are CPU specific and built from the source package for that architecture. It is possible to build a new binary package if you have the source code, however this is a little bit difficult to do for beginners.

The package software is going to maintain  a database about every package that is installed. This information includes the names and version numbers of all the software  packages as well as the locations of where the files are installed from each package, think about this like the add-remove programs within a windows system. This information is going allow the package software to uninstall software quickly, establish a new whether a new packages dependencies have been met and determine the package the user is using has already been installed before, and whether it was, if this version is newer and needs to update the old version or if its a brand new program.

Package Management Systems

RPM and Debian
RPM is Red hat Packet Manager and uses YUM (old packet manager) the newer version is DNF which is a modernised fork with is used with Fedora, it has some some of the old interface features from YUM

Debian is distribution, such as Linux Mint and Ubuntu and uses APT package manager

Installing the wrong package type can result in a erroneous install because the Linux version may have different dependencies or a rely on a different version of a dependency.

Old distributions often depended on the user downloading the package and installing it locally, however this was tedious as users would also have missing dependencies and have to locate and install them manually. Today as Linux has advanced software it is often tried and tested and the complete packages along with the correct dependencies . Today most linux distributions come with a software centre where you just need to select what software and everything will be automated, the linux version will be checked and the appropriate version and dependencies will be downloaded and your packet manager will install. Regardless of what you wish to install you generally need admin rights (root access).

Fedora dnf upgrade
dnf check-update – this will provide a list of up-gradable packages – latest versions.

sudo dnf upgrade – this will upgrade programs, packages and dependencies.
If you want to look for individual software upgrades you can, here is an example.

dnf search virtualbox
The result should show you something like this

virtualbox-guest-additions.x86_64

Now to view the information about the package you can run the following command

dnf info virtualbox-guest-additions.x86_64

You should see the the following information
Name Version Release Architecture Size Source  Repository URL License etc.

To see information on a software / package in ubuntu

apt info virtualbox
apt show virtualbox

To install an virtualbox

Sudo dnf install virtualbox-guest-additions.x86_64

How to install and then erase an installation in Ubuntu

sudo apt-get install chromium-bsu (arcade game)
sudo apt-get purge  chromium-bsu  this will remove

Example with Fedora installing and removing chromium remote desktop

sudo dnf install chromium-remote-desktop.x86_64
sudo dnf erase chromium-remote-desktop.x84_64

Removing legacy programs 7 dependencies

sudo apt upgradethis will check for updates, depending how recent your updates are it may well find nothing, however it could be that it  finds legacy files that are no longer needed.

sudo apt autoremove

Removing full programs

sudo apt remove <software-name>


The Kernel

Process Hierarchy
Provides software to manage Hard disks
Doles out CPU time and Resources
Performs all low level critical tasks
The Kernel is loaded in the early boot up process, it manages all the software processes on a linux computer.
The Kernel creates a hierarchy to manage what would be chaos, when the kernel boots it will run just one program

/sbin/init 

The init process is responsible for starting all other programs that linux needs to run, such programs that manage logins and servers etc.

All these programs launched by Init are known as children, the children of init can also launch programs, this happens for example when a user logs in to linux, the process launched is called the parent.

Init is the main parent with a lot of different children underneath it but each child can also be a parent. The result of this is a tree hierarchy.

Each process that runs has a PID ( process identification ), these numbers begin with a 1.

Each process that has processes running along with it has a PPID (Parent process ID) and this will point back to its parent, so if init with a pic of once launched a child process that child process would have a PPID of one

Identify Running Processes
To identify processes we use ps and top, you can uses these commands along with the name of the resources they are using. Another reason for identifying processes is to see how much memory is being used, for this we can use the free command.

ps aux – this command will display all the processes running and the command name for each process plus:

PID Value
Memory Utilization
Username running the process
CPU Utilization 

*learn how to use the process tool / options – check help / man / info

To narrow down to a small scope we can use the grep command, for example

ps ax | grep gedit
13814 pts/1    S+     0:00 grep –color=auto gedit

13814 – PID Process ID
ps provides information at a single moment in time.Since ps provides only a snapshot in time, the process can change at anytime, depending on what other processes are running and priorities.

The top command
The top man can be used if you want to see the CPU and memory hogging processes or to see how resources are used over time, top command is like an interactive version of ps, the processes running will be displayed in real time just like windows task manager.

man top for more details / options

To kill a Process

kill pid 34456

Measuring Memory usage
If we use the top command then press M it will show all the processes that are using memory starting with the most usage. Remember just because something is using alot of memory does not necessarily mean that this is bad, same goes for CPU utiltiazation, some programs can intensively use alot of memory and CPU power, applications that maybe intensive, video editing software, real time rendering software etc

Memory Leaks
Some times programs can have bugs and use memory unecessarily , they can get stuck in a process loop and keep using more memory instead of giving it back to the kernel when a process is done. Use top and press M if you need to check the memory intensive programs

Free command
The free command will show 2 important lines

Mem – Total RAM statistics 

Swap – The Swapfile for Virtual Memory – if you keep running out of physical memory a swap file is used on your disk drive, when data is not in immediate use then the RAM will be freed up by putting data on the drive in a temporary file and will be called back to RAM when needed.

Daemons and Log Files
Daemons are programs that run in the background, these often startup when the linux is booted, network services, servers and system services etc, the operations are often wrote to a log file Linux stores more of the log files in:

/var/log

Common Log files on a linux

boot.log – Boot Process
cups/ – Printer
gdm/ gnome manager log files
messages or syslog – general log files that contains log details from many daemons that don’t have their own dedicated log files

Secure – contains security related log files – this will contain for example, su sudo or other tools that elevate their privileges up to root level

Xorg.0.log – this will contain log entries relating to your xwindow (GUI)

Their are many log files, however, log files are frequently rotated and will often be over written every time a new log file is written, a new file can be created based on date and time, for example a firewall log

/var/log/ufw.1
/var/log/ufw.2
/var/log/ufw.3

Most of your logfiles will be in plaintext, so you can use pic vi nano or gedit to read the file contents

Specialized Log files

Some programs are going created their own specialized log files, but most of them are going to depend on a dameon known as syslog or syslogd to do there job. Like other daemons the syslogd is started up in the boot process via a startup script and runs in the background.

Klog/klogd 

Handles logging messages from the kernel separately from ordinary programs. To adjust or configure klog and how it handles message and what is logged from the Kernel there is a file  that ends with .conf  for example it maybe named as klogd.conf 

System messgaging

System messaging is a technique wherein a log daemon accept messages from other processes and directs them to a log file depending on the messages source and the priority code

Kernel Ring Buffer

This can be though as a log file for the Kernel itself, however, rather than being stored in a logfile it is stored in the Memory, like log files its contents also change as the computer runs

If you want to check the kernel logfile / buffer, you can type the following command

$dmesg 

The dmesg command will give a massive amount of information in one go, if you wish to 

Dmesg | less – to breakdown the log file page by page

Targeting a specific query in Kernel Ring Buffer – dmesg for example “hard disk”

sudo dmesg | grep | sda

Output 

[    2.796624] sd 32:0:0:0: [sda] 83886080 512-byte logical blocks: (42.9 GB/40.0 GiB)
[    2.796647] sd 32:0:0:0: [sda] Write Protect is off
[    2.796651] sd 32:0:0:0: [sda] Mode Sense: 3b 00 00 00
[    2.796687] sd 32:0:0:0: [sda] Write cache: disabled, read cache: disabled, doesn’t support DPO or FUA
[    2.804295]  sda: sda1 sda2 sda3[   2.804540] sd 32:0:0:0: [sda] Attached SCSI disk[  2.962866] EXT4-fs (sda3): mounted filesystem 79e1dd17-11e6-436e-8d02-d9b27d962b2c with ordered data mode. Quota mode: none.
Kernel ring buffer messages are invaluable in diagnosing hardware and driver problems.

The log files for the kernel ring buffer is stored in 
/var/log/dmesg file

If your distribution does not create the kernel ring buffer file default, you can do this manually by editing your rc.local located in the following directory

/etc/rc.d/rc.local

rc.local is a default file that loads up files and scripts when you startup a computer. To specify to create a dmesg log file add the following line

dmesg > /var/log/dmesg