Table of Content

Weight: 3

Description: Candidates should be able to configure the mounting of a filesystem.

Key Knowledge Areas:

  • Manually mount and unmount filesystems
  • Configure filesystem mounting on bootup
  • Configure user mountable removable filesystems

Terms and Utilities:

/etc/fstab
/media/
mount
umount

mount

show up mounts FS
- mount
- cat /dev/mounts or /proc/self/mounts

oldhorse@dclab-u1504s:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            230M     0  230M   0% /dev
tmpfs            49M  4.8M   44M  10% /run
/dev/sda1        98G  1.6G   91G   2% /
tmpfs           241M     0  241M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           241M     0  241M   0% /sys/fs/cgroup
/dev/sdb         20G   55M   19G   1% /myspace
tmpfs            49M     0   49M   0% /run/user/1000

oldhorse@dclab-u1504s:~$ cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#                
# / was on /dev/sda1 during installation
UUID=bb1f38c8-4af9-4e33-ae34-389cd3496734 /               ext4    errors=remount-ro 0       1
# swap was on /dev/sda5 during installation
UUID=dbc82d1f-d7eb-4afc-b1de-22f31f9dfd74 none            swap    sw              0       0
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0
/dev/sdb        /myspace        ext4    defaults,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0       1       3 
oldhorse@dclab-u1504s:~$ 

remount

root@dclab-u1504s:~# mount -o remount,ro /myspace/
root@dclab-u1504s:~# cd /myspace/
root@dclab-u1504s:/myspace# touch ttt
touch: cannot touch ‘ttt’: Read-only file system

UUID

Using a label or UUID makesyour system more robust when devices are added or removed.

root@dclab-u1504s:/myspace# blkid /dev/sdb
/dev/sdb: UUID="579506c9-2dee-4e12-aeba-8e88c3ea6453" TYPE="ext4"

root@dclab-u1504s:/myspace# mkdir uuid
root@dclab-u1504s:/myspace# mount UUID="579506c9-2dee-4e12-aeba-8e88c3ea6453" /myspace/uuid

root@dclab-u1504s:/myspace# df -h

/dev/sdb         20G   55M   19G   1% /myspace/uuid

root@dclab-u1504s:/myspace# ll uuid/
total 10564
drwxr-xr-x 3 oldhorse oldhorse    4096 Oct 17 09:43 ./
drwxr-xr-x 4 root     root        4096 Oct 18 01:58 ../
-rw------- 1 root     root        7168 Oct 17 09:18 aquota.group
-rw------- 1 root     root        7168 Oct 17 09:18 aquota.user
drwx------ 2 oldhorse oldhorse   16384 Oct  4 03:56 lost+found/
-rw-rw-r-- 1 oldhorse oldhorse 1048576 Oct 17 09:43 testfile1
-rw-rw-r-- 1 oldhorse oldhorse 9728000 Oct 17 09:43 testfile2

use softlink to mount

root@dclab-u1504s:/myspace# ls -l $( find /dev -lname "*sdb*")
lrwxrwxrwx 1 root root 6 Oct 18 01:43 /dev/block/8:16 -> ../sdb
lrwxrwxrwx 1 root root 9 Oct 18 01:43 /dev/disk/by-path/pci-0000:00:10.0-scsi-0:0:1:0 -> ../../sdb
lrwxrwxrwx 1 root root 9 Oct 18 01:43 /dev/disk/by-uuid/579506c9-2dee-4e12-aeba-8e88c3ea6453 -> ../../sdb

root@dclab-u1504s:/# mount /dev/disk/by-path/pci-0000:00:10.0-scsi-0:0:1:0 /myspace
root@dclab-u1504s:/# df -h|grep sdb
/dev/sdb         20G   55M   19G   1% /myspace

umount

umount <dev|mountpoint>

check opening file on mounted FS

root@dclab-u1504s:/# cd /myspace/
root@dclab-u1504s:/myspace# ll
total 10564
drwxr-xr-x  3 oldhorse oldhorse    4096 Oct 17 09:43 ./
drwxr-xr-x 23 root     root        4096 Oct 17 07:35 ../
-rw-------  1 root     root        7168 Oct 17 09:18 aquota.group
-rw-------  1 root     root        7168 Oct 17 09:18 aquota.user
drwx------  2 oldhorse oldhorse   16384 Oct  4 03:56 lost+found/
-rw-rw-r--  1 oldhorse oldhorse 1048576 Oct 17 09:43 testfile1
-rw-rw-r--  1 oldhorse oldhorse 9728000 Oct 17 09:43 testfile2
root@dclab-u1504s:/myspace# lsof -w /myspace/
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
bash     873 root  cwd    DIR   8,16     4096    2 /myspace
lsof    1060 root  cwd    DIR   8,16     4096    2 /myspace
lsof    1061 root  cwd    DIR   8,16     4096    2 /myspace

