O'Reilly logo

Linux Pocket Guide, 2nd Edition by Daniel J. Barrett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

mount — stdin  stdout  - file  -- opt  --help  --version

Synopsis

mount [options] device | directory

The mount command makes a partition accessible. Most commonly it handles disk drives (say, /dev/sda1) and removal media (e.g., USB keys), making them accessible via an existing directory (say, /mnt/mydir):

# mkdir /mnt/mydir
# ls /mnt/mydir                 Notice it’s empty
# mount /dev/sda1 /mnt/mydir
# ls /mnt/mydir
file1      file2      file3     Files on the mounted partition
# df /mnt/mydir
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1        1011928  285744    674780  30% /mnt/mydir

mount has tons of options and uses; we will discuss only the most basic.

In most common cases, mount reads the file /etc/fstab (filesystem table) to learn how to mount a desired disk. For example, if you type mount /usr, the mount command looks up “/usr” in /etc/fstab, whose line might look like this:

/dev/sda8    /usr    ext3    defaults    1    2

Here mount learns, among other things, that disk device /dev/sda8 should be mounted on /usr as a Linux ext3-formatted filesystem. Now you can mount /dev/sda8 on /usr with either of these commands:

# mount /dev/sda8     by device
# mount /usr          by directory

mount is run typically by the superuser, but common devices like USB and CD-ROM drives often can be mounted and unmounted by any user.

$ mount /media/cdrom

Useful options

-t type

Specify the type of filesystem, such as ext3 or ntfs.

-l

List all mounted filesystems; works with -t too.

-a

Mount all filesystems listed in /etc/fstab. Ignores entries ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required