infuerno.github.io

Pluralsight - Linux Installation and Configuration

Introduction

: Linux Kernel or core software

: Distribution e.g. Suse, Redhat, Ubunto

Determine Hardware Settings

Physical consoles are number tty1 to tty6. Psuedo terminals represent logical terminals such as GUI or X-Terminals and those made from SSH clients.

Resource Interrogation

Pseudo File Systems

These “file systems” contain information about the currently running system. It only exists while the system is running and only in RAM.

Managing the Boot Loader and Understanding Run Levels

Bootloader

The bootloader or bootstrap file is responsible for loading the kernel into memory. It may be located on the network (PXE boot) or in the master boot record.

At the grub boot menu enter e to edit an entry or c to go to a grub command line

Run Levels and Init

There are usually 6 run levels: 0 (Halt); 1 (Single User - root only); 2 (Multi-user, no network or GUI - though Ubuntu tends to use 2 for normal mode); 3 (Multi-user, no GUI); 4 is not implemented; 5 (Multi-user); 6 (Reboot)

When the system boots the init daemon reads a file to find the default run level. The old SysV init scripts used to work with /etc/inittab to specify the default run level and then directories such as /etc/rc3.d for the service scripts.

Newer distros use upstart and the /etc/init directory. e.g. on Ubuntu the default run level is set in /etc/init/rc-sysinit.conf

The boot menu can be configured by editing the /etc/boot/menu.lst file. Further command line options can be specified here, or after the boot menu has loaded e.g. 3 to enter run level 3; init=/bin/bash to just load up bash (handy for resetting a root password if unknown since this will automatically log you in)

Service Control

Software and Package Management

Red Hat / CentOS / Fedora

The problem with installing packages this way is that you need to first locate the rpm file in order to install it. Furthermore, if the rpm has any dependencies, these will need to be downloaded and installed alongside. The YUM repos answers these issues by resolving any dependencies.

Debian / Ubuntu

SUSU / openSUSE

Management of Shared Software Libraries

Developers can make use of shared libraries to stop code duplication DLLs in Windows, .so or .ko in Linux

So, for example, ls, grep, and cat all need to access the file system and will all use libc.so.6 in order to do that.

To test libraries under development, create a new directory to hold the libraries and set the LD_LIBRARY_PATH variable. Reviewing with ldd will reveal that the system will check the LD_LIBRARY_PATH location first for any modules required. Unset a variable with unset e.g. unset LD_LIBRARY_PATH

To load a module with additional paramters, create a .conf file in /etc/module.d/ according to the documentation

/etc/modprobe.d/blacklist.conf lists any modules which should never be loaded

Linux File System

A disk is often partitioned.

An MBR partition table allows for a maximum of 4 Primary partitions per disk and a maximum of 2TB per partition. One of the primary partitions can be a logical partitions and with a maximum of 15 partitions in total. (Uses msdos as the partition label.)

A GPT partition table - GUID partition table allows partitions of up to 8ZB in size and a maximum of 128 partitions. (Uses gpt as the partition label.)

Partitions are then formatted using file systems.

Creating partitions

Choosing a file system

For general use ext4. This is a journaled file system which maintains a journal of transactions. If the system crashes the journal can be checked to find out which files were in use and only the integrity of these files need be checked. This is a good choice for small files e.g. 4K, but not for bigger files e.g. 1GB.

XFS will be the default on Red Hat 7 and is designed for large files and for robustness. mkfs is used to make the file systems.

Creating file systems

mkfs is used to create file systems. Use tab completion on mkfs. to see the different possibilities. Packages may need to be installed e.g. XFS. When creating a file system, one parameter which can be set is the block size. e.g. 4096 bytes. If you try to save a 1KB file it will be saved to a 4K block and the rest of the space will be empty. If you save an 8K file, it will be saved to 2 4K blocks and may be fragmented.

Mounting file systems

Virtual Memory and File System Tools

Tools

Controlling Access to File Systems

Permissions

Permission can be set using symbolic notation (chmod g+x file1) or octal notation (chmod 777 file1) to the user, the group or others.

A filename links through to an inode which is the actual entry in the file system which contains metadata including a pointer to where the data is physically held on disk. A file has at least one name, but can have more than on name and will then have more than 1 hard link (count of hard links is shown in the ls -l listing).

The ls -ld long directory listing shows the number of hard links to that directory (the directory name itself, the . within the directory and the .. within all the sub directories). (A quick way to count the number of sub directories is to substract 2 from the link count! To verify use find . -maxdepth 1 -type d to display all the subdirectories and pipe this through to wc -l)

Soft links on the other hand have seperate inodes, but the data pointer points through to the same place on the physical disk

Implementing Quotas

Limits can be set in terms of blocks (space) or inodes (number of files). There are soft and hard limits. The soft limit can be exceeded, but by default only for 7 days.

vi +?<searchterm> <filename> to open a file in vi and go directly to that line for editing dd if=/dev/zero of=/data/file1 count=1 bs=1024M to create a file reading from /dev/zero which is a stream of 0s, and writing one file of size 1GB

quotacheck -cu /data to create user quota files for the /data file system. This will create an aquota.user file in the root of the file system, which is the quota database repquota -auv reports the quota usage quotaon /dev/sdb1 will enable running the quota check continuously (which would happen on boot by default) edquota -u claire will open an editor to allow editing the quota limits setquota -u claire 20000 25000 0 0 /dev/sdb1 allows setting quota limits in a one line command edquota -t to edit the grace period of the soft limit