AutomaticallyMountPartitions

Differences between revisions 1 and 2
Revision 1 as of 2006-01-24 05:54:02
Size: 12779
Editor: ppp-70-251-243-233
Comment: Changed title as requested
Revision 2 as of 2006-01-24 05:54:43
Size: 12778
Editor: ppp-70-251-243-233
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Mount Paritions Automatically = = Mount Partions Automatically =

Mount Partions Automatically

Under Ubuntu, partitions must be 'mounted' before they can be accessed. Mounting is simply the process of telling Ubuntu a certain partition exists, what it is, and where in the filesystem it should go.

With the release of Breezy Badger (Ubuntu 5.10), this step should be almost automatic. Until then, however, the instructions provided on this page may be used to mount any needed existing data.

Two methods will be discussed:

  • The first involves a script which will configure everything automatically. It should work well for most users.
  • The second involves manually editing Ubuntu's filesystem table. This sounds more complex than it really is. This method may be preferred by power users and system administrators who need more control over their setup.

Regardless of the method used, a terminal (Applications -> System Tools -> Terminal) will be required.

Mounting partitions with the script

Script assumptions

  • /media/ is an acceptable location for the partitions to be mounted
  • there are no entries in your /etc/fstab for windows drives already
  • the windows drives are currently not mounted.

NOTE:- I've added the last two script assumptions after dealing with a number of problems in IRC with regards to running this script successfully. The problems were invariably caused by entries being in the /etc/fstab file that were already referring to a windows partition/s and often the drive/s were mounted already (usually without the correct permissions for them to be accessible by the user). If you find you are experiencing problems with the script then, backup your current copy of fstab (this step should always be done when editing system files), remove the entries for window drives in your fstab file, then umount the windows drives, then run the script again.

Acquiring the script

The script must be downloaded before it can be used. Type the following lines.

cd
wget http://www.ubuntulinux.nl/files/diskmounter

The file diskmounter will now be in the current user's home directory.

Using the script

The script is non-interactive, and usage is simple. Type the following line.

sudo bash diskmounter

This will make the script executable, then execute it with administrative rights.

The script will generate some output, regardless of whether it succeeds or not. Read the output as it will indicate errors and things you should read.

Cleaning up

The script is no longer needed, so type the following line to get rid of it.

rm diskmounter

All partitions on the system should now be accessible.

To verify access, open Gnome's file browser and direct it to /media/, which can be found by clicking 'File System' under 'Places', and then double-clicking 'media'. Double-click any partition to be examined. If it contains files, the modifications were successful. If no files are found, read the next section.

If the script worked for you, don't stop reading yet! Some tips exist at the end of this article in the Hints, Tips, and Technical Information section to help make your Ubuntu experience even more enjoyable.

Mounting partitions manually

Viewing the system's physical information

To read the layout of the physical disks in the system, the 'fdisk' command is used. Before panicking, realize that fdisk will be used with only non-destructive options. Specifically, it will be used with 'l' (lower-case 'L', not '1'), which lists the partition table of the specified disk.

for i in `ls /dev/hd* | grep -e "hd\w$"`; do sudo fdisk -l $i; done

The slightly scary command above will look for all files that match '/dev/hd?', each representing one hard disk drive, with fdisk ignoring empty devices, like CD-ROM drives, excluding those with numbers at the end. It will then print their partition tables. The output from this command will look something like what follows.

Disk /dev/hda: 40.0 GB, 40013261856 bytes
255 heads, 63 sectors/track, 4439 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1 *         1             638      5124703  b   W95 FAT32
/dev/hda2           639           4525     31222327 83  Linux
/dev/hda3           4526          4635     497980   82  Linux swap

If the system has multiple hard disk drives, multiple lists will be displayed.

Deciding which partitions to mount

Most systems only have /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 command above was run, they can be identified as follows: hda 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).

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

System name

English name

Linux type

W95 FAT32

Microsoft FAT32

vfat

W95 FAT32 (LBA)

Microsoft FAT32

vfat

W95 FAT16 (LBA)

Microsoft FAT16

vfat

W95 Ext'd (LBA)

Microsoft extended partition

Not used

NTFS volume set

Microsoft NTFS

ntfs

Apple_HFS

Apple HFS

hfsplus

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, should be created on paper, containing all partitions to be added.

Preparing the system

Look through the list which was just created. For every location ('/media/windows'), run the following command.

ls /media/windows

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

Once every location has been confirmed as free, run the following command for each entry, replacing '/media/windows' with the chosen location.

sudo mkdir /media/windows

Editing Ubuntu's filesystem table

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

