Linux Administrator

How to Mount & Unmount Filesystem/Partition in Linux/UNIX

When we install new hard disk into our Linux system, typically we use utilities such as fdisk or parted to create partitions. After creating a partitions, we use mkfs command to create ex2, ext3, or ext4 partition. Than we use mount command to mount the partition into a mount point ( directory ) to use the filesystem.

In this tutorial I am going to explain how we can use mount and unmount command in Linux with example.

Mount command syntax

mount -t type device mount_point

1. Mounting A CD-ROM

The device file for CD exist under /dev directory, you can mount it like below.

# mount -t iso9660 -o ro /dev/cdrom /mnt

Where:

-o ro : Read Only access, CD ROM mounted wtih read only access
/mnt : Mount Point

2. Show All Mounts

To show the all mounts, execute the mount command without any arguments.

# mount
/dev/sda5 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)

OR, You can also use df command to show all the mount points.

# df
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sda5      195069136 128345036  56958520  70% /
udev             2008336         4   2008332   1% /dev
tmpfs             806244       928    805316   1% /run
none                5120         0      5120   0% /run/lock
none             2015604       228   2015376   1% /run/shm

3. Mount All The Filesystem Mentioned In /etc/fstab

/etc/fstab is used to mount the all filesystem during booting process. Follow the below command to mount all the filesytem mentioned in /etc/fstab.

# cat /etc/fstab
#
proc            /proc           proc    nodev,noexec,nosuid 0       0
/dev/sda5 /               ext4    errors=remount-ro 0       1
/dev/sda6 /mydata         ext2    defaults        0       2
/dev/sda7 /backup         vfat    defaults        0       3

Now execute the mount command with -a option to mount all the /etc/fstab entries.

# mount -a

# mount
/dev/sda5 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
/dev/sda6 on /mydata type ext2 (rw)
/dev/sda7 on /backup type vfat (rw)

To unmount all filesystem mentioned in /etc/fstab use same -a option with umount command like below.

# umount -a
umount: /run/shm: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
umount: /run: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
umount: /dev: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
umount: /: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

Above some filesystem are unable to unmount because it is busy or currently in use.

4. Mount Only A Specific Filesystem From /etc/fstab

It looks the mount point entries in “/etc/fstab” when you pass the directory name to mount.

# mount | grep /mountpoint

# cat /etc/fstab | grep mountpoint

 /dev/sda6 /mountpoint        ext2    defaults        0       2

Above You can see /mountpoint is not mounted but it is mentioned in ” /etc/fstab ” file. Now execute the below command to mount it.

# mount /mountpoint

# mount | grep /mountpoint
/dev/sda6 on /mountpointtype ext2 (rw)

You will get below error if we run again mount command.

# mount /mountpoint
mount: /dev/sda6 already mounted or /mountpointbusy
mount: according to mtab, /dev/sda6 is already mounted on /mountpoint

You can also use device name instead of directory name to mount.

# mount /dev/sda6

5. Show All Specific Type Mounted Partitions

Using -l with -t option you can list only specific type of filesystem like below.

# mount -l -t ext2
/dev/sda6 on /mountpoint type ext2 (rw)

# mount -l -t ext4
/dev/sda5 on / type ext4 (rw,errors=remount-ro)

6. Floppy Disk Mounting

The device file for Floppy Disk exist under /dev directory, you can mount it like below.

# mount /dev/fd0 /mnt
# cd /mnt

Unmount the Flopy Disk

# umount /mnt

7. Bind Mounts

Bind mounts are quite simple. Instead of mounting a device (with a file system) on a particular path you are mounting one path into another path.

For example: Let’s say you have a small /var but a very large /opt partition and you need additional space for your growing log files.

First, shut down the services writing to log files, then…

# mv /var/log /opt/var_log
# mkdir /var/log
# mount -o bind /opt/var_log /var/log

Now check the bind is done using below command.

# mount | grep var
/opt/var_log on /var/log type none (rw,bind)

Now restart the previously stopped services.

If want to persist across reboots, you will need to update your /etc/fstab file like below.

# vim /etc/fstab
/opt/var_log              /var/log                 none    bind    0 0

Save and exit.

8. Access The Data From New Mount Point

Follow the below command to access the data from new mounted point.

# mount -M /mountpoint /mnt/

Now you can check the old mount point moved to new mount point as shown below.

# mount | grep /mountpoint 
# mount | grep /mnt
/dev/sda6 on /mnt type ext2 (rw)

9. Mount Filesystem With Read/Write Access

Follow the below command to mount the filesytem with Read only access.

# mount /dev/sda6 /mountpoint -r
# mount  | grep /mountpoint 
/dev/sda6 on /mountpoint type ext4 (ro)

Here -r option is synonym to -o ro.

10. Remount The Mounted Filesystem

Follow the below command to remount the mounted filesytem.

# mount | grep /mountpoint 
/dev/sda6 on /mountpoint type ext4 (ro,noload)

# mount -o remount,rw /mountpoint 
# mount | grep /mountpoint 
/dev/sda6 on /mountpoint type ext4 (rw)

11. Mount ISO Image

Follow the below command to mount the ISO image.

# mount -t iso9660 -o loop centos_img.iso /mnt

12. Unmount Multiple Mounted Point

Follow the below command to unmount the more than one mount point.

# umount /mountpoint /mountpoint2
# mount | grep /mountpoint 
# mount | grep /mountpoint2

13. Lazy Unmount Of A Filesystem

Use lazy umount in cases where it was obviously stuck for various reasons (such as nfs server down), also when you need to see the original content of the directory that was mounted over by the mount. In both cases the mount is busy than you can do lazy unmount filesystem.

# umount /mydata -l

14. Unmounted File System Forcefully

Follow the below command to unmount the filesystem forcefully if device is busy.

# umount -f /mnt

If in any case it does not work go with lazy unmount.

I hope this article will help to mount and unmount the filesystem or partition in Linux. If you have any queries and problem please comment in comment section.

Thanks:)

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

5 Comments

  • > 7. Binding Mount Points To A New Mount Point
    > …
    > Now check the bind is done using below command.
    > # mount | grep /mountpoint
    > /dev/sda6 on /mountpoint type ext2 (rw)
    > /mountpoint on /mnt type none (rw,bind)

    This does not work for me, displaying a bind mount
    this way will show same info for both the original
    mount and the bind:
    /dev/sda6 on /mountpoint type ext2 (rw)
    /dev/sda6 on /mnt type ext2 (rw)
    (This might depend on whether /etc/mtab is a text
    file or a symbolic link to /proc/mounts.)

    > 9. Mount Filesystem With Read/Write Access
    > Follow the below command to mount the filesytem with read/write access.
    > # mount /dev/sda6 /mountpoint -r
    I think you meant to say “read-only” not “read/write” access.

Leave a Comment