Mounting Devices Part II

Total Page:16

File Type:pdf, Size:1020Kb

Mounting Devices Part II

s Mounting Devices – Part II

Other examples for creating a Mount: https://www.digitalocean.com/community/tutorials/how-to-set-up- an-nfs-mount-on-centos-6

 Displaying mounted file systems: To display all mounted file systems, issue the mount command. Or look at the files “ /proc/mounts and /etc/mtab “

 To display all mounts (via cmd): # mount | grep /dev/sdb

 Using “ /proc/mounts “: # cat /proc/mounts | grep /dev/sdb . The kernel provides the info in /proc/mounts in file form, but /proc/mounts doesn’t exist as a file on any hard disk.. Info comes directly from the kernel

 Using “ /etc/mtab “: # cat /etc/mtab | grep /dev/sdb . The /etc/mtab file is not updated by the kernel, but is maintained by the mount command. . don’t edit /etc/mtab manually

 “ df “ command: A more user friendly way to look at mounted file systems is the “ df “ command.. this command has the added benefit of showing you the free space on each mounted disk  Example: # df  Example: # df –h (diplays in human readable format)  Another Example: # df –h | egrep –e “(sdb2|File)”  “ du “ command:  Summarizes disk usage for files and directories. Using “du” on a mount point, you effectively get the disk space used on a file system  Example: du -h /boot /srv/wolf (display each subdirectory recursively)  -s option gives you a total summary for the parent directory  Example: # du –sh /boot /srv/wolf

 Permanent mounts: Until now, we performed all mounts manually, which works nice until the next reboot. There is a way to tell you pc to automatically mount certain file systems during boot.  “ /etc/fstab “ : the file system table located here contains a list of file systems, with an option to automatically mount each of them at boot time

. Command to see file: # cat /etc/fstab . Adding the following line, we can automate the mounting of a file system: /dev/sdb1 /home/project42 ext3 defaults 0 0

 the “/etc/fstab” file controls how Linux provides access to disk partitions and removable media devices . . . consists of a series of lines that contain six fields each  Example: Meaning of example above: 1.: The first column specifies the mount device. Most distributions now specify partitions by their labels or UUIDs. This practice can help reduce problems if partition numbers change. 2.: The second column specifies the mount point. 3.: The file system type code is the same as the type code used to mount a filesystem with the mount command. A file system type code of auto lets the kernel auto-detect the filesystem type, which can be a convenient option for removable media devices. Note that this option may not be available for all filesystems out there. 4.: One (or more) mount option(s). 5.: You will most likely leave this to 0 (otherwise set it to 1) to disable the dump utility to backup the filesystem upon boot (The dump program was once a common backup tool, but it is much less popular today.) 6.: This column specifies whether the integrity of the filesystem should be checked at boot time with fsck. A 0 means that fsck should not check a filesystem. The higher the number, the lowest the priority. Thus, the root partition will most likely have a value of 1, while all others that should be checked should have a value of 2.

Examples: To determine the UUID or Label name, use the following command:  blkid /dev/sdb1 RESULTS: /dev/sdb1: LABEL="Elements" UUID=4E1AEA7B1A6007" Type="ntfs"

 To mount a partition with label “NameHere” at boot time with rw and noexec attributes, add the following line in “/etc/fstab” file:  LABEL=NameHere /mountpath ext4 rw,noexec 0 0

 Securing mounts: File systems can be secured with several mount options..Here are some examples:  “ro” option will mount a file system as read only, preventing anyone from writing: # mount –t ext2 –o ro /dev/hdb1 /home/project42  “noexec” option will prevent the execution of binaries and scripts on the mounted file system: # mount –t ext2 –o noexec /dev/hdb1 /home/project42  “nosuid” option will ignore setuid bit set binaries on the mounted file system: # mount –o nosuid /dev/hdb1 /home/project42  “noacl” option prevents cluttering permissions with acl’s: # mount –o noacl /dev/hdb1 /home/project42

Exercise:  Mounting a USB Flash Drive

Recommended publications