How to mount a partition in Linux

Unlike Windows and MS-DOS, in Linux, in addition to not having a letter assignment -a B C D E:- for disk drives and partitions, you need to tell the system when a removable disk drive will be used to access it and when it will be discontinued so that it can be removed and replaced. Once the disk drives are configured in the system, you will need to know some methods and shortcuts to quickly mount and unmount them.

Preparations for mounting

Before mounting the partition, we must create a folder where we are going to mount it. It is usually done in /half/ (/ Mnt in some distributions), so it is recommended that we create it there:

sudo mkdir / media / lalala

Where lalala is the name that the folder will have, we can assign it whatever we want.

If the filesystem of the partition that we are going to mount is NTFS (used by operating systems Windows NT, Windows 2000, Windows XP, Windows Media Center, Windows 2003 Server, Windows Vista and Windows 2007 Server), then it is recommended to install the controller ntfs-3g in order to have write support on that partition:

sudo aptitude install ntfs-3g

If instead the file system is UFS2 (used by most operating systems based on BSDas NetBSD, OpenBSD, FreeBSD and its derivatives), then before mounting the partition we will have to load the kernel module into memory ufs:

sudo modprobe ufs

To avoid having to load it every time the system starts, we can edit the file / etc / modules:

gksudo gedit / etc / modules

And add the following line before 'loop':

ufs

Partition mounting

Now we are going to mount the partition in the created folder. This means that the contents of the partition will appear in that folder. The command to mount disks and / or partitions is mount, and is used as follows:

$ sudo mount -t filesystem [-or Options] / dev /partition mount_folder

It should be noted that if an error occurs during mounting, the partition data will not be compromised, it will simply not be mounted.

Parameters

The meaning of the parameters used in the command mount are the following:

  • filesystem: is the file system of the partition; can be vfat (FAT16 y FAT32), ntfs (NTFS) or ufs (UFS y UFS2); there are other possible values, but they are not covered in this article. Yes it is ufs, then we must indicate the options in a mandatory way ro y ufstype (the latter in case of being UFS2).
  • options: are the mount options, it can take more than one value, in that case the values ​​are separated with commas (,). Some possible values ​​are defaults (default values), ro (Read Only, that is, Read Only) and ufstype (to specify the type of UFS filesystem, in case this is used); if no special options are specified, we can write defaults, or ignore this parameter entirely (also removing the -o from ahead). In this article, we will use this parameter only for mounting partitions UFS y UFS2, and for mounting at system startup (see heading Mounting at system startup).
  • partition: is the identifier of the partition that we are going to mount; can be hdXY in case of being a disc IDE o ATA: sdX, Y in case of being SATA; The X is the letter of the hard disk (a for the first, b for the second, etc.) and the Y is the partition number (1 for the first, 2 for the second, etc.). If we want to know the name of the partitions we have on the computer, just run the following command:
$sudo fdisk -l
  • mount_folder: is the folder where the partition will be mounted, that is, where the data (files and folders) of the partition will appear; in most cases it is within /half/, although it may be anywhere else (see heading Preparations for mounting).

Concrete examples

To mount a partition FAT16 o FAT32:

sudo mount -t vfat / dev /partition /half/mount_folder

To mount a partition NTFS:

sudo mount -t ntfs / dev /partition /half/mount_folder

To mount a partition UFS:

sudo mount -t ufs -o ro / dev /partition /half/mount_folder

To mount a partition UFS2:

sudo mount -t ufs -o ro, ufstype = ufs2 / dev /partition /half/mount_folder

To mount a partition where Ubuntu is:

sudo mount / dev /partition /half/mount_folder

Mounting at system startup

Once we have managed to mount the partition, it will remain mounted while the system is running. When we restart or turn off the computer, we will have to remount the partition. If we want it to be mounted every time we start the system, we will need to modify the file / etc / fstab:

$ sudo gedit / etc / fstab

Here it has been used gEdit, but any text editor can be used, such as Nano o Vim. It is convenient to use gksudo o kdesu instead of sudo to start an editor in graphical mode; the first is for the desktop GNOME and the second for KDE.

Once the file is open, we have to change the line that begins with the identifier of the partition that we have mounted (/ dev / hdXY o / dev / sdXY) by the following:

/ dev /partition /half/mount_folder filesystem Options 0 0

If that line does not exist, we add it to the end of the file.

The arguments are the same as when we use the command mount. Here, if in options we do not use any value, we will have to write defaults, and we would have something like this:

/ dev /partition /half/mount_folder filesystem defaults 0 0

