Intermediate Linux Flashcards
Where are device files generally stored?
/dev
Device files are denoted with what characters in the first bit of the ls command?
c - character
b - block
p - pipe
s - socket
Devices are characterized using what two numbers?
major device number and minor device number
How can you interact with device drivers?
Through special files that look like regular files called device files or device nodes
A device takes all of our input and just discards it, so nothing gets returned
/dev/null
What are character devices?
These devices transfer data, but one a character at a time. These are pseudo devices (e.g. /dev/null) that aren’t really physically connected to the machine, but they allow the operating system greater functionality.
What is a block device?
These devices transfer data in large fixed-sized blocks. Most commonly devices such as harddrives, filesystems, etc.
What is a Pipe Device?
They allow two or more processes to communicate with each other, these are similar to character devices, but instead of having output sent to a device, it’s sent to another process.
Similar to pipe devices but they can communicate with many processes at once
Socket device
What does the major device number represent?
The device driver that is used
What does the minor device number represent?
The minor number tells the kernel which unique device it is in this driver class
A protocol used for allow communication between disks, printers, scanners and other peripherals to your system
SCSI (pronounced “scuzzy”) protocol.
SCSI stands for Small Computer System Interface
What does Linux identify with a prefix of sd?
sd (SCSI disk)
Linux systems correspond SCSI disks with hard disk drives in /dev
What is the name of the first and second hard disks in Linux?
First hard disk: /dev/sda
Second hard disk: /dev/sdb
e.g. /dev/sda3 - Third partition on the first hard disk
What are some of the most common pseudo devices?
The most common pseudo devices are character devices:
/dev/zero - accepts and discards all input, produces a continuous stream of NULL (zero value) bytes
/dev/null - accepts and discards all input, produces no output
/dev/random - produces random numbers
Sometimes in older systems you may see hard drives being referred to with what prefix?
hd
/dev/hda - First hard disk
/dev/hdd2 - Second partition on 4th hard disk
What was created to better manage devices on our system than the /dev directory?
A virtual filesystem, Sysfs, most often mounted to the /sys directory
What is the difference between /sys and /dev?
/sys gives us more detailed information than what we would be able to see in the /dev directory
The /dev directory is simple, and it allows other programs to access devices and interact with them
The /sys filesystem is used to view detailed information about the devices, and to manage the devices
$ mknod /dev/sdb1 b 8 3
This is the old way of creating a device node.
This command will make a device node /dev/sdb1 and it will make it a block device (b) with a major number of 8 and a minor number of 3.
How would you remove a device node using old methods?
To remove a device, you would simply rm the device file in the /dev directory
Dynamically creates and removes device files for us depending on whether or not they are connected
The udev system
What does the udevd daemon do?
It’s a daemon that is running on the system and it listens for messages from the kernel about devices connected to the system
What does udevd do when it finds a new device?
Udevd will parse the information and it will match the data with the rules that are specified in /etc/udev/rules.d.
Depending on those rules it will most likely create device nodes and symbolic links for the devices
How can you view the udev database and sysfs?
By using the udevadm command
Name the tools that list information about devices like the ‘ls’ command lists files and directories.
Listing USB Devices: lsusb
Listing PCI Devices: lspci
Listing SCSI Devices: lsscsi
A tool which reads input from a file or data stream and writes it to a file or data stream
dd
e.g. $ dd if=/home/pete/backup.img of=/dev/sdb bs=1024
if - input file
of - output file
bs - bytes
What tool can be used to make backups of anything, including whole disk drives?
dd
Linux filesystems structure should conform to what?
Filesystem Hierarchy Standard
The character for the root directory of the entire filesystem hierarchy
/
Everything is nestled under this directory
Essential ready-to-run programs (binaries) including the most basic commands such as ls and cp
/bin
Contains kernel boot loader files
/boot
Device files directory
/dev
Core system configuration directory that should hold only configuration files and not any binaries
/etc
Personal directories for users, holds your documents, files, settings, etc.
/home
Holds library files that binaries can use
/lib
Used as an attachment point for removable media like USB drives
/media
Temporarily mounted filesystems
/mnt
Optional application software packages
/opt
Information about currently running processes
/proc
The root user’s home directory
/root
Information about the running system since the last boot
/run
Contains essential system binaries which usually can only be ran by root
/sbin
Site-specific data which are served by the system
/srv
Storage for temporary files
/tmp
User installed software and utilities
/usr
Inside this directory are sub-directories for /usr/bin, /usr/local, etc.
Used for anything that is subject to change all the time like system logging, user tracking, caches, etc.
/var
A layer between applications and the different filesystem types, so no matter what filesystem you have, your applications will be able to work with it
Virtual File System (VFS) abstraction layer
What is a journaled system?
The system keeps a log file (journal) in order to keep track of tasks. The filesystem is always in a consistent state because of this, so it will know exactly where you left off if your machine shutdown suddenly.
This also decreases the boot time because instead of checking the entire filesystem it just looks at your journal.
The most current version of the native Linux filesystems
ext4
Compatible with the older ext2 and ext3 versions
A new filesystem for Linux that comes with snapshots, incremental backups, performance increase and much more
Btrfs - “Better or Butter FS”
High performance journaling file system, great for a system with large files such as a media server
XFS
Windows filesystems
NTFS or FAT
Macintosh filesystem
HFS+
This command reports file system disk space usage and other details about your disk
df
Hard disks can be subdivided into what?
Partitions
This is essentially making multiple block devices
What is a partition table?
This table tells the system how the disk is partitioned
The two main partition table schemes used
- ) Master Boot Record (MBR)
2. ) GUID Partition Table (GPT)
Space on a disk that is not allocated to a partition
Free space
Can partitions overlap?
No
You can have multiple partitions on a disk and they can’t overlap each other