203.2. Maintaining a Linux filesystem

203.2 Maintaining a Linux filesystem​

Weight:3

Description: Candidates should be able to properly maintain a Linux filesystem using system utilities. This objective includes manipulating standard filesystems and monitoring SMART devices.

Key Knowledge Areas:

  • Tools and utilities to manipulate and ext2, ext3 and ext4

  • Tools and utilities to perform basic Btrfs operations, including subvolumes and snapshots

  • Tools and utilities to manipulate XFS

  • Awareness of ZFS

Terms and Utilities:

  • mkfs (mkfs.*)

  • mkswap

  • fsck (fsck.*)

  • tune2fs, dumpe2fs and debugfs

  • btrfs, btrfs-convert

  • xfs_info, xfs_check, xfs_repair, xfsdump and xfsrestore

  • smartd, smartctl

File Systems Overview

Since lpic 1 course we have got familiar with some File Systems. Lets Compare important ones:

File System

Architecture

Max File Size

Max Volume Size

extends

journal

snapshot

ext2 (1993)

h-tree

2 Tbytes

32 Tbytes

No

No

No

ext3 (2001)

h-tree

2 Tbytes

32 Tbytes

No

Yes

No

ext4 (2006)

h-tree

16 Tbytes

1 Ebytes

Yes

Yes

No

xfs (1994)

b-tree

8 Ebytes

8 Ebytes

No

Yes

Planned

btrfs (2009)

b-tree

16 Ebytes

16 Ebytes

Yes

Yes

Yes

mkfs

mkfs (Make a file System) command is used to create a File System on a device.To review LPIC1:

We saw that mkfs is a front end for other commands:

We can use mkfs.ext4 /dev/sdb1 to format a partition or in another format:

mkswap

There is an exception among File Systems which is swap. We have mentioned that swap can be a file or an entire partition. To make a swap partition use mkswap /dev/sdXY command

File System maintenance Tools

Each file system has it own tools to maintain the problems.

fsck

fsck ( File System consistency check) is a tool for checking and repairing linux file system. Like mkfs, fsck is a front of other commands.

fsck is originally an ext tool . Try not to use fsck for other file systems because it might cause damage or data lost! How ever it is smart about other file systems like XFS and avoid running on them.

Do not forget you can not check a filesystem while you are using that, so do not forget to unmount!!!

fsck exit codes:

Based on health of ext Partition, different exit codes might be generated by fsck:

fsck usefull switeches

Description

-v

Produce Verbose output, include all file-system specific commands that are executed

-f

force fixing errors, ask conformation before each repair

-y

say "yes" to confirm fixing all errors

-n

emulate fixing errors, but no real write on hard disk

-N

Tell what fsck command will be run, and nothing is exexuted

-b <SuperBlockBackupLocation>

Restore super block from the backup

tune2fs

tune2fs Change different aspects of file system

fsck , tune2fs , fstab relation

Previously we see the fstab file for making automatic mounts, in the last field of fstab file we saw pass parameter:

We discussed then that the pass parameter can be 0, 1 or 2.

0

Never be checked by fsck during boot process

1

Check the partition with fsck duting boot with priority 1

2

Check the partition after other partitions with fsck priority2

But if you put 1 in fstab it would not work! Why? Because fsck look at other parameters of Partition File System and check intervals:

Among this long list Check interval and mount count are realy important. fsck check partitions we have mentioned in fstab if specific time interval arrives or number of mount count reach.

usefull commands

Description

tune2fs -L KING8GIG /dev/sdc1

Change Volume Name

tune2fs -i 7 /dev/sdb1

Change check interval to 7 days

tune2fs -c 10 /dev/sdb1

Change mount count to 10 times

tune2fs -m 0 /dev/sdb1

Change reserved Blocks to 0

dumpe2fs

dumpe2fs Show all super blocks info. SuperBlocks are kind of meta data of File System which keeps information about size, block size, the empty and filled blocks, size and location of inodes and many many more information. dumpe2fs can be used while partition is mounted.

As superbloacks are so important Files System is designed to keep back of them by copying them on several places of hard disk.

There is another way to observe location of super blocks backup:

-n cuase no changes on Hard disk and just show what it would do if it were to create a file system. And finally try dumpe2fs -h to get information about super blocks. Try it your self :)

debugfs

debugfs interactive file system editor.Its better to unmount the partition first.

maintenance XFS File System

XFS File System has its own tools.Base on our distro we might need to install xfsprogs to use XFS tools but XFS is Redhat Favorite File system so we use centOS7 here:

Okey we have Formatted and re partitioned /dev/sdb1 lets get to know about some XFS File System tools:

xfsprogs

Description

xfs_info

Give info about XFS Partition, partition must be mounted

xfs_repair

Fix XFS File System problem

xfs_check

Depricated ! Check XFS File System problems with no verbosity, use -v or "xfs_repair -n" instead

xfsdump & xfsrestore

XFS backup and restore commands, They can work with mounted partition as they are Backup & Restore process

xfs_info

xfs_repair

and if any problems have found use xfs_repair for that.

xfsdump , xfsrestore

There are two old xfs commands for backing up and restoring. They history back to days when tape media were only backup media.

There Three levels of backups that can be done woth xfsdump

xfsdump backup level

descriptio

0

Full backup

1

Only backup changed Files since Last backup

2

Backup File Changes since last full or Incremental Backup

Lets see the result:

and try to restore:

As you might not be an only admin of system use xfsrestore -I command to have a list of what ever has been backed up with xfsdump, including file sessions IDs and backup session IDs:

smartd , smartctl

S.M.A.R.T. (Self-Monitoring, Analysis and Reporting Technology) is a monitoring system included in computer hard disk drives (HDDs) and even solid-state drives (SSDs).So it is not linux specific tool or feature . it its duty is monitoring various indicators of Drive reliability in order to avoid hardware failures . Usually there is a software or 3rd party utility which is running on Host operating system which reads SMART data and notify user about health status of Disk Drive to avoid data lost.

Linux has two tiny tools smartd and smartctl for reading SMART data.Based on your distro you might need install smartmontool.

and to check weather our hard disk supports SMART and its enabled:

to do the <short|long|...> test on hard disk :

and for watching results:

some other usefull smartctl commands:

smartctl command

Description

smartctl -h /dev/sda

Print Help

smartctl -H /dev/sda

Print Health Status of Disk Drive

smartctl -c /dev/sda

Print SMART capabilities that have been implemented

Monitoring Disk Health inorder to avoid data lost can be an every day task, but SMART has deamon smartd wich dose it for us:

lets enable and use it vi /etc/default/smartmontools :

and make sure smartd is running and enabled:

Last updated