Introduction to mounting filesystems in Linux

DarkRaika
  • November 8, 2005
  • Read 309,728 times
 

Table of Contents

  1. Introduction
  2. Seeing a list of mounted filesystems
  3. The mount command
  4. How to unmount a filesystem
  5. Conclusion

Introduction

A filesystem is a way that an operating system organizes files on a disk. These filesystems come in many different flavors depending on your specific needs. For Windows, you have the NTFS, FAT, FAT16, or FAT32 filesystems. For Macintosh, you have the HFS filesystem and for Linux you have more filesystems than we can list in this tutorial. One of the great things about Linux is that you have the ability to access data stored on many different file systems, even if these filesystems are from other operating systems.

In order to access a filesystem in Linux you first need to mount it. Mounting a filesystem simply means making the particular filesystem accessible at a certain point in the Linux directory tree. When mounting a filesystem it does not matter if the filesystem is a hard disk partition, CD-ROM, floppy, or USB storage device. You simply need to know the device name associated with the particular storage device and a directory you would like to mount it to. Having the ability to mount a new storage device at any point in the directory is very advantageous. For example, lets say that you have a web site stored in /usr/local/website. The web site has become very popular and you are running out of space on your 36 GB hard drive. You can simply go out and purchase a new 73 GB hard drive, install it in the computer, and then mount that entire drive as /usr/local/. Now your /usr/local mount point has a total hard drive space of 73 GB, and you can free up the old hard drive by copying everything from the old /usr/local to the new one. As you can see, adding more hard drive space to a computer, while still keeping the same exact directory structure, is now very easy.


Seeing a list of mounted filesystems

In order to determine what filesystems are currently being used type the command:

$ mount

When you type this at a command prompt, this command will display all the mounted devices, the filesystem type it is mounted as, and the mount point. The mount point being local directory that is assigned to a filesystem during the process of mounting.


How to mount filesystems

Before you can mount a filesystem to a directory, you must be logged in as root (some filesystems can be mountable by a standard user) and the directory you want to mount the filesystem to must first exist. Also in some situations, you must be logged in as the root user in order to make the particular mount directory. If the directory exists, and any user can mount that particular device, then it is not necessary to be logged in as root. When mounting a particular filesystem or device you need to know the special device file associated with it. A device file is a special file in Unix/Linux operating systems that are used to allow programs and the user to communicate directly with the various partitions and devices on your computer. These device files are found in the /dev folder.

As our first example, lets use a real world example of accessing your Windows files from a floppy in Linux.

In order to mount a device to a particular folder, that folder must exist. Many Linux distributions will contain a /mnt folder, or even a /mnt/floppy folder, that is used to mount various devices. If the folder that you would like to mount the device to exists, then you are all set. If not you need to create it like this:

$ mkdir /mnt/floppy

This command will have now created a directory called /mnt/floppy. The next step would be to mount the filesystem to that folder or mount point.

$ mount -t msdos /dev/fd0 /mnt/floppy

You have now mounted an msdos filesystem, which is indicated by the -t (type) option. The device is recognized by the /mnt/floppy point. Now you can access MS-DOS formatted disks as you would any other directory.


To mount a CD-ROM:

$ mount -t iso9660 /dev/cdrom /mnt/cdrom

Again this is a similar method as above to mount the CD-ROM.

Different filesystems can also be mounted in a similar manner:

$ mount -t vfat /dev/hda1 /win

Any filesystems that are not mounted can be seen via the df command. So using that command you know what you got to work with.

Note: The -t option should be used so that the operating system knows the specific filesystem type that you would like to mount the device as. If you leave the -t option out of the command, mount it will attempt to determine the correct filesystem type it should mount the device with.

 


How to unmount a filesystem

When you are done using a particular filesystem, you should unmount. The command to unmount a filesystem is the umount command.

When unmounting a filesystem you simply type umount followed by the mount point. For example:

$ umount /mnt/floppy

$ umount /mnt/cdrom


Conclusion

Now that you know how to mount and unmount filesystems, even those from other operating systems, in Linux, using Linux should now be even more attractive and a much more powerful tool. For more information about the mount and umount commands you can view their man page (help files) by typing the following commands:

$ man mount
$ man umount

For more information about how to automatically mount certain filesystems when the operating system starts, you can view the following man page:

$ man fstab

As always, if you have any questions please feel free to ask them in the Linux Forum.

By DarkRaika

Users who read this also read:

  • Understanding Hard Disk Partitions Image
    Understanding Hard Disk Partitions

    When a hard drive is installed in a computer, it must be partitioned before you can format and use it. Partitioning a drive is when you divide the total storage of a drive into different pieces. These pieces are called partitions. Once a partition is created, it can then be formatted so that it can be used on a computer. When partitions are made, you specify the total amount of storage that you ...

  • Using man to get help in Linux and Unix Image
    Using man to get help in Linux and Unix

    Many users who try Linux for the first time can get confused easily as their is no readily apparent help system available to them. As Windows programs are typically graphical in nature, it is not too hard to find the help menu for that particular program. Linux, on the other hand, has thousands of very useful programs that are run from the command line and therefore it may not be easy to find the ...

  • Resizing and Adding Partitions using GParted Live Image
    Resizing and Adding Partitions using GParted Live

    This tutorial focuses on using GParted, or Gnome Partition Editor, a free and open source partition editor. To use GParted, you must first download the CD Image file (.iso file) of GParted Live for this program. Instructions on where to find and how to burn the GParted ISO file are covered in the Preparation step. In this tutorial we will be using Microsoft Windows XP for certain steps. If you use ...

  • How Hard Drives work Image
    How Hard Drives work

    Almost all desktop computers have a hard drive inside them, but do you really know what they are? Many people when they hear the word hard drive, think that it refers to the computer as a whole. In reality, though, the hard drive is just one of many different pieces that comprise a computer. The hard drive is one of the most important parts of your computer because it is used as a long-term ...

  • How to partition and format a hard disk in Windows Image
    How to partition and format a hard disk in Windows

    In order to use a hard drive, or a portion of a hard drive, in Windows you need to first partition it and then format it. This process will then assign a drive letter to the partition allowing you to access it in order to use it to store and retrieve data.

 

Comments:

blog comments powered by Disqus
search tutorials
Mandiant mWise Conference 2024

Login