Mount or unmount local filesystems
Author: AndreasKuehl andreas dot kuehl at clicktivities dot net FreeBSD, KevinDKinsey
Reviewer: name contact BSD flavour
Reviewer: name contact BSD flavour
Concept
Be familiar with all aspects of mounting and unmounting local filesystems including:
- how to mount/umount a specified filesystem
- how to mount all filesystems
- configuring filesystems to be mounted at boot
- passing options to
mount(8)
, and - resolving
mount
errors.
Introduction
A traditional BSD system has several hard disk partitions; modern computers also have optical drives, perhaps an older "floppy" drive, and other special devices, such as USB or firewire storage devices, flash disks, cameras that are really mass storage devices, etc. In order for these devices to be read from or written to, they must be "mounted" to some portion of the filesystem "tree". Critical local filesystems are mounted automatically at boot time. Some removable devices can be configured to mount when attached. Sometimes you don't wish to mount a filesystem at boot time: these filesystems can be mount
ed manually.
/etc/fstab
and rc
The rc
process mounts all filesystems listed in /etc/fstab
, unless they are marked "noauto". A traditional fstab
might look like this:
""cat /etc/fstab ""# Device Mountpoint FStype Options Dump Pass# ""/dev/ad0s1b none swap sw 0 0 ""/dev/ad0s1a / ufs rw 1 1 ""/dev/ad0s1e /usr ufs rw 2 2 ""/dev/ad0s1d /var ufs rw 2 2 ""/dev/acd0 /cdrom cd9660 ro,noauto 0 0
At the very least, the root filesystem (second line above) must be mounted.
Using mount(8) and umount(8) manually
mount
and umount
(note: that doesn't say "unmount") vary in the amount and types of arguments they expect. Generally, umount
is a little simpler. When given no type parameter, mount
expects a device to be of type UFS or UFS2. A good number of examples appear below; see the manual pages for comprehensive instruction on these system calls. Note that when using umount
, the device must not be "busy" (example, you can't umount
/mnt when you [or anyone else] is working in that directory....)
Examples
Show all mounted filesystems
# mount
Mount partition e on the first slice of the primary master IDE hard disk at /usr:
# mount /dev/ad0s1e /usr
Same thing, SCSI disk
# mount /dev/da0s1e /usr
*Unmount /usr
# umount /usr
Mount all filesystems listed in /etc/fstab:
# mount -a
Note that filesystems marked "noauto" in /etc/fstab would not be mounted by the above command.
Mount optical media in the CD-ROM drive as listed in /etc/fstab:
# mount /cdrom
Mount a floppy disk to /mnt:
# mount -t msdos /dev/fd0 /mnt
*Prepare the floppy to be removed:
#**umount /mnt**
Mount a FAT32 formatted USB "key" on /mnt:
# mount_msdosfs /dev/da0s1 /mnt
Note that USB devices are assigned SCSI device names; if usbd(8)
is running, the system log file /var/log/messages should show the name of the device within a few seconds after the device is inserted. Also, note that mount -t msdos
and mount_msdosfs
actually accomplish the same operation.
Practice Exercises
- Practice mounting and un-mounting non-critical filesystems.
- What do you think would happen if you attempted to
umount /
?
More information
mount(8), umount(8), fstab(5)