How to mount a partition automatically in Ubuntu Linux

Although Ubuntu has made it very easy to mount drives in recent versions, it often is simpler if a drive can be mounted when the computer boots. I’ve given below the steps to set a drive or partition to load on startup. This applies to Ubuntu and Linux Mint (and probably most Gnome based Linux distros).

Firstly, you need to establish the system location of your partition. You can either do this via the Terminal or, if you prefer a nice graphical interface, you can install GParted.

Ubuntu Hard Disk Naming

To explain a little further, the standard naming in Ubuntu for hard drives is /dev/sd# or /dev/hd# (sd# is for SATA and removable drives and hd# for IDE drives). The # will change depending on your system. For example, I have three hard drives on my system and they are named as follows:

/dev/sda
/dev/sdb
/dev/sdc

These naming conventions apply to the whole, physical drive. Partitions within these drives will have their own names. My main hard drive (sda) has two partitions and these are called:

/dev/sda1
/dev/sda2

My second hard drive (sdb) has one single partition which utilizes the whole drive and it is called:

/dev/sdb1

How to check the location of your hard disk

If you’re using the Terminal, open it and type:

sudo fdisk -l

Fdisk will output all the disks and partitions on your system. I’m presuming that you know the size of the partition and the file system (eg ext3 or NTFS) and therefore you’ll be able to recognize it from the list (I have a few drives/partitions and it can get a little confusing!) Take note of the path to the drive you want to mount (we’ll say for this example that it is /dev/sdb1). Also take note of the file system being used, as you will need it later.

Create a mount point

Everything in Linux is a file. Even a hard disk! This is a little strange to Windows users but it’s the way it is in Linux. To automatically mount your disk, you have to assign it a directory. The usual place to mount drives (and this includes CD-ROM and USB drives) is in the /media folder located in the root directory. In the terminal, to change to the media directory, type:

cd /media

Decide what you want to call your drive and create a directory in that name. I intend to use mine for Virtual Machine software so I’m going to call it vm. Type the following (changing vm to your drive name):

sudo mkdir vm

Note that Linux is case-sensitive so vm is different to VM and different again to Vm.

Set the drive to mount on boot

For the drive to mount automatically when you start Ubuntu, you need to add it to the fstab file. Firstly, backup your existing fstab file with the following command:

sudo cp /etc/fstab /etc/fstab_backup

Open the fstab using the following command:

sudo gedit /etc/fstab

You need to add a line to the bottom of this file and this depends on the type of file system you are mounting. I have given examples below. In each case, you will need to change the /dev/sdb1 part to the location of your partition (as figured out above). Change the /media/vm part to whatever you called your directory. Save and close the file when you’re done.

For an ext3 Linux partition, use the following: (This works for ext4 too. Just change the file system to ext4):

/dev/sdb1 /media/vm ext3 defaults,errors=remount-ro,users,user_xattr,user 0 0

For an NTFS drive, try this:

/dev/sdb1 /media/vm ntfs-3g defaults,locale=en_US.UTF-8 0 0

For a FAT32 system, try this:

/dev/sdb1 /media/vm vfat umask=000 0 0

Take ownership of the partition

Finally, if this is a Linux partition, you may want to take ownership of it. If you’re just using this drive to store files etc. it quickly becomes a pain when you have to open it as root every time you want to copy over a file. To do this, you need to change the permissions on the folder. The basic code to do this is as follows:

sudo chown -R YourUserName:YourUserGroup /media/YourFolderName

For example, if my user name is mesanna and my drive is called vm, I would type:

sudo chown -R mesanna:mesanna /media/vm

And that should be that! You can reboot your computer if you like to check that it automatically loads up your new drive.


