< Day Day Up > |
9.9.1 ProblemYou need to know how to insert and remove removable disks, such as floppies, CDs, or USB storage devices. 9.9.2 SolutionUse the mount and umount commands. This example mounts a CD drive: # mount -r -t iso9660 /dev/scd0 /cdrom -r means read-only; -t iso9660 is the filesystem type. /dev/scd0 is the name the kernel assigns to the device. /cdrom is the directory in which it is mounted. The /cdrom directory must already be present before you try to mount the disk. To find the filesystem type, use the file command: $ file - < /dev/scd0 /dev/stdin: ISO 9660 CD-ROM filesystem data 'Data1 You can omit the -r (read-only) flag when mounting a CD-ROM. It will complain, but it'll mount the disk anyway: # mount -t iso9660 /dev/scd0 /cdrom mount: block device /dev/scd0 is write-protected, mounting read-only This mounts a floppy disk readable/writable: # mount -w /dev/fd0 /floppy The following command mounts a USB storage device. The noatime option should be used on rewritable media that have a limited number of rewrites, such as CD/DVD-RW and flash storage devices: # mount -w -o noatime /dev/sda1 /memstick To unmount the device, use: # umount /memstick You may get a response like: # umount /memstick umount: /memstick: device is busy This means something (an application, a shell, or a file manager) is reading the filesystem. You can find out what with lsof (list open files): $ lsof /memstick COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME gs 938 dawnm 128r DIR 2,0 1024 12 /memstick/may-04.pdf bash 938 dawnm 129r DIR 2,0 1024 24 /memstick Now you can either close out the applications, or kill the lot with a single command: # kill -9 `lsof -t /memstick` mount can only be run by root. To give non-root users permission to mount removeable disks, you'll need to edit /etc/fstab (see the next recipe). 9.9.3 DiscussionThe umount "device is busy" error most commonly comes from having a terminal window open with the mounted device as a current working directory, like this: carla@windbag:/floppy$ It is important to unmount a disk before removing it. This gives the system a chance to complete any writes and to cleanly unmount the filesystem. On newer Linux systems, you can get away without specifying the filesystem type, because mount autodetects the filesystem types. 9.9.4 See Also
|
< Day Day Up > |