Tuesday, July 22, 2008

File system and partition information in Linux/Unix

I would like to summarize some useful commands which can be used to obtain information about partition table and file systems.
Some basic information (model, capacity, driver version...) about hard disk can be obtained by accessing files under these directories:
/proc/ide/hda, /proc/ide/hdc ...(For IDE equitments)
/proc/scsi/  (For SCSI equitments).
Useful posts:
How to add new hard disks, how to check partitions...?
File system related information
Partitions and Volumes

Partition table:
All partitions of a disk are numbered next way: 1-4 - primary and extended, 5-16 (15) - logical.
(1) fdisk (from package util-linux)
Partition table manipulator for Linux.
fdisk -l device       //list partition table
fdisk -s partition    //get size of a partition. If the parameter is a device, get capacity of the device.

(2) cfdisk
Curses based disk partition table manipulator for Linux. More user-friendly.
cfdisk -Ps    //print partition table in sector format
cfdisk -Pr    //print partition table in raw format(chunk of hex numbers)
cfdisk -Pt    //print partition table in table format.

(3) sfdisk
List partitions:
sfdisk -s device/partition    //get size of a device or partition
sfdisk -l device                  //list partition table of a device
sfdisk -g device                 //show kernel's idea of geometry
sfdisk -G device                //show geometry guessed based on partition table
sfdisk -d device                //Dump the partitions of a device in a format useful as input to sfdisk.
sfdisk device -O file          //Just  before  writing  the new partition, output the sectors that are going to be overwritten to file
sfdisk device -I fiel           //restore old partition table which is preserved by using -O tag.
Check partitions:
sfdisk -V device                 //apply consistency check
It can also modify partition table.

(4) parted
An interactive partition manipulation programs. Use print to get partition information.

File system:
use "man fs" to get linux file system type descriptions.
/etc/fstab        file system table
/etc/mtab        table of mounted file systems
(1) df (in coreutils)
Report file system disk space usage.
df -Th    //list fs information including file system type in human readable format
(2) fsck (check and repair a Linux file system)
fsck is simply a front-end for the various file system checkers (fsck.fstype) available under  Linux.
(3) mkfs (used to build a Linux file system on a device, usually a hard disk partition.)
It is a front-end to many file system specific builder(mkfs.fstype).Various backend fs builder:
mkdosfs,   mke2fs,   mkfs.bfs,   mkfs.ext2,   mkfs.ext3,   mkfs.minix, mkfs.msdos, mkfs.vfat, mkfs.xfs, mkfs.xiafs.
(4) badblocks - search a device for bad blocks
(5) mount
(6) unmount

Ext2/Ext3
(1) dumpe2fs (from package e2fsprogs, for ext2/ext3 file systems)
Prints the super block and blocks group information for the filesystem.
dumpe2fs -h /dev/your_device      //get superblock information
dumpe2fs /dev/your_device | grep -i superblock      //get backups of superblock.
(2) debugfs (debug a file system)
Users can open and close a fs. And link/unlink, create...files.
(3) e2fsck (check a Linux ext2/ext3 file system)
This tool is mainly used to repair a file system.

No comments: