Linux + Devices, Filesystems, Filesystems Hierarchy Standard

LX-103 – 104

104.1 Create Partitions and Filesystems

Manage MBR partitions table

Use various mkfs commands to create various filesystems such as,

  • ext2 / ext3 / ext4
  • XFS
  • VFAT

Awareness of ReiserFS and Btrfs

Basic knowledge of ‘gdisk’ and ‘parted’ with GPT

Commands : fdisk, gdisk, parted, mkfs, mkswap

Manage MBR Partitions Table

Storage devices are recognized by the MBR at the boot time.

Master Partition Table

  • Contains List Of partitions
  • Partition ID
  • Starting cylinder
  • Number of Cylinders

Master Boot Code

  • Contain program to load OS from disk
  • Initiate the boot process

FDISK utility

Used to create and manipulate partition tables

  • Does not support GUID Partitions Table (GPT)
  • List disk details -> fdisk -l /dev/sda
  • Edit partition table -> fdisk /dev/sdb

SFDISK Utility

Can be used to create and modify partitions

  • Does not support GUID Partitions Table (GPT)

‘partprobe’ updates kernel when changes are made. The partition table is re-read

Use various MKFS command to create various filesystems

The ‘mkfs’ command used to build a filesystem on the storage device.

Available mkfs tools are located in /sbin

  • ls /sbin/mkfs*
  • mkfs -t ext3 /dev/sdb1
  • mkfs.msdos -t ext3 /dev/sdb2

Enable journaling

  • mke2fs /dev/sdb1 -j

Check for bad blocks

  • mke2fs -c /dev/sdb1
  • fsck to file system check

Force filesystem creation on mounted partition

  • mke2fs -F /dev/sda5

Set inode size

Inodes are like pointers to files and directories. So it is important those pointers are available enough to point large number of files/directories in system.

  • mke2fs -i 8192 /dev/sdb1

Set filesystem label

  • mke2fs -L MyLabel /dev/sdb1

Re-write the superblock

Superblock is a filesystem components that has mapping of bad sectors and other details about the filesystem itself.

  • mke2fs -S /dev/sdb1

Create swap space with ‘mkswap’ command

  • 01. mkswap /dev/sdb1
  • 02. swapon /dev/sdb1
  •  swapon -s –> lists usable swap
  • swapoff /dev/sdb1 –> turn off swap
  • vi /etc/fstab

Basic Knowledge of GDISK and Parted with GPT

The GNU ‘parted’ utility can create, destroy and resize partitions.

parted -l

parted -a cylinder /dev/sda

‘resize2fs’ also can be used to resize partion

resize2fs /dev/sda1

104.2 Maintain integrity of Filesystem

Verify the integrity of the filesystems

Verify free space and inodes

Repair simple filesystem problems

Commands: du, df , fsck, e2fsck, mke2fs , debugfs, dumpe2fs, tune2fs, xfs_metadump, xfs_info

Filesystems may become corrupted due to misuse, power loss, or other issues.

The ‘fsck’ utility is primary usest to check and repair filesystem integrity.

  • Separate fsck commands exist for each filesystem type
    • Xfs_repair
  • May be run at boot, depending on configuration in /etc/fstab
  • Filesystems usually are unmounted
    • Fsck -y /dev/sdc1
    • Fsck -A
  • The ‘tune2fs’ utility is used to adjust ext filesystems
    • Tune2fs -l /dev/sdb1

-p                   Automatic repair (no questions)

 -n                   Make no changes to the filesystem

 -y                   Assume “yes” to all questions

 -c                   Check for bad blocks and add them to the badblock list

 -f                   Force checking even if filesystem is marked clean

 -v                   Be verbose

 -b superblock        Use alternative superblock

 -B blocksize         Force blocksize when looking for superblock

 -j external_journal  Set location of the external journal

 -l bad_blocks_file   Add to badblocks list

 -L bad_blocks_file   Set badblocks list

 -z undo_file         Create an undo file

To view filesystems of devices

df -Th

The disk usage (du) command shows storage stats for files and directories

  • du -a /usr
  • du -inodes /usr
  • du -h /sbin/* | sort -n
    • -h Digs deeper into directories
  • du -s /sbin/*

The disk free (df) command shows filesytems information

  • df -a
  • df -h
    • Size – appropriate size
  • df -H
    • size multiplies by 1000(aka marketing size)
  • df -i
    • Inodes described
  • df -t ext2
  • df -T

Show me the largest file underneath this directory

du -ah ~/Downloads/* | sort -n

104.3 Control mounting and un-mounting of Filesystem

Manually mount and un-mount filesystems

  • The mount and umount commads attach and detach filesystems to a mountpoint directory
  • Mount checks for filesystem entries
  • Filesystems can be mounted using a label

Configure file system mounting on bootup

  • The /etc/fstab cile contains information about filesystem use by the mount command.
  • Filesystem maintenance also includes updating ‘fstab’ file
  • The order of filesystem being mounted is significant

Field definitions for /etc/fstab

  • What will be mounted
    • Where will be mounted
    • Which filesystem type
    • Which options will be used
    • Will the ‘dump’ command be used to backup filesystem
    • Which order should filesystem be checked at boot time.

Configure user mountable removable filesystems

  • Allowing regular users to mount removable media may be convenient, but requires security considerations.
  • User-mounted filesystems will default to noexec unless exec is specified after the user option
  • Specifying noatime eilll disable access time recording

Using noatime may improve performance

  • sudo mkdir -p /media/user/usb
    • sudo chown user1 /media/user1/usb
    • sudo chmod 0777 /media/user1/usb
    • dmesg | grep -i usb
    • /dev/sdc1 /home/storage user, umask-000, utf8, noauto 0 0
      • etc/fstab definition for usb
    • sudo mount /media/user1/usb

mount -a

Re read the /etc/fstab file and mount any directories listed

104.4 Manage Disk Quotas

Commands : quota, edquoata, repquota, quotation

Setup Disk quota for the filesystem

Disk quotas enables set storage limits for and individual user.

Quota limits can be added to the /etc/fstab file

A ‘soft limit’ can be exceeded to for the duration of grace period.

The soft limit is enforced as a ‘hard limit’ once the grace period expires.

The hard limit cannot be exceeded

The ‘quotation, command enables quotas for the file system

quotacheck -c

creates quotas defined in /etc/fstab

Install ‘quota’ if not installed

apt install quota

quotacheck -cuav

Scans system for quota

‘repquota’ is utility for reporting quota

repquota -auvgs

To turn on quota for those specified on fstab

quotaon -augv

To specify a user for a quota limit

setquota -u user1 10 100 200 500 /mydata

setquota -u <user> <storage soft limit> <storage hard limit> <inode soft limit> <inode hard limit> <mounted point>

Finally, to enable quota

quotacheck -avf

These are not editable files. These are system files.

If you run ‘repquota -auvgs’ , you could see that quota being set to the specific user.

Quotas also can be set to groups.

setquota -g user 10 100 200 500 /mydata

Quota can be edit, using ‘edquota’ command

edquota user1

After editing, force it again with,

quotacheck -avf

‘warnquota’ command helps to report and quota violations

warnquota -u

Edit, Check and generate user quota reports

104.5 Manage file permissions and ownership

104.6 Create and change hard and symbolic links

104.7 Find system files and place in the correct location

Leave a comment

Your email address will not be published. Required fields are marked *