203.1. Operating the Linux filesystem

  • Topic 203: Filesystem and Devices

203.1 Operating the Linux filesystem

Weight:4

Description: Candidates should be able to properly configure and navigate the standard Linux filesystem. This objective includes configuring and mounting various filesystem types.

Key Knowledge Areas:

  • The concept of the fstab configuration

  • Tools and utilities for handling swap partitions and files

  • Use of UUIDs for identifying and mounting file systems

  • Understanding of systemd mount units

Terms and Utilities:

  • /etc/fstab

  • /etc/mtab

  • /proc/mounts

  • mount and umount

  • blkid

  • sync

  • swapon

  • swapoff

swap, swapon, swapoff

Previously we said that RAM is like a gateway of a town so that is too busy. Also we introduced some of techniques which is used by linux operating system in order to manage Memory. One of them was swap. Swap is emulated memory in disk. But what are its benefits and how dose it work ? Usually swap is used if computer run out of memory, in this condition two possible solutions are available. First avoiding user from running program or programs which require memory bigger that existing physical memory size and the second, crashing ! Obviously none of these solutions are acceptable. swap let us running programs and allocating them more memory than what we really have, by writing data on the hard disk temporarily. How ever this technique dose not guarantee performance.

swap can be put on a file(swap file) or can be an entire disk partition(swap partition)

swap file

Lets create a file and use it as swap space:

swapon -s command give us a summary of allocated swap spaces.

For being able to use this file as swap space, it should be populated and some meta data should be added, and its better to change the permission so just root has access to it:

and now lets add it to swap space

and the result:

in opposite to swapon command we can use swapoff to turn off swap on myswapfile.

swap partition

swap partition is usually made automatically during linux installation, but it is possible to manipulate that or add another swap partition as needed.

And lets add required meta data to desired partion before making swap on that:

and every thing is ready to put the swap on our new fresh partition:

use swapon -p to change the priority of using swap devices :

mount, umount , mtab, fstab

When we add a new internal hard disk to our computer it is bounded but it is not mounted. To make it usable first we need to make a partition on that, format it with a file system and then mount it, these is current setting of our computer:

as an example lets add a new 10GB hard disk :

Now lets mount /dev/sdb1 on a mount point to use it:

-t means what type of file system is going to be mounted, /dev/sdb1 is mount device and /mnt/my10ghdd is mount point.

mount command switches

Description

mount -V

Output version

mount -v

Verbose mode

mount -h

Prints help message

mount -a

mount all file systems mentioned in /etc/fstab file

mount -n /dev/sda7 /mnt/newpartition

mounting without writing in /etc/mtab file

mount -t <File System Type> /dev/sda7 /mnt/newpartition

indicates the File System ext2, ext3, ext4, iso9660, ntfs, swap, auto

mount -o <options> /dev/sda7 /mnt/newpartition

ro, rw, exec/noexec, suid/nosuid, dev/nodev, sync/async, user/users

Before exploring mount command options lets talk about sync/async concept:

sync/async

As spped difference between CPU and Hard Disk or other lazy devices, RAM are used. But Still there is a gap and latency between RAM and 3rd storage media. The solutions for omitting this speed gap are caches and buffers. Imagine CPU wants to write some thing on a poor floppy Disk. The data can be first stored in RAM and CPU can invest its valuable time on other things and than Data is writed down on floppy disk from ram.This is what logic accepts and usually happens, which is called "async". In opposite to "async" we have "sync" option which writes down dataat the same time on the floppy, and obviously take more time.

mount command options:

mount option

Description

ro

read-only

rw

read-write

exec/noexec

Permit/Prevent execution of binaries

suid/nosuid

Permit/Block the operation of suid, guid bits

dev/nodev

Interpret/Do not interpret character or block special devices on the file system

sync/async

I/O to the file system is done (a)synchronously

defaults

Use default options: rw, suid, dev, exec, auto, nouser, and async

remount

Attempt to remount an already-mounted file system, usually used to change mount options

/etc/mtab (contraction of mounted file systems table)

mtab is a file which is kept update with the mount subsystem.It lists currently mounted file system, how ever kernel doesn't do any thing with the mtab file. kernel puts its settings in /proc/mounts and /proc/self/mounts.

When we type mount the content of mtab file is shown:

They are the same, as mtab list includes some dynamically mounted system objects it shouldn't be edited by the Administrators.

/etc/fstab (file systems table)

Every thing seems right but our mounted devices are not persistent and wouldn't be accessible after reboot so far.To make a persistent mount we should use fstab. fstab is very similar to mtab but they are not related. fstab is more easier to edit:

Desciption:

Item

Example

Description

<file system>

/dev/floppy0 or UUID

Device/partion that contains file system

<mount point>

/media/floppy

Where do we wana mount device/partition

<type>

ext4

Type of File system

<option>

rw, user, noauto, exec, ...

mount options of accessing device/partition

<dump>

0 or 1

enable/disbale backing up device/pertition

<pass>

0 or 1 or 2

Control the order of fsck check partition/device during boot process

Lets take a look at fstab mount options:

fstab mount options:

Obviously fstab mount options and mount command options are the same but there some options which are meaning full if we are talking about fstab configuration:

mount option

Description

user

Allow an ordinary user to mount the file system. The name of the mounting user is written to mtab so that he can unmount the file system again.This option Implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line user,exec,dev,suid)

users

Allow every user to mount and unmount the file system. Implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line users,exec,dev,suid).

nouser

Forbin an ordinary user to mount the File System, this is the default

auto

File System can be mounted Automatically after boot . using mount -a option also mount Device/partition if it is not mounted

noauto

The File System will NOT be automatically mounted after reboot, mount -a wouldn't considering this Device/Partition.You must explicitly mount the filesystem.

_netdev

filesystem resides on a device that requires network access (used to prevent the system from attempting to mount these filesystems until the network has been enabled on the system)

blkid

blkid show all information of block devices in our system,

in fstab we can use UUID (Universally Unique Identifier) instead of Device abstract name from /dev/ directory. This way we reduce the mount fails because HAL might change the name as time passes and other Disks are installed.

And Finnally lets go back and make the swap partition permanent by editing fstab file :

and another way to see UUID of devices is:

Last updated