Let's Visit Linux Mount and Unmount Again

by Anish


Posted on Friday December 21



mount - mount a filesystem

By default, the mount command displays a list of media devices currently mounted on the system:

$ sudo mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=2002872k,nr_inodes=500718,mode=755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
/dev/vda1 on /boot type ext2 (rw,relatime,block_validity,barrier,user_xattr,acl)
/dev/mapper/ubuntu--vg-root on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
.....
.....

The mount command provides four information:

  • The device filename of the media
  • The mount point in the virtual directory where the media is mounted
  • The filesystem type
  • The access status of the mounted media

The basic mount option

mount -t type device directory

Windows Device type

OS File Systems
Windows vfat,ntfs,iso9660

Linux Device type

lsblk displays block devices

$ lsblk -f
NAME  FSTYPE  LABEL UUID MOUNTPOINT
vda
 vda1  ext2  eb311fb6-841d-4220-9994-046ff3b46721 /boot
 vda2
 vda5  LVM2_member Gx5XbE-coCx-2c9e-XuP3-qD7T-R8GR-0k0nwV
 ubuntu--vg-root ext4  e2a78946-d108-438c-ac8c-4b003f74ae64 /
 ubuntu--vg-swap_1 swap  710191d7-7abd-4fb7-b4d9-eae243cd6077 [SWAP]

To mount the USB memory stick at device /dev/sdb1 at location /media/disk, you use the following command:

mount -t vfat /dev/sdb1 /media/disk

To mount the CDROM at device /dev/cdrom at location /mnt/disk, you use the following command:

mount /dev/cdrom /mnt/cdrom

mount Command options

Parameter Description
-a All the filesystems listed via getfsent(3) are mounted
-d Causes everything to be done except for the actual system call
-f Causes the mount command to simulate mounting a device, but not actually mount it
-s Ignores mount options not supported by the filesystem
-o async,force,noasync,noauto,nodev,noexec,noowners,nosuid,rdonly,sync,update,union,noatime,nobrowse mount -t hfs -o nosuid,-w,-m=755 /dev/disk2s9 /tmp
-r Mount the file system read-only

mounts all filesystems except those of type NFS and HFS.

mount -a -t nonfs,hfs

mounts NFS share

mount -t nfs ip_address:/dirname /mnt/localdiskname

The unmount command

To remove a removable media device, you should never just remove it from the system. Instead, you should always unmount it first

umount [directory | device ]

To unmount the data directory

sudo umount /data

If any program has a fi le open on a device, the system won't let you unmount it.

$  umount /data
umount: /data: device is busy 
umount: /data: device is busy

Mounting the Remote File System

SSHFS is Linux based software that needs to be installed on your local computer

sudo mkdir /data
sudo chown user:group /data
sudo sshfs -o allow_other,defer_permissions root@:/ /mnt/data
or for Key Based
sudo sshfs -o allow_other,defer_permissions,IdentityFile=~/.ssh/id_rsa root@:/ /mnt/data

How to Make a Mount Point

A mount point is "just" a directory. So all you need to do is to create a directory, then mount it, the only tricky part is the device name which you are mounting

mkdir /data
chown user:group /data
mount /dev/sdb1 /data
  • /dev/sda - raw device
  • /dev/sda1 - virtual device, like a partition

Device Names

IDE controller naming convention

drive name drive controller drive number
/dev/hda 1 1
/dev/hdb 1 2
/dev/hdc 2 1
/dev/hdd 2 2

partition names

drive name drive controller drive number partition type partition number
/dev/hda1 1 1 primary 1
/dev/hda2 1 1 primary 2
/dev/hda3 1 1 primary 3
/dev/hda4 1 1 swap NA
/dev/hdb1 1 2 primary 1
/dev/hdb2 1 2 primary 2
/dev/hdb3 1 2 primary 3
/dev/hdb4 1 2 primary 4

SCSI Drives

drive name drive controller drive number partition type partition number
/dev/sda1 1 6 primary 1
/dev/sda2 1 6 primary 2
/dev/sda3 1 6 primary 3

Next Reading : How to Monitoring All Executed Commands in Linux



Thanku for reading !!! Give a Share for Support

Asking for donation sound bad to me, so i'm raising fund from by offering all my Nine book for just $9


python Cryptography Topics
Topics
For Coffee/ Beer/ Amazon Bill and further development of the project Support by Purchasing, The Modern Cryptography CookBook for Just $9 Coupon Price

Kubernetes for DevOps

Hello Dockerfile

Cryptography for Python Developers

Cryptography for JavaScript Developers

Go lang ryptography for Developers