AutomaticallyMountPartitions – Community Help Wiki

Broadly speaking, there are two approaches:

Per-user mount (usually low/

    medium)

  • System-wide mounting (anywhere, often under /mnt) Per-user mounting

does not require root access, it only automates the desktop interface. System-wide mounts (/etc/fstab) can allow access from before logon and are therefore much more suitable for access over a network or by system services.

Commands must be entered in a terminal (Type terminal in the program launcher of recent Unity-based Ubuntu versions, or select Applications -> Accessories -> Terminal from the previous versions menus).

udisks

This is the modern replacement for gnome-mount. It is not specific to the gnome.

When you mount a disk normally with File Explorer (nautilus, etc.), you mount disks interacting with udisks behind the scenes

.

You can do the same on the command line with the udisks tool. For example:

/usr/bin/udisks -mount /dev/sdb1

The bit after -mount is the device name of the partition you want to mount. (/dev/something). The command will mount /dev/sdb1 to /media/<uuid> where <uuid> is the identifier of the particular partition. Read below to find the uuid of your partition.

Find the device name of

your partition

  • Open your partition in nautilus (this ensures that it is mounted)
  • type mount in a terminal. You should see a line with your disk name as:

/dev/sdb1 in /media/My-Happy-Disk type vfat….

Finding the UUID

of the partition

A device name like /dev/sdb1 is based on where the physical drive is connected and the order in which the drives were made available to the computer, so if your computer changes, the same command could mount a different partition. This may happen only from a software update.

The solution is to use a UUID. A UUID is a globally unique name for the partition. A UUID will remain the same if you place an internal disk in an external USB caddy or rename the partition.

  • Type ls -al /dev/disk/by-uuid/ you will see an entry that matches the name you saw before

: lrwxrwxrwx 1 root root 10 2012-02-15 10:23 1313-F422 ->.. /.. /sdb1 The

UUID in the example is 1313-F422

You can now determine the command you need to mount the device using UUID. For our example it would be

/usr/bin/udisks -mount /dev/disk/by-uuid/1313-F422

Of course, you need to replace 1313-F422 with the UUID of the device you want to

mount.

Again, this will mount your partition to /media/<uuid> which is not consistent with the way nautilus mounts partitions. Nautilus-mounted partitions can be found in /media/<user>/<uuid> with <user> the current logged in user.

To keep the folder structure consistent, you can use an alternate command that takes care

of the correct mount point automatically: udisksctl mount -block-device /dev/disk/by-uuid/<uuid>

Of course, <uuid> must fit the correct UUID of your partition, for example, 1313-F422 in this example.

Add

to

startup

  • From the Ubuntu script (click on the logo at the top left) search for startup apps or press Alt + F2 and type gnome-session-properties

  • Press the Add button.

  • Choose a name, paste your command and press the

  • Add button

