Mandriva

Mounting I

Summary:

  • Why Linux Handles Media Differently
  • Default mount Setup In Mandrakelinux
  • Mounting In Detail
  • Writing Windows NTFS
Section index - KB index

Why Linux Handles Media Differently

If you are coming from a non-Unix operating system such as MS Windows 9.x or the 'classic' Mac OS, one of the main obstacles of getting to grips with Linux is its different handling of partitions, removable media and network shares (from now on referred to as 'media').

In those operating systems, partitions play a more or less prominent role in tasks related to files and directories. You have several 'drives' in Windows (e.g. A:, C:, D: etc) or 'Volumes' in Mac OS. Applications install to a folder of their own, dropping off one or more files in the 'system directories' of these operating systems. New partitions, external media or network shares appear as new 'drives' or 'volumes'.

In Unix, and thus in Linux, things are handled almost entirely differently. This is because in contrast to the later Mac OS and Windows operating systems, Unix systems have been developed from the start as multi-user operating systems: usually there were one or more central servers accessed by users via their terminals. Often directories were distributed; the users' home directories were on machine A, the executables and libraries on machine B etc. Users were usually not allowed to install their own applications. Instead they would have needed to ask the system administrator to install an application for them on the main server.
If such multi-user systems had used something like the Mac OS or Windows file systems, with their somewhat arbitrary 'volume' and 'drive' naming, their separate application directories, and their non-continuous directory structure, then administering them would have been something of a nightmare.

Linux has inherited the characteristics of the Unix file system, namely:

  • All partitions, external media and network shares are regarded as an internal part of the single system directory tree, starting at '/', the root directory.
  • There are no 'application folders'. Files are installed according to their type (e.g. executable, documentation etc), not according to the application to which they belong.
section index

Default Mount Setup In Mandriva Linux

One of the very first ideas which started Mandriva Linux off from Red Hat was to make media easier to access for users. Back in the old days, you had to be 'root' to mount a medium, and something as simple as installing an RPM from a CD was somewhat tedious: switch to 'root' account, insert CD, mount CD, install program, unmount CD, switch back to user account. This procedure soon becomes tiresome.

Of course, such a restriction makes perfect sense in a multi-user environment, with a single system administrator, where you don't want everyone to be able to 'muck around' with the system. However, it is unsuitable for single user machines.
Therefore all removable media were configured to be user (un)mountable in early Mandriva Linux releases. With the introduction of 'supermount' in Mandrakelinux 7.2, to be discussed later, a first attempt at automatic mounting of removable media was made. From Mandrakelinux 10.0 to Mandriva Linux 2005, a different auto-mounting system has been used. It is detailed here on the development wiki. Furthermore, all locally available Windows partitions are set up to be accessible (read-write) by users and are mounted automatically at boot time.

KDE and GNOME will use icons for removable drives. When you insert an optical disc or plug in a removable storage device, it will be automatically mounted and an icon for it will appear on the desktop. When you are finished using the disc or device you may simply remove it and the icon will disappear. However, there is a slight risk of data corruption involved in unplugging USB devices without unmounting them. To avoid this, you can unmount a USB device before removing it from the menu that appears when you right-click on its desktop icon.

Mandriva Linux also provides the ~DiskDrake tool which allows you to configure local mounts as well as resize partitions. ~DiskDrake is available as a graphical module of the Mandriva Linux Control Center (Hardware - Mount Points) but can also be run on the console. The Control Center also contains tools for configuring network mounts.

If you want to know all the gory details, however, you're welcome to read on ;-).

section index

Mounting In Detail

The idea behind 'mount' is pretty simple: we use a command to tell the system which media it should integrate into the tree or which it should remove. This way the system will always know which media are accessible and which are not.

A simple

$ mount