Run the following command to open Ubuntu's filesystem table in a text editor.

sudo gedit /etc/fstab

The file opened contains lines of the form <device> <location> <Linux type> <options> <dump> <pass>. Every element in this line is separated by whitespace (spaces and tabs).

'options' is a string of options which should be applied to the partition when it is loaded. The following table should help in the decision of what options to use.

Description

FAT(16|32) partition

NTFS partition*

Apple Partition

Accessible by everyone

user,auto,fmask=0111,dmask=0000

ro,auto,user,fmask=0111,dmask=0000

user,auto,file_umask=0111,dir_umask=0000

Accessible by a subset of users**

user,auto,fmask=0177,dmask=0077,uid=1000

ro,user,auto,fmask=0177,dmask=0077,uid=1000

user,auto,file_umask=0177,dir_umask=0077,uid=1000

*At this time, NTFS may only be mounted read-only by the kernel. This means information may be read, but no information may be written.

**uid=1000 restricts access to the user created while installing Ubuntu. 1001 is the user created after that, and so forth. gid=# may be used with or in place of uid to grant access to a group. However, group and user enumeration is beyond the scope of this article. To learn more about options, type 'man mount'.

So, to grant all users access to '/dev/hda1', which will be located at '/media/windows', and is of type 'vfat', the line added would be.

/dev/hda1   /media/windows   vfat   user,fmask=0111,dmask=0000   0   0

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

'dump' and 'pass' are only of use to native filesystems. They can be set to '0' for all additional partitions.

For every item in the list of partitions to be mounted, add one line of the form above to the end of the fstab file open in gEdit.

Ensure there's a blank line at the end of gEdit (move to the end of the file and hit Return).

Save the file and close gEdit.

The worst is now over.

Mounting and checking the partitions

In the terminal, type the following command.

sudo mount -a

To verify that the partitions were mounted properly, open Gnome's file browser and direct it to the locations at which the partitions were mounted. Click the 'File System' button to access '/', and navigate from there. If the partition being examined contains files, the modifications were successful, and the partitions will be automatically mounted every time the system is restarted.

If no files are found, please see ["XChatHowto"] and join #ubuntu on irc.freenode.net.

Hints, Tips, and Technical Information

Adding a bookmark

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

While browsing the filesystem using Gnome's file browser, click 'Bookmarks', then 'Add Bookmark'. A new entry will be placed in the bar on the left, and the location will appear under the 'Places menu'.

Alternatively, bookmarks may be added while opening or saving a file by clicking the 'Add' button.

To remove a bookmark, click either 'Edit Bookmarks', or the 'Remove' button, either of which is the counterpart of the two addition methods stated above.

More technical tips

Symlinking for greater convenience

If navigating to a partition's mount point seems inconvenient, even with the links on the left of Gnome's 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 directory '/media/windows' will be placed on the desktop. Files may be dragged into it, it may be opened, it can be renamed and moved, and if it proves to be annoying, it can be deleted like any other file without risking damage to its contents.

This process is called symlinking because the link created is symbolic. It merely points to the location being referenced.

Unmounting a partition to prevent unwanted access

While it's easy and effective to set permissions on partitions, there may be times when setting permissions won't be enough. Sometimes, people who can't be trusted with important information, such as a term paper, may need access to a system, and modifying the filesystem table may be impractical. When things like this happen, it's easy to archive data to preserve permissions and stick it on a mounted partition or device, then unmount the device, preventing "accidental" access. (The potentially jokingly malicious user would need to know the filesystem 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 at '/media/windows' will be unmounted, and attempts to access it will yeild only an empty directory. To bring it back later, either reboot, or simply run the following command.

sudo mount /media/windows

Technical background information

How Linux manages partitions

Linux uses a virtual filesystem (VFS) to maintain a single tree of files, all spread from '/'. When a partition is mounted, it is added to the tree at its mount point.

When a FAT32 partition is mounted at '/media/windows', all access to '/media/windows' and everything below it is transparently handled by the Linux kernel using the 'vfat' module. Applications need not know they're dealing with anything else. However, mounting a partition at a location inside of another mounted partition is unpredictable, unstable, and generally a bad idea.

Every partiton maintains its own free space and internal filesystem, so they can be mounted on other systems and behave properly. (If you have two operating systems or a removable hard disk drive, feel free to test this -- it's hard to break anything, and sharing /home (provided no usernames overlap) and swap between two Linux installations is very convenient)

To see what's going on behind the scenes, try the 'df' and 'mount' commands.


CategoryDocumentation

AutomaticallyMountPartitions (last edited 2008-08-06 17:01:22 by localhost)