Removable disks are prevalent in Unix machines; CD-ROMs, DVD-ROMs, Zip disks, and floppies are all removable disks. When a Unix system boots, normal filesystems are all mounted automatically. By definition, removable filesystems may not even be in the machine at boot time, and you certainly don't want to have to reboot your machine just to change CDs.
To do this, you use mount and umount
. The -t
option allows you
to specify the type of filesystem. On my FreeBSD machine, I can mount a
FAT-formatted Zip disk with:
# mount -t msdos /dev/afd0s4 /zip
If I've formatted the Zip disk with a BSD ufs filesystem
instead, I don't need the -t
option, since
ufs is the default on FreeBSD, and I would use the BSD
partitioning scheme (/dev/afd0c) instead of
the BIOS partitions (/dev/afd0s4).
If you use your removable disk regularly, you can add it to your fstab and make this simpler:
/dev/acd0c /cdrom cd9660 ro,noauto 0 0 /dev/afd0c /zip ufs rw,noauto 0 0 /dev/afd0s4 /mszip msdos rw,noauto 0 0
Note that I've set up my fstab for both ufs-formatted and
FAT-formatted Zip disks, and that the Zip drive and the CD-ROM are both set
noauto
to keep them from being
automatically mounted. Having these in my fstab means I can just type mount /zip or
mount /cdrom to mount a Zip disk or CD-ROM. Don't
forget to create the directories /cdrom,
/zip, and /mszip!
Generally the mount and umount commands must be run as root. However,
you'd often like normal users to be able to mount and unmount removable disks.
Linux has an easy way to do this: just add user
to the options field in /etc/fstab and normal users will be able to mount and unmount
that device. (Incidentally, Linux also has an auto
filesystem type, which is very handy for removable devices,
because it does its best to dynamically figure out what filesystem is on the
removable media.) On other platforms, it can be a little more complex.
Generally, the trick is to set the permissions on the device file properly. On
FreeBSD you also need to use sysctl to set
vfs.usermount
, which will allow users to
mount properly chmoded devices on directories
they own; similar tricks may be needed on other platforms. To set the floppy
drive to allow anyone to mount it and the CD-ROM to allow anyone in the cdrom
group to mount it, you'd do something like
this:
#chmod 666 /dev/fd0
#chgrp cdrom /dev/acd0c
#chmod 640 /dev/acd0c
Then, as a normal user in group cdrom
, you
could:
%mkdir ~/cdrom
%mount -t cd9660 /dev/acd0c ~/cdrom
Solaris has a daemon, vold, which handles all of the messy details of removable media for you. At the time of this writing, very current versions of Linux have automount daemons and devfsd to handle such things; check your platform's current documentation.
— DJPH