will provide you with a list of media currently mounted. If you have any Windows partitions on your system, these will usually be already mounted, too (directories '/mnt/win_drive).

In order to mount a medium ('to make it part of the local directory tree'), you (usually) have to be 'root' and you have to provide the system with some facts about the medium you want to mount: what the medium is and via which directory in the filesystem you want to access it:

~# mount device_name mount_point

To unmount, you use the 'umount' command (N.B. there is no 'n' in 'umount'1.1 ):

~# umount mount_point

An example: to mount an MS-Windows partition ('vfat') which resides on the first partition of the first IDE-disk to '/mnt/disk', you'll type (as root):

~# mount /dev/hda1 /mnt/disk

To unmount:

~# umount /mnt/disk

Easy, isn't it? ;-) Take this step by step.

Device Naming

In Unix and thus in Linux, everything is regarded as a file. All file and input/output operations are handled via files. Devices (hard disks, keyboards, graphic cards, printers etc) are also handled via files. These device files are located in the '/dev' directory. All read and/or write operations to and from devices go via these files. If you print a document, the data is simply sent to the device file of your printer in '/dev', if you save a file, that data is sent to the device file of the partition you save it to.

Device names follow strict conventions, which means that on all Linux systems each specific device has always the same device file.
The allowed device file names are listed in '/usr/src/linux/Documentation/devices.txt' (online copy).
Common device names are:

/dev/hda-h 1-63

e.g.

/dev/hda1

These are devices connected via IDE (hard disks and their partitions, CD-R, internal ZIP etc). The letter describes the position of the device on the bus (a=master on first IDE channel, b=slave on first IDE channel, c=master on second channel etc.).
The number describes the position of the partition. If the medium does not feature partitions (CD-Rs or DVDs for example), it simply doesn't require that number. A CD drive which is master on the second IDE channel has just '/dev/hdc' for its device file (or '/dev/cdrom' which in turns links to '/dev/hdc').

Everything that has partitions has their device names subdivided in names according to the partitions available (device name + partition number). The master hard disk on the first IDE channel has the device file '/dev/hda'. The first partition on that disk has the device name '/dev/hda1', the second '/dev/hda2' etc.

Things are a bit different, however, when Windows is installed on the same disk. Windows 9x is based on MS-DOS and thus can't handle more than one of the four 'primary' partitions available. Therefore further partitions ('drives') in Windows are created as so-called 'extended partitions' in one of the four 'primary partitions'. In Linux, the first 'extended' partition is always labeled as '5', even if one or more of the 'primary partitions' isn't used:

/dev/hda1 (...) b Win95 FAT32 /dev/hda2 (...) f Win95 Ext'd (LBA) /dev/hda5 (...) b Win95 FAT32 /dev/hda6 (...) 83 Linux

As you can see, the first partition is used by Windows 9x, which must be installed on the first primary partition. The second provides the structure for the 'extended partitions' (it's of no use by itself). '/dev/hda5' is the second Windows partition ('D:'), and Linux lives on '/dev/hda6', despite the fact there are only three 'real' partitions on the disk.

Why is it done this way? Because this way there's no device name shift in case another primary partition gets created. This new partition would get the device name '/dev/hda3'.

As you can see, a maximum of 63 partitions per disk is allowed.

/dev/fd0-7

These are the floppy devices, with '0' being the first drive and '7' being the eighth.

/dev/sda-p 0-15

SCSI disk devices. Numbering like IDE. Maximum of 15 partitions per disk. Notice that USB, FireWire and SATA devices are also handled via these devices files. On modern systems, all the drives could potentially be of this type.

/dev/sr0-15

SCSI CD-ROM devices, nowadays usually referred to as '/dev/scdx'. 0= first device, 1= second device etc. IDE CD-ROMs are handled via '/dev/hd'. Notice that all USB and IEEE 1394 CD/DVD/CD-R are handled via these device files, too.

/dev/pda-d

Parallel port IDE devices. Partitions as with IDE. Maximum of 15 partitions.

/dev/pf0-3

Parallel port ATAPI disk devices.

To find out what partitions are available on a device, either use 'diskdrake' from the Mandriva Linux Control Center (Hardware - Mount Points), or type

~# cfdisk -P s /dev/device_name

as 'root'. E.g. to find out about the first IDE hard disk in a system, you'd type cfdisk -P s /dev/hda.

Notice that upon installation Mandriva Linux configures a few mnemonic links like '/dev/cdrom' which points to the 'real' CD-R device file. You can create such links, too. If you have a ZIP which mounts to '/dev/sda4', you can - as 'root' - create a link like this one:

~# ln -s /dev/sda4 /dev/zip

Now you can use '/dev/zip' as an alternative device file name for that ZIP.

Optional: File System Type

Many explanations and tutorials on 'mount' mention the -t type option to specify the file system on the medium. You will find that for mounting local file systems, providing this option isn't necessary. 'mount' supports auto-detection for most of the supported local file systems.

~# mount /dev/hda1 -t vfat /mnt/disk

mounts the first partition on the first IDE hard disk to '/mnt/disk' and tells 'mount' which file system to expect ('vfat', the file system used by Windows 9x), instead of letting it figure it out on its own.

The -t option does have its use when mounting or unmounting multiple media at once:

~# umount -a -t vfat

for example unmounts all media with a Windows FAT file system on them.

Mount Point

This is a directory a medium is mounted to. If the medium is mounted, its content is accessible via this directory like with any other directory. If the medium isn't mounted, this directory is just an ordinary empty directory. You can even copy files into this empty directory. These files however will disappear when a medium gets mounted to this directory and reappear when the medium gets unmounted. From this it should also be clear that one directory can only be host to one mounted medium at any given time, you can however mount a medium to a directory on a mounted medium.
Notice that the access permissions on these directories do not have any influence on the permissions of mounted media.

If you have a look at the 'diskdrake' module or the file '/etc/fstab', you notice that two types of mounts can be distinguished by their mount points: one type is mounted to directories across the system ('/', '/home', '/usr', '/dev' etc), while the other type has their mount directories in the '/mnt' directory. The first type is integral part of the system, whereas the second is regarded as temporary (e.g. removable media, Windows partitions, network shares).

The reason for this distinction is easy to conceive: this makes it much easier to exclude temporary media from backups or system maintenance jobs, like for example the update of the database for the 'locate' command.

Optional: Options

Usually you won't need the -o options argument for the mount command. The default options are sensible, and for everything beyond you'd use the '/etc/fstab' file (to be discussed later).

'mount' basically has two sets of options for every 'mount' command: a set of general options applicable to all file systems (like -o ro for mounting a medium read-only, and a set of file system specific options (like -o codepage=850 to enable a special character conversion on a mounted Windows partition). Options are separated by a comma, no spaces. Read man mount for a complete listing.

Like the -t option, -O (capital O) can be used to (un)mount multiple media at once:

~# mount -a -O umask=0

for example mounts all media from '/etc/fstab' which have the 'umask=0' option in their entry. -t and -O can also be used together with -a:

~# umount -a -t vfat -O ro

unmounts all media with the Windows FAT file system on them which are mounted read-only.

On the next page, we'll be cleaning up this mess with a nice configuration file and have a look at 'supermount'.

section index

Writing Windows NTFS

The kernel 2.6 implements the possibility to write to a NTFS partition. However this is not recommended yet. So you should mount a NTFS partition readonly.

There are projects on the internet which already support the writing to NTFS:

The Linux-NTFS Project
Captive: The first free NTFS read/write filesystem for GNU/Linux

section index

Next Item: Configuring mounts, supermount


Related Resources:

Filesystems HOWTO

man mount

man 8 umount

man fstab

Revision / Modified: June 03, 2005
Author: Tom Berger
Updates: Adam Williamson

Legal: This page is covered by the GNU Free Documentation License. Standard disclaimers of warranty apply. Copyright LSTB and Mandrakesoft.

KB - Mounting I
Version 1.16 last modified by philippeboxho on 22/04/2006 at 19:04

 


en es fr

RSS

Creator: AdminWiki on 2004/03/22 09:44
(c) Mandriva 2007
18888888