3.2. Maintaining a Linux Filesystem

This section covers a list of commands related to filesystem maintenance.

3.2.1. fsck

fsck - check and repair a Linux filesystem

Main options:

-b

use alternative superblck

-c

check for bad blocks

-f

force checking even when partition is marked clean

-p

automatic repair

-y

answer yes to all question

3.2.2. sync

sync - flush filesystem buffers

Updates modified superblocks and inodes and executes delayed writes. The operating system keeps data in RAM in order to speed up operations. This may cause data to be lost in the event of a crash unless sync is executed. Sync will simply call the sync system call. Another way of doing this is to use the 'ALT+sysreq+s' key combination

3.2.3. hdparm

hdparm - get/set hard disk paramters

The hdparm tool is used to control I/O options for ATA/IDE device drivers

The main options are

-a

Get/set filesystem readahead. This is used to improve read performance by reading additonal disk blocks ahead of time.

Example:

hdparm -a /dev/hda
/dev/hda:
 readahead    = 256 (on) 
-B
Set the advanced power management feature. A value from 1 to 255 is expected. The power saving mode is highest for low values and better performance is obtained for higher values.
-c
Enable (E)IDE 32-bit I/O support. This is only for data transfers from the PCI bus to the IDE controller and not along the disk ribbon, which still uses 16-bits.
-d

Enable the "using_dma" flag for the drive. This almost always increases performance.

Example:

 hdparm -d1 /dev/hda

 /dev/hda:
 setting using_dma to 1 (on)
 using_dma    =  1 (on)

-i

This option prints out the information about the current driver settings.

3.2.4. badblocks

badblocks - search a device for bad blocks

It is recommended NOT to use badblocks directly but to use the -c flag with fsck or mkfs.

Main options:

-b

block size

-c

number of blocks tested at a time

-i

file with a list of known bad blocks, these blocks will be skipped

-o

output file, passed to mkfs

3.2.5. mke2fs

mke2fs - create an ext2/3 filesystem

Main options:

-b

blocksize

-i

number of bytes between consecutive inodes 'bytes-per-inode'

-N

number of inodes

-m

Percentage of blocks reserved for user root

-c

Check for bad blocks

-l

Read bad blocks from file

-L

Set a volume LABEL

-j or -J

Create journal (ext3)

-T

Optimise filesystem type, values are:

news

one inode per 4KB block

largefile

one inode per megabyte

largefile4

one inode per 4 megabytes

3.2.6. dumpe2fs

dumpe2fs - dump filesystem information

dumpe2fs prints the super block and blocks group information for the filesystem present on a device

3.2.7. debugfs

debugfs - ext2 file system debugger

debugfs is used to test and repair an ext2 filesystem.

The main options are:

-w
open the filesystem as writeable
-b
set blocksize

3.2.8. tune2fs

tune2fs - adjust tunable filesystem parameters on second extended filesystems.

Main options:

-l

read the superblock

-L

set the device's volume LABEL

-m

change the filesystem's reserved blocks for user root

-j or -J

set a journal