Disk and Filesystem Commands


In this chapter we’ll handle some basic methods for examining disks and partitions in Linux.  These commands need to be used carefully as it would be easy to accidentally erase data, and that’s never good!

Before we talk too much about partitions and mount points it is important to understand that a Linux mount point can be anywhere you could put a directory.  While at the base of any Linux system there is a / directory, commonly called the root directory a partition may be mounted anywhere below that.  Here are some examples of common mount points and what you might find there:

Mount Point Contents
/ the slash partition is where everything starts
/boot contains essential boot files
/usr/local reserved for installed software ‘local’ to this computer
/tmp temporary files for this system or any applications on it

Here we see that /usr/local is listed as a partition; however, it does not come directly below the root (/) partition.  This takes a little getting used to, but just be aware that a disk partition can be mounted anywhere.

Displaying File System Information

It is very common to have to examine disk use to determine where there is free space, where the disk may be nearing full and where you may need to add disk or move files.  One of the most essential commands used to examine disks is the df command.

The df command is used to display information about mounted file systems.  By default the df command will typically return disk information in kilobytes.  Since there can be variation on this default behavior it is often nice to use the –k option which will force df to displays disk space usage in kilobytes as seen in this example:

$ df -k

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hdf1             18727836   2595832  15180656  15% /
/dev/hda1               101086      5945     89922   7% /boot
none                    128560         0    128560   0% /dev/shm

These results show that two file systems are mounted.  The Filesystem column of the output shows the path to the disk device which is currently mounted at the Mounted on location.  The 1K-blocks column displays the size of the entire partition while the Used and Available columns indicate the number of 1K blocks on that device used and available.  The Use% column will show what percentage of the disk is currently used and is the quickest way to identify disks which are getting full.

To get the display in a friendlier format, the –h option can be used:

$ df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/hdf1              18G  2.5G   15G  15% /
/dev/hda1              99M  5.9M   88M   7% /boot
none                  126M     0  126M   0% /dev/shm

The  -h option will show output in the familiar gigabyte, megabyte or kilobyte (G, M or K respectively) scales.  This makes things more human readable, hence the h.

It is easy to see that the first file system is 18GB in size, with 2.5GB used and 15GB of available free space. It is mounted on the root (/) mount point.

The second file system is 99MB in size, with 5.9MB used and 88MB of available free space. It is mounted on the /boot mount point.

This output also shows a shared memory space of 126MB currently available (/dev/shm).

Creating a File System

Some file systems are created automatically during the Linux installation process.  For instance, when I set up a system with Fedora Core 2 (Red Hat) for this book, the installation tool detected the two disk drives and offered to automatically configure their partitions and setup a file system.

There are many different types of file systems. Microsoft Windows administrators are familiar with filesystems like FAT16, FAT32, and NTFS.  The comparable options on Linux are ext2, ext3, and Linux-swap.  The differences between these filesystem types are beyond the scope of this book.

During the lifetime of a Linux system it is not uncommon to want to add additional disk space to a system by adding disks or replace a current drive with a larger capacity.  Here are some of the most useful commands for setting up disks:

Note:  You will need root privileges to to perform most of these tasks.

Command Function
fdisk Partition a hard disk
fsck Check and optionally repair one or more Linux file systems
mkdir Make a new file directory
mkfs Make a file system
mkswap Make a swap area on a device or in a file
mount Mount a file system (umount to unmount)
parted Disk partitioning and partition resizing program.  It allows the user to create, destroy, resize, move and copy ext2, ext3, Linux-swap,  FAT  and FAT32 partitions.
sfdisk List the size of a partition, the partitions on a device, check the partitions on a device, and repartition a device.

Table 3.1: Commands for file system creation

Copy from http://www.dba-oracle.com/linux/disk_filesystem_commands.htm

Advertisements
By dbglory Posted in Linux

One comment on “Disk and Filesystem Commands

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