LPI Linux Certification/Control Mounting And Unmounting Of Filesystems
Candidates should be able to configure the mounting of a filesystem.
- Key knowledge area(s):
- Manually mount and unmount filesystems.
- Configure filesystem mounting on bootup.
- Configure user mountable removeable filesystems.
- The following is a partial list of the used files, terms and utilities:
Attach a filesystem
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
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.
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
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
- 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
- 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 happenning?
- Use tar to view the contents of the floppy.