Skip to main content

How to mount and unmount a hard drive in Linux?

I lease multiple Linux servers. One of them has multiple hard drives installed in it. After asking the data center to reload the OS on it, the staff did not mounted the second drive. Surprisingly it is extremely easy for anyone with a root access to mount a hard drive on a Linux-based system. Here I will show you the very basic ways to mount and unmount a hard drive. This particular server is running CentOS 5.

Determine available drives and partitions

To star, you should first find out what hard drives and partitions are available. A quick way to show available hard drives in your system is to run the command fdisk -l. The results will give you some helpful information about the connected drive(s), as well as information on the partitions, and their size.

Fdisk is a partition manipulating program. The letter "l" attribute stand for list, causing fdisk to list the system partitions. You can read more in the fdisk man pages.

[caption id="attachment_1059" align="aligncenter" width="655"]Hard disk list command in Linux. List of hard drives on the system.[/caption]

I should point out that your hard drive or drives will be identified on your system with the letters hd or sd. If you have multiple drives they will be identified by a letter, e.g. hda /hdb, or sda /sdb. The partitions on each drive will be identified numerically, e.g. hda1 /hda2, or sdb1 /sdb2. You can see this in the screenshot above.

How to mount a hard drive in Linux

First thing you should do is create a directory where the drive or partition will be mounted. In my case, I use the second hard drive for storing backups so I created a directory called backups. I set the permissions to 755, although others would recommend 777 - full read and write access for everyone. In my opinion that is a security risk, especially on an Internet accessible server.

You will have to either authenticate as the root user or use elevated privileges via sudo. If you have either authenticated as root or via sudo bash then you can omit the sudo text from the commands below.

The commands to create the directory and set its permissions are:
# Creating the directory and setting its permissions.
# mkdir /path/dir_name
# chmod 755 /path/dir_name

$sudo mkdir /backups
$sudo chmod 755 /backups

Now that we have the target directory created, it is time to mount the hard drive partition. In my case the second hard drive has only one partition. It encompasses the entire hard drive.

The command we are going to use is mount. Look through the mount man pages for detailed overview of the various functions that mount can perform.
# Mounting partition in the directory.
# mount /dev/partitionId /path/dir_name

$sudo mount /dev/sdb1 /backups

Your partition should be permanently mounted now.

How to unmount a hard drive in Linux

To unmount a hard drive or a partition in Linux, the command is the same as when you are mounting the same, except you have to add a u to the front of the command. It becomes umount.
# Un-mounting the drive.
# umount /dev/partitionId /path/dir_name

$sudo umount /dev/sdb1 /backups

Keep in mind that although when we refer to the procedure we use the word unmount, the actual command does not have n in the beginning. The umount man pages contain a list of the various attributes you can use, as well as some of the other functions the program offers.


  1. mount: you must specify the filesystem type

  2. No, specifying the file system type (FST) is no a “must”. Mount is capable of auto detecting the file system type if it is a standard/known FST to the kernel*. You will have to specify the FST if you are using an old not supported FST or some other special circumstances.

    Those who would like to know how to specify a file system type use the following command
    mount -t /dev/sdb1 /backups

    If you want mount to automatically try to guess the file system type follow the instructions from the articles, or append -t auto.
    mount -t auto /dev/sdb1 /backups

    * Known file system types are - adfs, affs, autofs, cifs, coda, coherent, cramfs, debugfs, devpts, efs, ext, ext2, ext3, ext4, hfs, hfsplus, hpfs, iso9660, jfs, minix, msdos, ncpfs, nfs, nfs4, ntfs, proc, qnx4, ramfs, reiserfs, romfs, squashfs, smbfs,sysv, tmpfs, ubifs, udf, ufs, umsdos, usbfs, vfat, xenix, xfs, xiafs. There might be others. As the kernel evolves support for some FSTs might be dropped.

  3. Thanks a lot for the overview, found it a helpful refresher.

    However, do you have to use chmod -R 755 to give the folder permissions in the first step?

  4. Hi Ab,

    Chmod does not need the -R recursive flag because the "backups", or whatever you choose to name your directory you are going to use to mount the partition, is empty.

  5. $sudo mount /dev/sda /oldhd
    mount: you must specify the filesystem type

    $sudo mount -t msdos /dev/sda /oldhd
    mount: wrong fs type, bad option, bad superblock on /dev/sda,
    missing codepage or helper program, or other error
    In some cases useful info is found in syslog - try
    dmesg | tail or so

    $sudo mount -t auto /dev/sda /oldhd
    mount: you must specify the filesystem type

    If specifying the filesystem type is not actually required, my copy of mount hasn't got the memo.

  6. Your copy of mount did get the "memo". Please have a look through the mount man pages!

    You, on the other hand, are doing it wrong.

    You need to identify the partition by its number. Which is also probably why you are unable to mount a known file system type (msdos) when using the full command.

    Assuming your sda hard drive has only one partition, then you will be mounting sda1. Your mount command will be:

    $sudo mount -t auto /dev/sda1 /oldhd


    $sudo mount -t msdos /dev/sda1 /oldhd


Post a Comment

Popular posts from this blog

Format MAC Address [JavaScript]

I am currently working on a project which will allow users to register their Wi-Fi enabled, non-web browser enabled, devices on the network. These are devices like printers, Apple TV, and Xbox*. One of the data points that have to be collected from the user is the device MAC address. The project customer wants that address to be properly formatted when they see it in the support ticket.

We have several options. We can format the address either on the back-end after the form has been submitted. Or we can format it on the front end via a separate text field for each character pair, but that is too many fields to handle. A better solution is to use a single field and format the user input at the time of input or upon submit. In those cases, the former is better because the data will already be formatted when the overall form input is being validation after the user clicks the “Submit” button.

We are going to format the user input as it is being provided, thus having proper data when vali…

How to setup Coda 2 to push to GitHub?

Setting up a new site in Coda 2 and cloning a GitHub remote repository is not that big of a deal. Where you will most likely run into problems is when you try to push your changes to the GitHub remote repository. Below I will show you how to update the Git config file in your local repository so you do not run into one of the following errors:
git push failed remote: Remote anonymous access to repository deniedgit push origin master Username: fatal: Could not read passwordThe GitHub repository address I am going to use is that of Source Code DNA: I will assume that you have already setup your Coda 2 site profile and cloned your repository, you have made some changes, and now you are ready to push those changes to your projects GitHub repo.

SNOOZ: Sound. Sleep.

I was on the Snooz Kickstarter page today, revisiting the project’s details and timeline progress. The device, which is a white-noise generating machine, recently became available for pre-order. Snooz is meant to be an alternative to having a TV or a stationary fan running at bed time. In my case, I bought it for my wife so we can get the TV out of the bedroom.

Whilst on the comments page I read the following comment, posted recently by Ken Tran:

I'm not a fan of the new fabric design. ...
I must disagree. If you take a look at the original design, which is all plastic and no style, I must say it is fugly. It is all utilitarian - not something I rally want to look at or see when I walk into the room. The final design, seen on the right, is something that beacons to be explored, looked at, utilized.

I am a big fan of Bang & Olufsen. They use fabric from Kvadrat in their line of products. Incorporating soft materials like fabric or leather in something which is meant to be place…