CS469 - Linux and Unix Administration and Networking

Making filesystems:

# mkfs [-t type] [fsoptions] device
# mke2fs [-t type] device

  • Formats a block device or file into a filesystem.

    -ttype (ext2 / ext3 / ext4 / xfs / jfs / etc)
    -m res Reserved for root percentage (a percentage of the disk set aside only for root in case regular users fill the drive.
    -i b/inode Bytes / Inode (determines how many inodes will be available)
    -j Create w/ ext3 journal (automatic for ext3/4)
    -E opts Extended options like stride=, etc.
    -c Check for bad blocks.
FS type Description
ext2 Original Linux file-system, lacks many modern features
ext3 Extension of ext2 which added Journaling (method of preventing data loss on power-failures)
ext4 Further extension of ext3 with proper 64 bit support
btrfs "Better FS", slow but lost of new features.
xfs Default for Red Hat, reasonably fast and efficient, but a bit old now
jfs IBM journaled file-system
Other OS file-systems
vfat Virtual FAT, extends FAT (MS DOS) file-systems with long filenames, supports all FAT through FAT32
ntfs Windows NTFS
Virtual file-systems
tmpfs Temporary ram drive file-system
proc Proc virtual filesystem (/proc)
sysfs System virtual filesystem (/sys)
devpts Virtual pseudo-terminal device file-system (/dev/pts)

# fsck [-a] device

  • Check and repair a (or all: -a) file-system.

# e2fsck device

  • Check and repair a ext[2-4] filesystem.

> yes [string]

  • Print 'y' or a lot.

# badblocks [-svw] [-o out] device

  • Check device for bad blocks. Mostly useful for checking old style spinning disk drives.

    -s Show progress
    -v Verbosity
    -w Perform a write-test
    -o out Output bad block #'s to out

# e2label <device>

  • display or change the label on a ext* filesystem.

# tune2fs [-l] device

  • List / adjust ext* filesystems.

# /sbin/mkfs.*
# /sbin/fsck.*

  • Helper symbolic links to the real programs to make/check a filesystem, i.e.
    /sbin/mkfs.ext4 -> mke2fs

Standard block devices:

SCSI/SATA/SAS hard drives.

  • Drives connected to a computers SATA (Serial ATA (AT Attachment, AT from the now ancient PC/AT computer standard)) or SAS (Serial Attached SCSI) or the now deprecated SCSI (Small Computer Systems Interface). USB drives also use /dev/sd* device names.
     │   │   └── Partition number
     │   └────── Drive enumeration
     └────────── Block device driver type

Old IDE devices used /dev/hd* device names, however those device names may be deprecated in favor of /dev/sd*.



  • Partition 1 on the first SATA drive (sda)


  • Partition 3 on the third SATA drive (sdc)

Raid (MD) devices:

  • RAID (Redundant Array of Inexpensive Drives) is a collection of two or more block devices usually arranged together to provide either protection from data loss, improved throughput, or both. These block devices are the virtual software RAID block devices. We'll discuss making these in next weeks lessons.


Ram Drives:

  • Ram drives are in virtual in-memory file-systems, often used for placing temporary data (such as /tmp or /var/run) or data that needs very fast, low latency accesses (such as some database applications.)


Loop-back devices:

  • Used for mounting images (files that contain a filesystem), often CD-ROM images.



# mount -o loop ./cdrom.iso /mnt/cdrom

  • Mounts the cdrom.iso image at /mnt/cdrom, allocating /dev/loop0 automatically for us.

NVME devices:

  • NVMe or Non-Volatile Memory Express devices provide storage (usually in the form of solid state, NAND flash) that is directly attached to a CPU via it's PCI Express (PCIe) data bus (normally a 4x connection (i.e. 4 individual data lines) providing a theoretical 3.94GB/s throughput w/ PCIe version 3, twice that with PCIe version 4.)
           │     │     └── Partition number
           │     └──────── Drive enumeration
           └────────────── NVMe Bus enumeration

Other device files:

Sometimes the kernel may for some reason re-order physical devices (particularly when adding/removing other devices,) which would prevent the system from mounting the requestd file-system. To overcome this problem, many file-systems allow the option of specifying a user-defined label for the file-system or may be referred to by a UUID (Universally Unique ID - auto-generated when the file-system is made.) Theses labels or UUID's can be displayed by special /dev/disk entries, such as:


  • Lists devices/file-systems by their UUID, use UUID=uuid in /etc/fstab in place of the regular device file., i.e.:
    UUID=6d65a372-a94b-4fd9-a5d3-1c14b2cb5a1e ...


  • Lists devices by their user-defined labels (if it has one.) Use LABEL=label in /etc/fstab in place of the regular device file name, i.e.:
    LABEL=root ...

I personally prefer file-system labels as they are easier to use and remember and can provide meaningful information about what is contained on the file-system.

Programs to list block devices:

> lsblk

  • List block devices.

# blkid

  • List information about block devices.

Example file-system:

> dd if=/dev/zero of=fsimage bs=1k count=64

  • Makes a 64K blank file called fsimage

> mkfs -t ext4 ./fsimage

  • Formats it to be an ext4 filesystem

> mount -o loop ./fsimage /mnt

> cd /mnt

The /dev filesystem

We've been discussing a lot of device files, and in Unix things should present as much as possible as a file. There are two types of device files in Unix, those being character special and block special. A character special device is like a serial device, where data is read from it, but cannot be re-wound, i.e. there is no seeking to different points of the input. A block special device on the other hand is like a linear array of data, any point of which can be seeked to and read/written. In this way a block device is like a regular file with its data.

Normally device files are created for us automatically as required by the system, normally the udev system, and /dev itself is a special devtmpfs filesystem (like a tmpfs ram-drive.)

We can however create device files in /dev or any other file-system ourselves if need by using the mknod program.

# mknod name type [major minor]

A normal user can use mknod to create FIFO (named pipes) files (it is probably easier to just use mkfifo which is specifically made for that task,) but to create character or block special devices requires super-user privileges.

The type can be 'c' or 'u' for a character special device, 'b' for a block special or 'p' for a named pipe. Named pipes do not require a major or minor number.

Major/minor numbers are used by the kernel to reference a specific device in the system and can be viewed on a block or character device using the ls command. They appear as comma separated numbers in the place a file-size would normally appear:

~> ls -la /dev/null /dev/sda1
crw-rw-rw- 1 root root 1, 3 Mar 16 10:49 /dev/null
brw-rw---- 1 root disk 8, 1 Mar 16 10:49 /dev/sda1

Here we see that the /dev/null device has major #1 and minor #3 and the first partition on /dev/sda has major #8 and minor #1.

You will likely rarely need to worry about device files, but you should be aware of the mknod command and how the kernel keeps track of what device is which via the major/minor number system.


  • Reading: man 4 fstab

The system file-system table, lists file-systems that the system should know about, including those devices that should be mounted at boot time. Even those devices that you don't want to mount at boot (mount option: noauto) should be added if they are periodically mounted so that they can be mounted by their mount point, rather than device name.

Format (by field):

  • The device or file (such as a swap file), may be a LABEL=X or UUID=X entry instead.

  • The mount point, where on the file-system the device should be mounted, if the device has no mount-point you can use anything here, such as none.

  • Type of FS, use auto if you want the kernel to try to automatically determine the file-system type being used (often used for removable media devices.)

  • Mount options (comma separated)

    Option What it does
    * defaults Mount with default options (rw,suid,dev,exec,auto,nouser,async)
    * noatime Don't update atime records on files
    * noauto Don't mount it explicitly (mostly used in /etc/fstab)
    nodev Don't interpret device files on the file-system
    * noexec Don't execute binaries on the file-system
    nosuid Don't allow setuid binaries on this file-system
    * remount Remounts the file-system with the new options
    * ro Mount file-system in read-only mode
    rw Mount FS in read-write mode (default)
    user Allow a user to mount
    owner Allow the device owner to mount

    * = remember these (may be useful in the future)

  • Historically used by the "dump" command (used to backup file-systems to tape archival devices.) May be used by other programs.

  • "fsck" pass number for file-systems that need to be checked. Should generally be 1 for the first partition that should be checked on each device and 2 for the second etc.

Example /etc/fstab:

# Lines starting with # are comments:
# Device         mnt-point        fs-type     mount-options    dmp fsck-pass
/dev/nvme0n1p2   swap             swap        defaults         0   0
/dev/nvme0n1p3   /                ext4        defaults         1   1
/dev/nvme0n1p1   /boot/efi        vfat        defaults         1   0
#/dev/cdrom      /mnt/cdrom       auto        noauto,owner,ro,comment=x-gvfs-show 0   0
/dev/fd0         /mnt/floppy      auto        noauto,owner     0   0
# These are "virtual" devices:
devpts           /dev/pts         devpts      gid=5,mode=620   0   0
proc             /proc            proc        defaults         0   0
tmpfs            /dev/shm         tmpfs       nosuid,nodev,noexec 0   0



  • Currently mounted filesystems (in fstab format.) /etc/mtab is maintained by the mount command, while /proc/mounts is maintained by the kernel.

Monitoring disk I/O:

# iostat [interval [count]]

  • Display CPU and disk I/O stats.

# vmstat [interval [count]]

  • Display virtual memory statistics.


  • Commands to remember:
Command What it does
mkfs.* Make a file-system
fsck.* Check/repair a file-system
lsblk List block devices and partitions
mknod Make a device file
iostat View current I/O usage
vmstat View current memory usage
  • Files/dirs to remember
File/dir What it's for
/dev The device files directory
/dev/disk/by-uuid/* Storage devices listed by their UUID
/dev/disk/by-label/* Storage devices listed by their label
/etc/fstab The file-systems and mount-points registry
/etc/mtab The mounted file-systems (maintained by mount)
/proc/mounts Mounted file-systems (maintained by the kernel)