If it is a partition FAT16 o FAT32 and it doesn't work for us defaults, we can try the following options:

auto, users, exec, umask = 000
defaults, rw, user, auto, umask = 0

With the latter, read, write and execute permissions are being given to all users. If we want to restrict these permissions only to a particular group of users (for example: users), the options should look like this:

defaults, rw, user, auto, umask = 007, gid =group 0 0

Where group should be replaced by the user group, for example, users.
Finally, if for any reason some characters (such as the letter ñ), we must add the following option along with the others used, to change the character map:

iocharset = utf8

For example, a line could look like this:

/ dev / hda0 / media / hda0 vfat defaults, rw, user, auto, iocharset = utf8, umask = 000 0 0

To mount all devices listed in the file / etc / fstab we have to execute the following command in a terminal:

sudo mount -a

With this we already have our partition mounted every time Ubuntu is started.

Create a launcher to partition

Once we have mounted the partition, we verify that sometimes it can be uncomfortable to always access the folder / media / hdXY (or to which we have specified), to solve this we can do two things:

  • Create a symbolic launcher in our folder home or in any other folder
  • Create an icon on the desktop that directs us to the mounting folder

Symbolic launcher in / home

The first option is to create a symbolic launcher (they are like the shortcuts of Windows), for example in our personal folder home. With this we will be able to access the partition from this folder and without duplicating the information.

We write the following line in the terminal:

$ ln -s / media /mount_folder / home /user/destination_folder

Where mount_folder is the folder where we mount the partition, user is the name of our user in the system and destination_folder is the symbolic launcher that we will create to act as a mounting folder.

Icon on desktop

If what we want is to create an icon on the desktop, we must do the following:

In GNOME

  1. We display the desktop context menu (right mouse button)
  2. Select the option Create link
  3. We choose the type Enlace
  4. We fill in the blank fields with the required data
  5. We accept for the link to be created

In KDE

  1. We display the desktop context menu (right mouse button)
  2. Select the option Create New -> Link to Device -> Hard Drive
  3. In the General tab, we write the name of the icon
  4. In the Device tab, we write the identifier of the partition (/ dev / hdXY)
  5. We accept for the link to be created

Partition disassembly

If for any reason you want to unmount the partition, you just have to write this in terminal:

sudo umount binder

Where binder is the location of the folder where the partition is mounted (for example: / mean / hdaX).

Source: Ubuntu Guide


