You cannot access a hard drive partition, CD-ROM, or floppy diskette until the related device or partition is mounted. Mounting a device checks the status of the device and readies it for access. Linux can be configured to automatically mount a device or partition when it boots; but you must manually mount other devices and partitions.
If a device uses removable media, the media may not be present when the system boots. If the system is configured to automatically mount such a device and the media is not present, an error occurs. Therefore, devices that use removable media are not generally configured for automatic mounting.
Before you can remove media from a device, you must unmount it. The system also unmounts devices when it shuts down. Mounting and unmounting devices is a privileged operation; generally, only the root user can manually mount and unmount devices.
To mount a device or partition, you use the mount command, which has the following pattern:
options device directory
The mount command provides many options. However, you can generally use the mount command without any options; consult the manual page to learn about the available options.
The reason you can use the mount
command without options is that the file
/etc/fstab describes your system’s
devices and the type of filesystem each is likely to
contain. If you add a new device to your system, you may
need to revise the contents of
/etc/fstab or specify appropriate
options when you mount the device.
You must specify the device that you want to mount and a directory, known as the mount point. To make it convenient to access various devices, Linux treats a mounted device as a directory; mounting the device associates it with the named directory. For example, a common operation is mounting a CD-ROM. You can accomplish this with the command:
mount /dev/cdrom /mnt/cdrom
/dev/cdrom is a link that
points to the actual device file associated with your
system’s CD-ROM drive. The directory
/mnt/cdrom is a directory created by
the install program; this directory is conventionally used
as the mounting point for CD-ROMs. After the
command has completed, you can access files and directories
on the CD-ROM just as you would access ordinary
files and directories on the path
/mnt/cdrom. For example, to list the
top-level files and directories of the CD-ROM simply
To mount a floppy diskette in your
a: drive, type:
mount /dev/fd0 /mnt/floppy
To unmount a device, specify its mount point as an argument of the umount command. For example, to unmount a CD-ROM diskette, type:
Only the root user can unmount a device. Moreover, a device can be unmounted only if it’s not in use. If, for example, the working directory of a user is a directory of the device, the device cannot be unmounted.
Before you can write data on a floppy diskette, you must format it. The Linux command to format a floppy is fdformat. Simply follow the command with an argument that specifies the floppy drive and the capacity of the diskette; the available arguments are listed in Table 4.6. For example, to format a 1.44 MB floppy in your system’s a: drive, type:
Once you’ve formatted the floppy, you can mount it and then read and write it. Be sure you unmount the floppy diskette before you remove it. Unmounting the floppy diskette ensures that all pending data has been written to it; otherwise, the floppy diskette may be unusable due to corrupt data.