Mounting


Described in technical terms, mounting is the practice of making a file system available under Linux. This can take the form of a partition on your hard disk, a CD-ROM, a network server, or many other things.

Mounting drives might seem a strange concept, but it actually makes everything much simpler than it might be otherwise. For example, once a drive is mounted, there's no need to use any special commands or software to access its contents. You can use the same programs and tools that you use to access all of your other files. Mounting creates a level playing field on which everything is equal and can therefore be accessed quickly and efficiently.

Using the mount Command

Mounting is usually done via the mount command. Under SUSE Linux, you must be the root user to do this, although other versions of Linux are less strict and let ordinary users use the command, too.

With most modern versions of Linux, mount can be used in two ways: by specifying all the settings immediately after the command, or by making reference to an entry within the fstab file. This is a configuration file stored in the /etc directory that contains details of all file systems of the PC that can be mounted.

Note 

The root file system is itself mounted automatically during bootup, shortly after the kernel has started and has all your hardware up and running. Every file system that Linux uses must be mounted at some point.

Let's say that you insert a CD or DVD into your computer's DVD-ROM drive. To mount it and make it available to Linux, you would type:

mount /media/dvd

The mount command first looks in your fstab file in the etc directory to find what you're referring to. Figure 15-4 shows an example of the contents of that file. (The example in the figure uses the cat command, which is discussed in Chapter 16). Using this information, the mount command attempts to make the contents of the CD available in the /media/cdrom directory. Note that this is done in a virtual way; the files are not literally copied into the directory. The directory is merely a magical conduit that allows you to read the CD's contents.

image from book
Figure 15-4. Details of all frequently mounted file systems are held in the /etc/fstab file.

There aren't any special commands used to work with mounted drives. The shell commands discussed in Chapter 14 should do everything you need.

The mount command doesn't see widespread usage by most users nowadays, because most removable storage devices like CDs, and even photographic memory card readers, are mounted automatically under SUSE Linux. However, there will be occasions when you need to mount a drive manually.

Mounting a Drive Manually

Let's look at an example of when you might need to mount a drive manually. Suppose that you've just added a second hard disk to your PC that has previously been used on a Windows system. This has been added as the primary slave.

The first thing to do is create a mount point, which is an empty directory that will act as a location where you can tell mount to make the disk accessible. You can create this directory anywhere, but under SUSE Linux, the convention is to create it in the /mnt directory. Therefore, the following command should do the trick (assuming you've switched to root user):

mkdir /mnt/windows

You now need to know what kind of partition type is used on the disk, because you need to specify this when mounting. To find this out, use the fdisk command (you'll have to switch to root first—type su -). Type the following exactly as it appears:

fdisk -l /dev/hdb

This will list the partitions on the second disk drive (assuming an average PC system). With most hard disks used under Windows, you should find a single partition that will be either NTFS or FAT32.

Caution 

Be aware that fdisk is a dangerous system command that can damage your system. The program is designed to partition disks and can wipe your data if you're not careful!

With this information in hand, you're now ready to mount the disk. For a FAT32 disk, type the following:

mount -t vfat /dev/hdb1 /mnt/windows

For an NTFS disk, type the following:

mount -t ntfs /dev/hdb1 /mnt/windows

You use the -t command option to specify the file type and list the file in the /dev directory (this file is only virtual, of course, and merely represents the hardware). After this, you list the directory that is acting as your mount point.

Now when you browse to the /mnt/windows directory, by typing cd /mnt/windows, you should find the contents of the hard disk accessible.

For more information about the mount command, read its man page (type man mount).

Removing a Mounted System

What if you want to get rid of a mounted system? You might have noticed that you're unable to eject your CD while it's mounted—the button on the front of the drive just won't work.

There's a special command designed for the purposes of unmounting: umount (notice there's no n after the first u). It's used in the following simple way:

umount /media/cdrom

This will unmount the CD-ROM.

Note that if you're currently browsing the mounted directory, you'll need to leave it before you can unmount it. The same is true of all kinds of access to the mounted directory. If you're browsing the mounted drive with Konqueror or if a piece of software is accessing it, you won't be able to unmount it until you've quit the program and closed the Konqueror window (or browsed to a different part of the file system).




Beginning SUSE Linux from Novice to Professional
Beginning SUSE Linux: From Novice to Professional
ISBN: 1590594584
EAN: 2147483647
Year: 2005
Pages: 293
Authors: Keir Thomas

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net