LPI Linux Certification/Control Mounting And Unmounting Of Filesystems
Detailed Objectives
[edit | edit source](LPIC-1 Version 5.0)
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 removeable filesystems.
- Use of labels and UUIDs for identifying and mounting file systems.
- Awareness of systemd mount units.
The following is a partial list of the used files, terms and utilities:
/etc/fstab
/media/
mount
umount
blkid
lsblk
Attach a filesystem
[edit | edit source]The mount command serves to attach the file system found on some device to the big file tree.
mount [options] mount [options] [-t vfstype] [-o options] device dir
If the device or directory is listed in /etc/fstab you can use the following:
mount [options] [-o options [,...]] device | dir
Normally only root has the privilege to mount devices unless it is specified in the /etc/fstab file. Examples:
# Print all the mounted filesystems (/etc/mtab). mount
# Mount devices or dirs listed in /etc/fstab. mount -a
# Mount /dev/hdc partition in read only mode without updating /etc/mtab. mount -n -o ro /dev/hdc /mnt
# Allow a user to mount the CDROM if the following line is in /etc/fstab: # /dev/cdrom /media/cdrom iso9660 ro,user,noauto,unhide mount /media/cdrom mount /dev/cdrom
# Sync in realtime mount -o sync /dev/sdb1 /mnt/usb
Detach a filesystem
[edit | edit source]To detach a filesystem from the file tree, use umount.
umount [options] umount [options] [-o options [,...]] device | dir
A busy filesystem cannot be unmounted.
- Open files
- Working directory of a process.
Examples:
umount -a # Unmount devices or dirs listed in /etc/fstab. umount /mnt # Unmount the filesystem attached to /mnt. umount /media/cdrom # Allow a user to unmount the CDROM if the following line is in /etc/fstab: /dev/cdrom /media/cdrom iso9660 ro,user,noauto,unhide
File system information
[edit | edit source]The file /etc/fstab contains all the file systems and related information that will be used when doing a mount -a. (Boot time)
The file /etc/mtab is maintained by the kernel and keeps track on what is or isn't mounted. The /etc/fstab format is:
#Device Mount point Fs type Options 1 2 /dev/hda3 / reiserfs defaults 1 2 /dev/hda1 /boot ext2 defaults 1 2 /dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0 usbdevfs /proc/bus/usb usbdevfs noauto 0 0 /dev/hda2 swap swap pri=42 0 0
Common options:
- ro: read only
- noauto: Don't mount automatically
- exec: Can execute binary on the filesystem
- suid: Allow to setuser bit
- user: Allow a user to mount/unmount it
- unhide: hidden file visible
- async: All operations will be done asynchronously
- default: rw, suid, dev, exec, auto, nouser, and async
Exercises
[edit | edit source]- Create a line in /etc/fstab that allows any user to access the floppy disk. Check that you can mount the floppy and can create a file with touch.
- Do the following manipulation:
- Create a ext2 file system on the floppy.
- Mount the floppy.
- Copy all the files /etc/*.conf into the floppy.
- Unmount it. What's happening?
- Mount it back and check that all the files are there.
- Issue the following command:
- Tar cvf /dev/fd0 /etc/*.conf
- Try to mount it back. What's happening?
- Use tar to view the contents of the floppy.