Must-know Topics on Linux

Table of Contents

  1. System Architecture (2–3)
  2. Linux Installation and Package Management (2–3)
  3. GNU and Unix Commands (4)
  4. Devices, Linux Filesystems, Filesystem Hierarchy Standard (3–4)
  5. Shells and Shell Scripting (4)
  6. User Interfaces and Desktops (1–2)
  7. Administrative Tasks (4-5)
  8. Essential System Services (3–4)
  9. Networking Fundamentals (4–5)
  10. Security (3)
  11. Other

2. Linux Installation and Package Management

Design hard disk layout

(Link1, Link2)

  1. The entire hierarchy of directories that is used to organize files on a computer system. On Linux and Unix, the directories start with the root directory , which contains a series of subdirectories, each of which, in turn, contains further subdirectories, etc. A variant of this definition is the part of the entire hierarchy of directories or of the directory tree that is located on a single partition or disk.
  2. The type of filesystem, that is, how the storage of data is organized on a disk or on a partition on a hard disk. Each type of filesystem has its own set of rules for controlling the allocation of disk space to files and for associating data about each file (referred to as meta data) with that file, such as its filename, the directory in which it is located, its permissions and its creation date.
  • Partition is a logical division on a hard disk drive. e.g. /dev/sda1 of /dev/sda. It contains a single type of filesystem. Although partitions are logically independent, they become logically connected when they are mounted. We can use df -h, mount -l, cat /proc/partitions, fdisk -l to confirm partitions.
  • Mount point is a directory (typically an empty one) in the currently accessible filesystem on which an additional filesystem is mounted. Mount a partition named /dev/hda5 (which is the fifth partition on the first HDD), a new directory could be created for it, such as /par5, then mount it with: mount /dev/hda5 /par5 .

What happens if mounting a device to a mount point that is not empty?When you want to mount a CD-ROM, /dev/sr0, at the mount point /media/cdrom. When you mount the CD-ROM, the files and subdirectories on the CD-ROM become the files and subdirectories in and below /media/cdrom. Any files or subdirectories that were already in /media/cdrom are no longer visible, although they still exist on the block device that contained the mount point /media/cdrom. If the CD-ROM is unmounted, then the original files and subdirectories become visible again.

  • LVM (Logical Volume Manager) is designed for the cases you need to resize your partitions or even add new disks and add them to your mount points. LVM helps you create one partition from different disks and add or remove space to them. The main concepts are:
  1. Physical Volume (PV) is a whole drive or a partition. It is better to define partitions and not use whole disks — unpartitioned.
  2. Volume Groups (VG) is the collection of one or more PVs. OS will see the VG as one big disk. PVs in one VG, can have different sizes or even be on different physical disks.
  3. Logical Volumes (LV): OS will see LVs as partitions. It is analogous to a physical GPT or MBR partition in the sense that it is the unit of space that is formatted with a particular filesystem type, such as ext4 or XFS, and is then mounted as part of your Linux filesystem. An LV resides entirely within a VG.
  • Swap works like an extended memory. Kernel will page memory to this partition / file. It is enough to format one partition with swap file system and define it in /etc/fstab.

swap size is 1 or 2 times the system memory but not more than 8GBs.

3. GNU and Unix Commands

The Linux command line

  • The echo command prints (or echos) its arguments to the terminal.
$ echo Where     are   my   spaces? # all the extra spaces were compressed down to single spaces
Where are my spaces?

4. Devices, Linux Filesystems, Filesystem Hierarchy Standard

Create partitions and filesystems (Link1 Link2)

  • Blocked devices is a technical term for any storage device which can be formatted to fixed sized blocks and blocks should be able to be accessed individually. That is Hard disks, USB Memories, CDs, . Some block devices mostly used as one single filesystem (like CDs & Floppies) and some are divided into Partitions (Hard disks).
21:06:38 [name@host ~]$ ls -l /dev/vda
brw-rw---- 1 root disk 252, 0 Aug 27 2015 /dev/vda
  • fdisk is the main command for viewing or changing and creating partitions. -l switch is for show. fdisk -l /dev/sda.
  • Formatting the partition. Linux can handle more than 100 kind of partitions. One important attribute of a filesystem is journaling, which allows for much faster recovery after a system crash. A journaling filesystem is preferred over a non-journaling one. The followings are the most common formats.
  1. The ext2 filesystem is a non-journaling type, it has largely been replaced by ext3 and more recently ext4.
  2. The ext3 filesystem adds journaling capability to a standard ext2. It offers reasonable performance.
  3. The ext4 filesystem started as extensions to ext3 to address the demands of ever larger file systems by increasing storage limits and improving performance.
  4. ReiserFS is a B-tree-based filesystem, great for large numbers of small files, journaling, no longer in active development & does not support SELinux, replaced with Reiser4.
  5. The XFS filesystem is a filesystem with journaling. It comes with robust features and is optimized for scalability. XFS aggressively caches in-transit data in RAM.
  6. The swap filesystem. Swap space must be formatted for use as swap space, but it is not generally considered a filesystem.
  7. The vfat filesystem is known as FAT32, it is not journaled and lacks many features required for a full Linux filesystem implementation.
  • You can format your partitions with mkfs command (and mkswap for swap).e.g. to format a partition to ext3, we can do either of below.
mkfs -t ext3 /dev/sda1
mkfs.ext3 /dev/sda1

Procedures of add/extend disk
1. Recognize disk. echo “- — -” > /sys/class/scsi_host/host0/scan , fdisk -l | grep Disk
2. Make partition. fdisk -u sdx => sdb2 => write
3. Create PV. pvcreate -vd /dev/sdb2
4. Extend VG. vgextend -vd $VG /dev/sdb2
5. Extend LV. lvextend -l +100%FREE -vd /dev/$VG/$LV
6. Extend Filesystem. resize2fs /dev/$VG/$LV. The size of mount point mapping to this LV will be changed.

Maintain the integrity of filesystems

  • fsck is used to check and optionally repair one or more Linux file systems. e.g. fsck /dev/sdb.
  • inodes contain the information about files. Information like the owner, when the last time it is used or edited, its size, if it is a directory or not and people access rights on. The inode number is unique within a particular filesystem and is also called files serial number. df -i.

Control mounting and unmounting of filesystems

mount /dev/sda1 /media
umount /media



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store