Mount a drive in Linux

Mount a drive in Linux

I had a person ask me how to mount and unmount a drive in Ubuntu. I was unable to find a clear tutorial on how to do this, so I wrote my own.

First, understand why you would need to mount or unmount a drive. Ubuntu and most user friendly operating systems automatically mount and unmount a drive when you are in a gui. When you are operating headless or doing advanced functions you will need to know mounting.

I put a 1 GB SD card in my macbook pro for this example.

First thing is you need to find the address if the item. To do this you need to use the fdisk command. It has the same name as the program you may be familiar with in dos / windows.

Type in sudo fdisk -l

This will run fdisk as administrator. The “-l” will list all partitions.

wpid-wpid-wpid-vmwarefusion1-2011-01-27-15-32-2011-01-27-15-32-2011-01-27-15-32.png

In this example there are 2 hard drives with a total of 4 partitions.

/dev/sda1
/dev/sda2
/dev/sda5

all belong to my main hard drive. The reason that it shows 3 partitions when you can only see one is that linux has a hidden system file partition and a hidden swap file. Don’t worry about this drive.

The one that we want is

/dev/sdc1

This is the 1 GB SD card. You can tell because it has 995,000 blocks and is FAT 16.

So far easy enough. Here is where people get mixed up.

When you manually mount a drive you need to give it a mount point. Think if it as a bridge between the 2 devices.
I am going to make my own mount point called “spuderMountPoint”. This mount point can be where ever you want, but common practice is to put it in the /mnt or the /media directory under root. I am goes to put my mount point in the mnt folder for this example.

Make a mount point like this.

wpid-wpid-wpid-vmwarefusion-2011-01-27-15-32-2011-01-27-15-32-2011-01-27-15-32.png

Great now I have my mount point. It is time to mount the device.
-Type in “sudo mount”
-Then the address of the device. In my case it is /dev/sdc1
-Then type where you want to mount it to. In my case it is /mnt/spuderMountPoint/

wpid-wpid-wpid-1____vmwarefusion-2011-01-27-15-32-2011-01-27-15-32-2011-01-27-15-32.png

It is important to note that the sdc1 is mounting partition 1 on the sd device identified by ‘c’. Don’t get this confused with windows c: drive. This example just happened to have 3 drives so it took the third letter in the alphabet.

If you wanted to mount the entire drive and not just a particular partition (this is actually recommended in most cases), just leave off the number

To mount the entire drive sda you would type

sudo mount /dev/sda /somemountpoint

To mount the third partition on a drive identified as sdf you would type

sudo mount /dev/sdf3 /somemountpoint

Mount a drive as read only

You may be doing some data recovery or working on a raid where you really don’t want to mount the drive and risk having any data written to it. In that case you will want to mount the drive as read only. This is extremely important if you are doing any kind of data forensics work or happen to get a job at the CIA and need to submit evidence that a drive hasn’t been tampered with. (Far fetched? perhaps…)

Simply add a -r to the parameters like this

sudo mount -r /dev/sda /somemountpoint

Unmount a drive

When you want to unmount a drive, simply type

sudo umount (not unmount) then the device address

wpid-wpid-wpid-2____vmwarefusion-2011-01-27-15-32-2011-01-27-15-32-2011-01-27-15-32.png

Advertisements

About spuder
spuder is a "super computer" support engineer by day, and tinkerer / hobbyist by night.

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

%d bloggers like this: