Mounting a File System on a Linux machine


In this short tutorial I’ll show you how to mount and unmount File Systems on a Linux machine. Note that I’m using a CentOS VM hosted in my VMware environment. Until this point you should have added a new disk and partitioned it according to your needs. After the partitioning process is completed, make sure to add a File System to your newly created partitions.
Once all the above steps are completed we’ll need to mount the two partitions on our System. To achieve these results we’ll use the mount command. If you type this command without any parameters, all mount points will be displayed:
Linux mount command
Before we go ahead and mount the two partitions, we’ll need to create two individual folders for them. Usually, the default location on which partitions are mounted is /mnt. I’ve created two folders in this location:
How to mount a File System in Linux
We can now mount the two partitions by typing the following:
mount /dev/sdb1 /mnt/Disk2p1/
mount /dev/sdb2 /mnt/Disk2p2/
At last we can check out that the mounting operation was successfully:
How to mount Linux partitions
We can check out the file system information on the two partitions by running the
 dumpe2fs /dev/sdb1 | less and  dumpe2fs /dev/sdb2 | less commands:
dumpe2fs command
Type df -hT to check out storage space information for your Linux machine:
How to check out storage information on a Linux machine
Several fields are listed when df command is executed:
– filesystem device
– filesystem type
– total size of a particular filesystem
– used space
– available space
– percentage of used space
– mount point location
Linux offers another command to check disk space usage within the System. You can use du command to verify the disk usage of each directory within the hierarchy. For example, you can navigate to /etc and execute du command to evaluate this directory. -s option can be used to activate summary mode and display the overall disk usage of a particular folder:
Linux du command
To unmount a partition simply type umount /dev/sdb2:
How to use the umount command
Use dmesg to view the information from the kernel regarding the mounting operations. From Wikipedia: “dmesg (display message or driver message) is a command on most Linux– and Unix-based operating systems that prints the message buffer of the kernel.”
dmesg command
 
Just like in Windows, Linux has a utility to scan and fix bad blocks on the hard drive. Simply use the following command to check a partition: fsck.ext4 -v /dev/sdb2
Linux partition check tool
fsck can also be used to check the file system. Note that unless you are sure that the check will not make you loose any data, don’t use the disk check tool directly. You can run it without modifying data blocks by using the fsck -n option. There are several important options available with this command so take some time and study the man page.
Note that for all mount operations, the System stores a mount database  in /etc/mtab. The mount operation will fail of it cannot write to this file. There are a lot of short and long options that can be used with mount so take some time and study the man page for this command.
Advertisements

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