[2] Linux Flashcards
What is the boot process?
[1] The BIOS checks the device hardware
[2] The bootloader finds the boot sector on the hard drive which contains the Linux kernel
[3] The Linux kernel is loaded
[4] The Linux kernel starts a RAM disk and loads basic drivers onto it
[5] The drivers on the RAM disk are used to mount the file system
[6] The kernel triggers the initialisation system, which mounts the file system and starts key daemons
How do boot logs work?
They are stored in the kernel ring buffer which is in RAM
Therefore, they are volatile i.e. do not persist on reboot
What command is used to read the boot log?
dmesg
What is it called when the kernel has an error?
Kernel panic
What are kernel modules?
Extensions to the Linux kernel e.g. third-party device drivers
What configuration files are used in Linux to manage DNS resolution?
/etc/hosts maps hostnames to IP addresses e.g. localhost -> 127.0.0.1
/etc/resolve.conf contains the IP address of DNS name servers to use
What are pseudo file systems?
A virtual file system that only exists in RAM. It is created by the kernel and is volatile system is running
What are the main pseudo file systems?
/proc - contains information about processes running on a system
/sys - contains information about the system hardware and kernel modules
What information is included about processes listed in /proc?
Their PID (process id), process data and the hardware they are running on
What are some key filesystems?
/var - the variable location. Stores dynamic content such as websites and logs
/home - the users’ home directories
/boot - Linux kernel and supporting files
/opt - optional software e.g. libraries
/dev - all hardware attached to the computer
- swap space e.g. if RAM over fills
How can swap space be setup?
Either as a swap partition (faster) or a swap file
How big should the swap space be?
At least 50% of the RAM size
How are hard drives represented in the file system?
/dev/sda for the first, /dev/sdb for the second.
If the first is partitioned then it’s /dev/sda1, /dev/sda2 etc.
What are mountpoints?
A mapping from an entire hard disk or partition that maps to a particular directory
Which Linux command is used for mounting?
The mount command shows existing mounts and can be used to create new mounts
Which Linux command shows block devices?
lsblk shows all block devices on a system and their names
Which Linux command shows swap partitions?
swapon –summary
What are the primary file systems?
Non-journaling: ext2
Journaling: ext3, ext4, xfs
Btrfs
What is the difference between Non-Journaling and Journaling filesystems?
They keep track in RAM of changes that have not yet been written to the disk
How does Btrfs work?
It is CoW (copy on write)
When editing a file, it only stores the changes so old versions can be accessed
What filesystem do Linux boot partitions use?
They must be FAT partitions, although VFAT can be used to allow longer file names
What command would mount a second hardrive to /opt?
mount /dev/sdb1 /opt
Where are mount configurations saved?
/etc/fstab
How can ls be used to show file sizes?
ls -lh gives a long listing in human readable foramt
What information does ls -lh include?
Filename, file size, ownership and permissions
Which command show the available disk space?
df -h (“disk free”)
For each filesystem, this shows the size used, the amount available and where it is mounted
Which command shows free memory?
free -h
This shows both physical memory and swap space
Which command shows how much disk space is used by files?
du -h
By default this is file size of all files in current directory
use du -sh to show a summary i.e. total use for that directory
To see another directory, specify it’s path e.g. du -sh /home/marrick
How can du be used recursively?
du -h –max-depth=2 will recurse to show the current directory and sub directories
What is an inode?
A pointer to the file/folder and its ownership/permissions
Which command displays locale information?
use locale to view locale
Which command shows the current time/date
date
date -u for UTC
Which command sets the time zone?
tzselect
Which command updates the system clock?
timedatactl
Where is time / date information stored?
The time itself is at /etc/localtime
/etc/timezone stores the time zene
/usr/share/zoneinfo is a databse of available timezones
Which command creates new users?
useradd -m [username]
Note that the -m flag creates a home directory
Which command sets the password for an account?
passwd [username]
To set your own password, omit the [username]
Which command deletes a user?
userdel
Does userdel delete the user’s home directory?
No. unless the -r flag is used
Which command shows the groups that a user is of?
groups [username]
omit the [username] to see your users
Which command creates groups?
groupadd
Which command adds users to a group?
- when creating a user, use -G e.g. useradd -G curators
* usermod -a -G [group] [username]
Which command deletes groups?
groupdel
Which file stores a list of users?
/etc/passwd
Note that password hashes are in /etc/shadow
Which file stores a list of groups?
/etc/group contains a list of users and their members
How are system accounts distinguished from user accounts?
- root account has id of 0
- system accounts have 1 <= id <= 1000
- user accounts have id > 1000
What defaults are used for new users?
/etc/skel is used as a template for the home directory
/etc/default/useradd gives user config e.g. groups, andch shell to use
Which command displays users that are part of a group?
getent group [group]
Where are shell configurations stored?
~/.bashrc or similar for non-bash shells
Where should you set persistent environment variables?
In ~/.bashrc e.g. add “export NAME=value
Which tools are used to schedule tasks?
cron or systemd
How can cron tasks be set?
By using crontab to save tasks into the users cron table
Where are cron tabs located?
/etc/cron.hourly
/etc/cron.daily etc
How does cron notation work?
You specify the minute of the hour, hour of the day etc. and then the script to run
Which command runs a command at a specific time?
The at command
Which commands work with directories?
cd / mkdir / rmdir (won’t delete directory contents)
How does path work?
The $PATH environment variable describes directories that the user can execute the contents without specifying their full path
How are file permissions enocoded?
Symbolically: r=read, w=write, x=execute, -=no permission
Ocatal: Three bits, corresponding to read, write and execute
e.g. read/execute is 011 = 3
Which commands change ownership and permissions?
chown changes user ownership
chgrp changes group ownership
chmode changes the permissions of a file/directory