26 Comments

  1. Michal
    Posted 17 March, 2009 at 7:36 pm | Permalink

    thanks, that was very is to follow and it really works ;)

  2. Ryan
    Posted 10 June, 2009 at 11:45 am | Permalink

    Yes…this tutorial was very VERY informative. Ive been to a few other websites and they don’t quite fit the bill. You make it so easy…even a caveman can do it. xD Thanks again.

  3. Mjf
    Posted 16 July, 2009 at 7:27 am | Permalink

    I just have to thank you for the guide, I have used it several times and it is the most well written easily understandable guide available. Thank you.

  4. Posted 16 July, 2009 at 8:11 am | Permalink

    Thanks! Happy to help :)

  5. Vim Toutenhoofd
    Posted 22 July, 2009 at 12:49 am | Permalink

    I probably spent an hour or two searching before I stumbled on your instructions. Using them I succeeded in mounting a partition I had created on a virtual disk drive (created with VMware Workstation). A year or two ago I had installed Ubuntu on that virtual drive. Thank you!

  6. occeo
    Posted 18 October, 2009 at 12:28 am | Permalink

    If only every Linux guru like you could write simple and clear instructions like yours for Windows users…Microsoft would go bust.

  7. Posted 18 October, 2009 at 12:56 am | Permalink

    I like your thinking! And thanks for the compliment. :)

  8. karthik
    Posted 18 October, 2009 at 4:00 am | Permalink

    thanks for the instructions……….

    like ur way of making things look simpler..

  9. Joep
    Posted 22 November, 2009 at 9:24 pm | Permalink

    Great instructions. I only have a question about the last bit. How would I know what file system I have NTFS/EXT3/FAT32.
    Using EXT3 it doesn ‘stick’ after reboot
    Thanks,
    Joep

  10. Posted 24 November, 2009 at 8:17 pm | Permalink

    @Joep If you open a terminal and type:

    df -T

    Press enter and this should display the file system used on all partitions on your system. Hope this helps! :)

  11. vivek
    Posted 5 December, 2009 at 5:48 pm | Permalink

    Perfect!! worked without a hitch… thanks :)

  12. Joep
    Posted 10 December, 2009 at 7:04 pm | Permalink

    Hi,

    A while ago, but it turned out it sticks using FAT32. So that must be it.

    Works now!!
    Thanks a mill,
    Joep

  13. Posted 10 December, 2009 at 9:11 pm | Permalink

    Glad you got it sorted Joep! :)

  14. James
    Posted 22 December, 2009 at 1:21 am | Permalink

    Thanks so much for this how to, it’s as straightforward and easy as it possibly can be.
    I used to have to manually mount my share partition before I could play music from it in Banshee, now I don’t have to. :D

  15. JackieNP
    Posted 24 December, 2009 at 1:38 pm | Permalink

    Thank you. That is easy to understand.

  16. Janis
    Posted 26 December, 2009 at 4:08 pm | Permalink

    thank you mesanna!
    that was easy and quick and – it worked perfectly!
    you just made me very happy :)

  17. Posted 31 December, 2009 at 5:16 am | Permalink

    Hey, nice straightforward guide. I’ll be following it when I get the impetus to do it. Sexy blog theme, BTW. Very classy minimalism.

  18. Posted 2 January, 2010 at 10:09 pm | Permalink

    Woo, thanks :D

  19. M. Faraz
    Posted 5 January, 2010 at 10:18 am | Permalink

    Amazing article and just what I was looking for.

    Just one thing though, you dont need to restart/reboot the PC to test the fstab…just type (sudo) mount -a, and it will mount the partitions you have just added.

  20. Posted 6 January, 2010 at 9:34 pm | Permalink

    @M Faraz Thanks for your comment! I know you can mount drives with the sudo mount command, but I suggested rebooting so that you can check they mount automatically, that was all :)

  21. Posted 14 January, 2010 at 5:09 pm | Permalink

    I have been using ubuntu for one year now, and this is one the best tutorials I have come across. Much more elegant than most ubuntuforums posts. The partition mounts as it should, and I learned a bit about Linux file systems at the same time. Please consider writing more tutorials such as; partitioning a usb thumbdrive, grub/grub2 customization, etc.

  22. Posted 15 January, 2010 at 9:09 pm | Permalink

    Thank you!

  23. Biohazard Grrl
    Posted 8 February, 2010 at 2:46 am | Permalink

    Brilliant!
    Thanks so much, works perfect on Linux Mint 8.

  24. Merijn
    Posted 9 February, 2010 at 4:21 pm | Permalink

    Thanks! It worked perfectly, and I have no experience with linux whatsoever :)

  25. media
    Posted 19 April, 2010 at 3:09 am | Permalink

    this realy solved my problem in like 2min =) i can now share my disk nr2 to my ps3 over mediatomb. you realy made it easy with this guide, and thank your for that =)

  26. Muhammad
    Posted 23 May, 2010 at 1:46 pm | Permalink

    That was great ….. Thanks A lot

One Trackback

  1. [...] Mesanna’s Weblog Confessions of a Linux Newbie Contact Me « How to mount a partition automatically in Ubuntu Linux [...]

Post a Comment

Required fields are marked *

*
*