Three methods will be discussed:

  1. The first method is to manually edit the Ubuntu file system table. This sounds more complex than it actually is.
  2. The second method,

  3. for versions 6.06 and later, is described in MountingWindowsPartitions.

  4. The third, simple method is to install the pysdm package (in Gutsy) and then use the System Management Storage Device Manager without any manual editing of the fstab file, and ignoring most of the instructions they follow. (NOTE: psydm removed from repositories in 12.10 and presumably beyond – see http://ubuntuforums.org/showthread.php?p=12338212. The use of arya automount or mount manager is not recommended)

Manual configuration help

To mount hard disk partitions, you should have a basic understanding of the information below.

Once installed, you can navigate to System > Network and File Systems

> A basic understanding is still required…

Viewing physical system information

To read the layout of the physical disks in the system, the ‘fdisk’ command is used. Before you panic, keep in mind that fdisk will be used only with non-destructive options; specifically, it will be used with ‘L’ (lowercase ‘L’, not ‘1’), which lists the partition table of the specified disk.

sudo fdisk -l

As an example, here is what the output would be if one had a laptop with an internal drive and a USB drive attached

: WARNING: GPT (GUID partition table) detected in ‘/dev/sda’! The fdisk utility does not support GPT. Use GNU Parted. Disk /dev/sda: 180.0 GB, 180045766656 bytes 255 heads, 63 sectors/track, 21889 cylinders, total 351651888 sectors Drives = 1 * 512 sectors = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Booting the device End block id System /dev/sda1 1 351651887 175825943+ ee GPT Disk /dev/sdb: 8019 MB, 8019509248 bytes 255 heads, 63 sectors/track, 974 cylinders, total 15663104 sectors Drives = 1 * 512 sectors = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xc3072e18 Boot of the device End block id System /dev/sdb1 * 2192 15663103 7830456 b W95 FAT32

If your system has multiple hard drives, Multiple lists will be displayed.

Decide which partitions to mount

Most systems have only /dev/hda, which is the

hard disk drive, and /dev/hdc, which is the CD-ROM or optical drive. If more were listed when the above command was executed, they can be identified as follows: had is the first drive on the first IDE channel (0:0), hdb is the second drive (0:1), hdc is the third drive (1:0), and hdd is the fourth (1:1). SCSI and S-ATA disks have names such as sda and sdb.

Look through the list generated above to identify the partition(s) to be mounted. The following table lists some common types of ‘System’, which can help this process.

A list of the form ‘/dev/hda1: /media/windows/ (vfat)’, where ‘/dev/hda1’ is the device, ‘/

media/windows’ is the arbitrary location where the partition will appear when mounted, and ‘vfat’ is the Linux type, it must be created on paper, containing all the partitions to be added

.

System Preparation

Look through the list that was just created. For each location (‘/media/windows’), run the following command.

ls /media/windows

If a response such as ls: /media/windows: No such directory file is returned, the location is open. If a list of files or nothing is returned, the location already exists and the scheduled location will need to be modified.

Once each location has been confirmed to be free, run the following command for each entry, replacing ‘/media/windows’ with the chosen location.

sudo mkdir /media/windows

Editing Ubuntu File System Table

It is possible to break Ubuntu if some of the above lines in the file opened during this step are modified, So be sure to read this section carefully.

The Ubuntu file system table is located in ‘/etc/fstab’. Open this file for editing by running the following

command for Ubuntu gksu gedit /etc/fstab or

this command for Kubuntu

kdesu kate /etc/fstab

or command line

nano -w /etc/fstab

The open file contains lines of the form <device> <location> <Linux type> <options> <dump> <pass>. Each item on this line is separated by white space (spaces and tabs):

# /etc/fstab: Static file system information. # # Use ‘blkid’ to print the universally unique identifier for a device #; this can be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <system > < files point> <type> <options> <dump> <pass> # / was on /dev/sda2 during installation UUID=a2db89ed-d599-4138-8838-0b950b6c3fbb / ext4 errors=remount-ro 0 1 # /boot/efi was on /dev/sda1 during installation UUID=AEF0-9F26 /boot/efi vfat defaults 0 1 # swap was on /dev/sda3 during installation UUID=df17fdb9-57a4-4302-856e-3cd656848355 none swap sw 0 0

<file system>

The first field, (fs_spec), describes the special block device or remote file system to be mounted.

For ordinary mounts, it will contain (a link to) a special block device node (created by mknod(8)) for the device to be mounted, such as /dev/cdrom or /dev/sdb7. For NFS mounts one will have <host>:<dir>, for example, knuth.aeb.nl:/. For procfs, use proc.

Instead of giving the device explicitly, you can specify the file system (ext2 or xfs) to be mounted by its UUID or volume label (cf. e2label(8) or xfs_admin(8)) by typing LABEL=<label> or UUID=<uuid>, for example, LABEL=Boot or UUID=3e6be9de-8139-11d1-9106-a43f08d823a6. This will make the system more robust: adding or removing a SCSI disk changes the name of the disk device, but not the label of the file system volume. The UUID of a drive can be determined by typing ls -l /dev/disk/by-uuid/ in a shell.

<

mount point>

The second field, (fs_file), describes the mount point for the file system. For swap partitions, this field must be specified as none. If the mount point name contains spaces, they can be escaped as 40.

<type>

The third field, (fs_vfstype), describes the file system type. Linux supports many types of file systems, such as adfs, affs, autofs, coda, coherent, cramfs, devpts, efs, ext2, ext3, hfs, hpfs, iso9660, jfs, minix, msdos, ncpfs, nfs, ntfs, proc, qnx4, reiserfs, romfs, smbfs, sysv, tmpfs, udf, ufs, umsdos, vfat, xenix, xfs, and possibly others. For details, see mount(8). For file systems currently supported by the running kernel, see /proc/filesystems. An input swap denotes a file or partition to be used for the exchange, cf. swapon(8). An ignored entry causes the line to be omitted. This is useful for displaying disk partitions that are not currently used.

<options>

The fourth field, (fs_mntops), describes the mount options associated with the file system

.

It is formatted as a comma-separated list of options. Contains at least the mount type plus any additional options appropriate for the file system type. For documentation on the options available for non-NFS file systems, see mount(8). For documentation on all nfs-specific options, take a look at nfs(5). Common to all types of file systems are the noauto (do not mount when “mount -a” is given, for example, at boot time), user (allow a user to mount) and owner (allow the device owner to mount) options, and comment (for example, for use by programs that maintain fstab). The owner and comment options are Linux-specific. For details, see mount(8).

<dump>

The fifth field, (fs_freq), is used for these file systems by using the dump(8) command to determine which file systems should be dumped. If the fifth field is not present, a value of zero is returned and dump will assume that the file system does not need to be dumped.

<pass>

The sixth field, (fs_passno), is used by the fsck(8) program to determine the order in which file system checks are performed at the time of reboot. The root file system must be specified with a fs_passno of 1, and other file systems must have a fs_passno of 2. File systems within a drive will be checked sequentially, but file systems on different drives will be checked at the same time to use the parallelism available in the hardware. If the sixth field is missing or zero, a value of zero is returned and fsck will assume that the file system does not need to be checked.

<options> example

For more information about options

, type ‘man mount’.

*If you want write access to your file system, you must set the file system type to ‘ntfs-3g’ instead of ‘ntfs’. You may need to install the ‘ntfs-3g’ package for this to work, so make sure it’s installed before using ntfs-3g.

**uid=1000 restricts access to the user created during Ubuntu installation. 1001 is the user created after that, and so on. gid=# can be used with or instead of uid to grant access to a group. However, enumerating groups and users is beyond the scope of this article.

Example <type>

Note for international users: If your file system contains funny symbols, you may need to add an option for utf-8 support

.

fstab example

So, to grant all users access to ‘/dev/hda1’, which will be located in ‘/media/windows’,

and is of type ‘vfat’, the added line would be. /dev/hda1 /media/windows vfat user,

fmask=0111,dmask=0000 0 0 This

entry is case-sensitive. In general, lowercase letters are used to avoid confusion.

‘dump’ and ‘pass’ are only useful for native file systems. They can be set to ‘0’ for all additional partitions.

For each item in the list of partitions to mount, add a line from the previous form to the end of

the fstab file.

Mounting Fakeraid

It is assumed that you have formatted your raid set using the dmraid command with instructions found in FakeRaidHowto.

You need to know the name of your raid

set sudo dmraid -ayRAID set “sil_aiaedhaeafaa” already active RAID set “sil_aiaedhaeafaa1” already active Edit fstab

According to the instructions above

: nano -w /etc/fstab

An example line to add

/dev/mapper/sil_aiaedhaeafaa1 /media/raid reiserfs user,nosuid,exec,nodev 0 0

Make sure to create the /

media/raid directory mkdir /media/raid

Reboot

Mounting and checking partitions

In the terminal, type the following command:

sudo mount -a To verify that partitions were mounted

successfully, open the Gnome file explorer and point you to the locations where the partitions were mounted. Click on the ‘File System’ button to access ‘/’, and navigate from there. If the partition being scanned contains files, the modifications were successful and the partitions will be mounted automatically each time the system is rebooted. If no file is found, see XChatHowto and join #ubuntu in irc.freenode.net.

Using pysdm in Precise

Pysdm is a program to automatically configure partitions whenever Ubuntu is started

.

Installation

sudo apt-get install

pysdm

Usage

Select each partition you want to change from the list. Note the type. It is often ext3 (Linus) or NTFS (Windows). Use the wizard and press OK. By default, the partition is mounted at boot time. You can also mount the partition now. Press Apply. Fact.

Add

a bookmark

Bookmarks can be added to help speed up access to commonly used files and locations, such as mounted partitions

.

While browsing the file system using the Gnome file browser, click ‘Bookmarks’, then ‘Add Bookmark’. A new entry will be placed in the left bar, and the location will appear in the ‘Places’ menu.

Alternatively, bookmarks can be added when opening or saving a file by clicking

the ‘Add’ button.

To delete a bookmark, click on ‘Edit Bookmarks’ or the ‘Delete’ button, either of which is the counterpart of the two addition methods mentioned above.

More technical tips

Symlinking for added convenience

If navigating to the mount point of a partition seems inconvenient, even with the links to the left of the Gnome file browser, a link can be placed on the desktop, or anywhere else, for that matter.

Try the following command:

ln -s /media/windows ~/Desktop/

A link to the ‘/media/windows’ directory will be placed on the desktop. Files can be dragged into it, it can be opened, renamed and moved, and if it turns out to be annoying, it can be deleted like any other file without risking damaging its contents.

This process is called symbolic linking because the link created is symbolic. It simply points to the referenced location.

Unmount a partition to prevent unwanted access

While it is

easy and effective to set permissions on partitions, there may be times when setting permissions is not enough. Sometimes people who can’t be trusted with important information, such as a term document, may need access to a system, and modifying the file system table can be impractical. When things like this happen, it’s easy to archive data to preserve permissions and paste it into a partition or mounted device, then unmount the device, preventing “accidental” access. (The potentially malicious user would jokingly need to know the file system table, and while that information isn’t well hidden, it’s hard to access without drawing attention.)

Try the following command to unmount a partition: sudo umount

/media/windows

The partition mounted on ‘/media/windows’ will be unmounted, and attempts to access it will only show an empty directory. To recover it later, restart or simply run the following command.

sudo mount /media/windows

Technical background information How

Linux

manages partitions

Linux uses a virtual file system (VFS) to maintain a single file tree, all extended from ‘/’. When a partition is mounted, it is added to the tree at its mount point.

When a FAT32 partition is mounted on ‘/media/windows’, all access to ‘/media/windows’ and everything below it is handled transparently by the Linux kernel using the ‘vfat’ module. Apps don’t need to know they’re dealing with something else. However, mounting a partition in one location within another mounted partition is unpredictable, unstable, and generally a bad idea.

Each partiton maintains its own free space and internal file system, so they can be mounted on other systems and behave properly. (If you have two operating systems or a removable hard drive, feel free to try this: it’s hard to break something, and sharing /home (as long as no usernames overlap) and swapping between two Linux installations is very convenient)

To see what’s happening behind the scenes, try the ‘df’ and ‘mount’ commands.

CategoryBootAndPartition CategoryCommandLine

Contact US