20 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   electronicanarias said

    Thank you very much for your blog, it has been very useful to me.

  2.   Let's use Linux said

    You're welcome! Thanks for the encouragement!
    A hug! Paul.

  3.   Jofalko said

    Can you mount a partition in a folder on your home (for example, Documents) with a line in the fstab? I tried it and either it gives me an error when starting linux, or it doesn't mount anything. Is it impossible?

  4.   Let's use Linux said

    In principle it should be possible. Could you pass us the line of the fstab you are using?
    Cheers! Paul.

  5.   Jofalko said

    Hi, Pablo:
    The line I use for mounting in fstab is:
    / dev / sda3 / home / jose / Documents ntfs defaults 0 0
    Well, the system replaces the name of the folder «Documents» with the name of the volume label of the unit, which is mounted but empty. If instead of that I put it in another directory p. ex. / media / data, it works perfectly.
    Greetings.

  6.   Let's use Linux said

    Did you make sure that this line is after the one used to mount your HOME partition (in case you have one) ??? Try putting that line last, below the rest of the lines that mount the different devices / partitions on your system.
    Cheers! Paul.

  7.   Jofalko said

    Yes, it is last, after loading the home partition and swap.

  8.   Let's use Linux said

    So I have no idea. In theory I think it should work perfect. The only thing that strikes me is that my fstab lines all end in 0 1, and yours ends in 0 0. I'm not sure but maybe that has something to do with it.
    Cheers! Paul.

  9.   Jofalko said

    I have looked in the manuals and the last option has to do with a system check if there is a restart ... well, I have tried with other values ​​and it does not work. Anyway, thanks for the help.
    All the best

  10.   kickers25 said

    In the parameters section you do not put the names

  11.   Let's use Linux said

    Thank you! I think I already corrected it. 🙂

  12.   David Peru said

    I will be very grateful if you could answer my question directly.
    I have an HP laptop where Windows XP and Ubuntu 14.04 are installed. I am in the process of migration to Linux and this laptop is not for my exclusive use.
    My question is if I can somehow create a partition from linux that can be viewed later from windows. My idea is to use this partition as a common work area, where I can save the files worked and that can be seen by both operating systems.
    It took a lot of work to install the UBUNTU 14.04 because of the graphics card and I forgot to ask to create a common area. I appreciate in advance the help to this question.

    1.    let's use linux said

      Hello david!
      Of course it can. To create a "common" workspace as you call it, all you have to do is create a partition in the ntfs or fat32 format. The ext4 partitions are "invisible" to Windows (unless you use a special program).
      Cheers! Paul.

      1.    David Peru said

        Dear Pablo. Thank you very much for the quick answer.
        Please could you be a little clearer? How do I create that partition? ? with Gparted?
        It means that I am going to subdivide the area of ​​the linux disk or the area of ​​the windows disk, right?
        If it is to use gparted, please tell me, as a novice, how I should do it.
        I imagine that I will not have data losses (or programs) in both systems, right?
        I notice from the Gparted that I have an area "ext4" with "/" of 55.24 GiB with 7.30 GiB used. is this normal ??
        Thank you very much again.
        David

        1.    let's use linux said

          Hello david! Look, the simplest thing is that you do nothing. 🙂
          Not seriously. Desde Linux You are supposed to be able to access your Windows files without problems and from Windows, obviously, you should also be able to access them.
          Does the Windows partition appear when you start the system? I mean, can you see what in Windows you would call your C: \?
          If not, then all your trouble comes down to mounting that partition (on which Windows is installed). It is the easiest and fastest.
          For this, I recommend you read the following posts (although one is enough):
          https://blog.desdelinux.net/montar-una-particion-ntfs-o-fat32-al-arrancar-ubuntu/
          https://blog.desdelinux.net/como-montar-hdds-o-particiones-mediante-terminal/
          https://blog.desdelinux.net/con-fstab-como-montar-automaticamente-una-particion-ntfs/
          https://blog.desdelinux.net/auto-montar-particiones-con-fstab/
          https://blog.desdelinux.net/como-auto-montar-particiones-al-inicio-la-forma-facil/
          https://blog.desdelinux.net/como-montar-una-particion-en-linux/
          Cheers! Paul.

  13.   Mr. Axolote said

    Hello, congratulations on this site with such clear instructions. but this time I can't find the answer. I tell you:

    I am a Linux novice because more than 3 years ago I got rid of winsuck, but I am very far from being an expert, and the following problem is a good example. Hopefully you can help me:

    I have used Ubuntu and Lubuntu since I got to know Linux. Now I decided to go a little further and try Ubuntu 14.04, Elementary OS and PepperMint all on the same HP mini lap which has been a real treasure.

    The fact is that I did not have at hand where to back up my personal files located in a separate partition made in FAT32, and I decided to risk re-partitioning to install the 3 mentioned Distros without formatting the entire disk.

    I read as much as I thought necessary on the subject and I launched myself as a reckless adventurer… ..but something went wrong and I cannot access the sda3 partition where my files are because GParted says that it does not have a known file system and with sudo blkid doesn't even send me a reply.

    When partitioning I made 3 primaries and an extended one with 2 logics inside it. Use ext4 and obviously SWAP. But DO NOT change the file system from the one that was FAT32 so as not to erase or damage it.

    So far I have only installed Ubuntu 14.04 on: sda1 primary ext4 / boot

    I think then the question is: How can I know or assign a file system to sda3 to mount it and have access to my documents, MUSIC, photos, etc? Does Testdisk help me in this case? Should I reinstall Ubuntu? 14.04 to re-partition and change something in that process?

    I hope I have expressed myself clearly and can help me, as one of the reasons why Linux fascinates me is the possibility of trying, erring and learning with the help of such a large community of passionate Linuxeros.

    Thank you in advance.

  14.   Laurentius said

    Hey.
    What would be the difference between this method that uses the / dev / sdx line to set the partition to mount with the one that uses the UUID = XXXXXXXXX parameter?
    I see that my fstab uses the latter.
    Greetings.

    1.    yukiteru said

      With the UUID, the system uses a static unique identifier for each partition when mounting. This method is better than using / dev / sdX since the latter is dynamic and changes according to the kernel's detection of the device. Changes in the kernel or udev can break this scheme, while with the UUID this does not happen, and it is the reason why they use it.

  15.   fabian said

    hello, how are you
    after mounting the partition that I have in / dev / sda4 in / data
    How do I create a launcher at that motage point?
    appear in the explorer alongside the other drives?
    grace I use FEDORA 22

  16.   andres said

    hello and how would it be done with a mac hfs + partition from ubuntu to read and be able to access these files, you can't enter mac only from ubuntu is there any way to copy this disk for later reading and writing in ubuntu?