root@dclab-u1504s:/myspace# fuser -m /myspace/
/myspace:              873c
root@dclab-u1504s:/myspace# ps -ef|grep 873
root       873   872  0 01:55 pts/0    00:00:00 -su
root      1075   873  0 02:09 pts/0    00:00:00 ps -ef
root      1076   873  0 02:09 pts/0    00:00:00 grep --color=auto 873

lazy umount

root@dclab-u1504s:/myspace# umount /myspace 
umount: /myspace: target is busy
        (In some cases useful info about processes that
         use the device is found by lsof(8) or fuser(1).)
root@dclab-u1504s:/myspace# umount -l /myspace 
root@dclab-u1504s:/myspace# df -h|grep myspace
root@dclab-u1504s:/myspace# 

root@dclab-u1504s:/myspace# ll
total 10564
drwxr-xr-x 3 oldhorse oldhorse    4096 Oct 17 09:43 ./
drwxr-xr-x 3 oldhorse oldhorse    4096 Oct 17 09:43 ../
-rw------- 1 root     root        7168 Oct 17 09:18 aquota.group
-rw------- 1 root     root        7168 Oct 17 09:18 aquota.user
drwx------ 2 oldhorse oldhorse   16384 Oct  4 03:56 lost+found/
-rw-rw-r-- 1 oldhorse oldhorse 1048576 Oct 17 09:43 testfile1
-rw-rw-r-- 1 oldhorse oldhorse 9728000 Oct 17 09:43 testfile2

root@dclab-u1504s:/myspace# umount -f /myspace 
umount: /myspace: target is busy
        (In some cases useful info about processes that
         use the device is found by lsof(8) or fuser(1).)

CD/DVD mount

root@dclab-u1504s:/myspace# ls -l /dev|grep sr
lrwxrwxrwx 1 root root           3 Oct 18 01:43 cdrom -> sr1
lrwxrwxrwx 1 root root           3 Oct 18 01:43 cdrw -> sr1
lrwxrwxrwx 1 root root           3 Oct 18 01:43 dvd -> sr1
brw-rw---- 1 root cdrom    11,   0 Oct 18 01:43 sr0
brw-rw---- 1 root cdrom    11,   1 Oct 18 01:43 sr1

root@dclab-u1504s:/myspace# ll /media/
drwxr-xr-x  2 root root 4096 Sep 20 06:26 cdrom/

root@dclab-u1504s:/myspace# ll /media/cdrom/
total 8
drwxr-xr-x 2 root root 4096 Sep 20 06:26 ./
drwxr-xr-x 4 root root 4096 Sep 20 06:26 ../
root@dclab-u1504s:/myspace# mount /dev/sr0 /media/cdrom/

mount: /dev/sr0 is write-protected, mounting read-only
root@dclab-u1504s:/myspace# df -h

/dev/sr0         31M   31M     0 100% /media/cdrom
root@dclab-u1504s:/myspace# mount |grep sr0
/dev/sr0 on /media/cdrom type iso9660 (ro,relatime)
root@dclab-u1504s:/myspace# 

swap

root@dclab-u1504s:/myspace# swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda5                               partition       1045500 0       -1

root@dclab-u1504s:/myspace# fdisk -l /dev/sda

Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1d4280cc

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1  *         2048 207620095 207618048   99G 83 Linux
/dev/sda2       207622142 209713151   2091010 1021M  5 Extended
/dev/sda5       207622144 209713151   2091008 1021M 82 Linux swap / Solaris

Quiz questions

1. Write the full command to mount the first partition of the third scsi disk on the /mnt directory
2. How would you allow a non root user to mount a cdrom on /mnt/cdrom?
3. How does one prevent a filesystem from being mounted at bootup?
4. Who can use the umount command?
Answers to quiz questions
1. mount /dev/sdc1 /mnt
2. Create an entry in /etc/fstab with “user” and “noauto” in the options column.
3. Add “noauto” in the options column in /etc/fstab.
4. Only root, unless the filesystem was mounted by the user and the options column in /etc/fstab includes “user”.