Linux Filesystems what to know?

Here are some things that might help you out :)
There is much more to know about linux filessytems, but this might be a good start :)

hope this helps :)

# Some commands, they might come in handy ;-)

############################################
df		        report file system disk space usage
df -h		        use the -h switch to display MBs instead of blocks.
df -i   	        show the free Inodes per file system
du		        estimate file space usage
du {file} -h	        use the -h switch to make the stats human readable.
tune2fs		adjust tunable filesystem parameters on ext2/3 filesystems.
tune2fs -l 	        show the actual filesystem superblock data {dev} should contain a SB.
e2label		Change the label on an ext2/3 filesystem
mkfs		        Build a linux file system
mke2fs		Build a Ext2 file system
mkisofs		Build a iso file system
mkudffs		Build a UDF file system
mkswap		Build a Swap file system
mkdosfs		Build a FAT File system
mkfs.vfat	        --
mkfs.msdos	        --
mount		Mount a linux filesystem
umount		Unmount a linux filesystem
swapon		Enable/disable devices and files for paging and swapping
swapoff		--
fsck		        Check a linux filesystem. (USE WITH CAUTION and RTFM FIRST!)
partprobe		inform the OS of partition table changes or list partitions on a device
parted		a partition manipulation program. A very strong but dangerious tool.
###########################################
# ALWAYS CONSULT THE MANPAGES BEFORE USING ANY
# OF THESE COMMANDS! KNOW WHAT THEY DO AND KNOW
# WHAT THEY WONT DO. SOME ARE DESTRUCTIVE WHEN USED
# INCORRECTLY!
###########################################

Linux devices
Next to these commands there is more to know about the linux filesystem. Most important aspect to know is how the fysical disks are made accessible. This is done by a process called mounting. When a linux OS boots it will probe for fysical attached disks and will create devices for each detected disk in the /dev/ directory. In some cases a device module (driver) is needed to be loaded into the kernel in order for it to access and probe the disk.

Depending on the device type a file (device) will be created in the /dev/ directory with a very specifik name. Here are some examples you might encounter in the /dev/ directory.

First MFM, RLL and IDE hard disk/CD-ROM interface
0 = /dev/hda		Master: whole disk (or CD-ROM)
64 = /dev/hdb		Slave: whole disk (or CD-ROM)

SCSI disk devices (0-15)
0 = /dev/sda		First SCSI disk whole disk
16 = /dev/sdb		Second SCSI disk whole disk
32 = /dev/sdc		Third SCSI disk whole disk

IBM iSeries virtual disk
0 = /dev/iseries/vda	First virtual disk, whole disk
8 = /dev/iseries/vdb	Second virtual disk, whole disk

For a full list check this site :)

http://www.kernel.org/pub/linux/docs/device-list/devices.txt

Linux Logical Volume management (LVM)
Linux also supports software raid. I wont be paying to much attention here because I allways advice people to use hardware raid instead. When you encounter “Volgroup##” inside the fstab you know an LVM group has been created. The LVM can be manipulated and verified using one of the following commands.

lvchange     lvdisplay    lvmchange    lvmsadc      lvreduce     lvresize
lvconvert    lvextend     lvmdiskscan  lvmsar       lvremove     lvs
lvcreate     lvm          lvmdump      lvm.static   lvrename     lvscan

please consult the manual for more details about these commands.

linux creating a filesystem and mounting
When a device is available in the devices directory you can actually start to use the device. One way of doing this is simply using the mount command stating, mount {device} {mountpoint}. But before doing this you need to decide what you want to do with the device. In most cases a filesystem will be created ontop of the device. For this task you can use the mkfs command or use parted to create partitions.

Please readup on the various filesystem types available. Commonly the Ext2 / Ext3 filesystems are used because they offer the best safety and manupilation options (ext3 doesnt support all the manipulation options ext2 supports). The following site is a good starting point when you are looking for more information on the subject.

http://www.yolinux.com/TUTORIALS/LinuxClustersAndFileSystems.html

Other options are mounting the disk without a filesystem in place a so called raw device, or use the device as swap space using swapon/off. Clustered filesystems are also an option but not described in this article.

Once you have decided how to use the disk, and the disk is available within linux (drivers etc) the next step would be making the disk available after boot. For this the fstab file is used. Simply add a new line with the correct parameters and the disk will be mounted at boot.

Some Important Files and their Locations.

/etc/fstab           Static Information about filesystems.  
/etc/mtab           Table of mounted filesystems
/etc/mtab~         Table of mounted filesystems lockfile
/etc/mtab.tmp     Temporary file
/etc/filesystems   A list of filesystems to try

Finaly, some tips while working with fylesystems.

TIP. Test the fstab file using the “mount -a” command before attempting a reboot. Best test is to unmount the disk prior to the mount -a command.

TIP. Also best practise is to modify disks, partitions, perform fsck`s in INIT 1. This will limit the ammount of running deamons dramaticly and will make your filesystem manipulation tasks much easier.

TIP. The mtab file will always list “devices” instead of “labels”. If you are wondering which device is used by a label try consulting the /etc/mtab.

TIP. In the /dev/ directory there might be a /disk/ directory. This directory will allow you to mount devices by the following attributes;
by-id,
by-label,
by-path,
by-uuid

This directory might come in handy when you are not sure what device was created by that usb disk you just plugged in. using the by-path for instance will show you de bus that is used by the various available disks, or by label that will show what label mappings exsist.
Always use the “ls -lart” command here to get the full details.

TIP. Be very carefull using the fsck command, it is well capable of destroying data on your disk if using incorrectly. Always read the manual fist using the manpages (man fsck).

About these ads

About Chris Gralike

Listen carefully to the people around you. Keep an open-mind, realize there is far more to learn, do, and accomplish. Treat your colleagues and competitors with respect and have FUN doing what you do best! These are my recommendations for success, what are yours? Find me at : LINKEDIN : http://www.linkedin.com/in/chrisgralike TWITTER : http://twitter.com/#!/chris_gralike WORDPRESS : http://sysengineers.wordpress.com/

Posted on April 20, 2010, in Linux, Linux Commands, Uncategorized and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink. 1 Comment.

  1. One other obvious-but-often-neglected thing that should be done *before* executing filesystems, LVM, RAID or any other storage related admin command, is to analyze the workload as described in an article I wrote some months ago:

    http://www.vigneras.name/pierre/wp/2009/07/21/choosing-the-right-file-system-layout-under-linux/

    Regards.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 54 other followers

%d bloggers like this: