Working with Devices

This section presents commands that work with devices. You’ll learn how to mount and unmount devices and how to format a floppy diskette.

Mounting and Unmounting Drives

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.

Tip

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:

mount 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.

Tip

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:

root@desktop:/root# mount /dev/cdrom /cdrom

The file /dev/cdrom is a link that points to the actual device file associated with your system’s CD-ROM drive. The directory /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 /cdrom. For example, to list the top-level files and directories of the CD-ROM simply type:

root@desktop:/root# ls /cdrom

To mount a floppy diskette in your a: drive, type:

root@desktop:/root# mount /dev/fd0 /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:

root@desktop:/root# umount /cdrom

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.

Tip

If you can’t unmount a device, check each virtual console to see if one of them has a session that’s using the device as its working directory. If so, either exit the session or change to a working directory that isn’t associated with the device.

Formatting Floppy Diskettes

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:

root@desktop:/root# fdformat /dev/fd0H1440

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.

Table 4-6. Floppy Drive Designators

Designation

Meaning

/dev/fd0

3.5-inch diskette in a: (1.44 MB)

/dev/fd0d360

5.25-inch diskette in a: (360 kB)

/dev/fd0D720

3.5-inch diskette in a: (720 kB)

/dev/fd0h1200

5.25-inch diskette in a: (1.2 MB)

/dev/fd0H1440

3.5-inch diskette in a: (1.44 MB)

/dev/fd0H2880

3.5-inch diskette in a: (2.88 MB)

/dev/fd1

3.5-inch diskette in b: (1.44 MB)

/dev/fd1d360

5.25-inch diskette in b: (360 kB)

/dev/fd1D720

3.5-inch diskette in b: (720 kB)

/dev/fd1h1200

5.25-inch diskette in b: (1.2 MB)

/dev/fd1H1440

3.5-inch diskette in b: (1.44 MB)

/dev/fd1H2880

3.5-inch diskette in b: (2.88 MB)

Get Learning Debian GNU/Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.