- ChapterВ 2В Performing Basic File System Administration
- 2.1В Building File Systems
- 2.2В Mounting File Systems
- 2.2.1В About the mount Command
- 2.2.2В Using Additional Options of the mount Command
- 2.2.3В Mounting a File That Contains a File System Image
- 2.2.4В About the File System Mount Table
- 2.3В Configuring the Automounter
- 2.3.1В About the Automounter Configuration File
- 2.3.2В Installing and Enabling the Automounter
- 2.4В Creating a File System on a File Within Another File System
- 2.5В About Access Control Lists
- 2.5.1В Enabling ACL Support
- 2.5.2В Setting and Displaying ACLs
- 2.6В About Disk Quotas
- 2.6.1В Enabling Disk Quotas on File Systems
- 2.6.2В Assigning Disk Quotas to Users and Groups
- 2.6.3В Setting a Grace Period for Soft Limits
- 2.6.4В Displaying Disk Quotas
- 2.6.5В Enabling and Disabling Disk Quotas
- 2.6.6В Reporting on Disk Quota Usage
- 2.6.7В Maintaining the Accuracy of Disk Quota Reporting
ChapterВ 2В Performing Basic File System Administration
This chapter describes basic tasks for administering file systems. The chapter also describes how to configure Access Control Lists (ACLs) and how to configure and manage disk quotas.
2.1В Building File Systems
The mkfs command syntax enables you to build a file system on a block device:
Typically, the -t fstype and -L label options are used with the mkfs command. The following example builds an ext4 file system with the label Project:
If you do not specify the file system type, an ext2 file system is created by default.
As an alternative, you can omit -t fstype and instead use the appropriate full mkfs. extension command as listed in /sbin . The following command produces the same result as the previous command:
To display the file system type, use the blkid command, for example:
The output of the previous command would be similar to the following:
Each file system type supports a number of features that you can enable or disable by specifying additional options with either the simple mkfs command format or the full mkfs. extension command. For example, you can use the -J option to specify the size and location of the journal that is used by the ext* file system types.
For more information, see the blkid(8) , mkfs(8) , and mkfs.fstype(8) manual pages.
2.2В Mounting File Systems
To access a file system’s contents, you need to attach its block device to a mount point in the directory hierarchy. Any directory can be used to function as a mount point.
Typically, you create a new directory for a mount point. If you use an existing directory, the contents remain hidden until you unmount the overlying file system.
2.2.1В About the mount Command
You use the mount command to attach the device containing the file system to the mount point as follows:
The device can be mounted by referencing its name, UUID, or label. For example, to mount the file system that was created in the previous section to /var/projects , any of the following commands can be used after you create the directory by running the following commands:
Issuing the mount command by itself displays all of the currently mounted file systems. In the following example, an extract of the command’s output indicates the following:
/dev/sdb1 with an ext4 file system is mounted on /var/projects for both reading and writing
/dev/mapper/vg_host01-lv_root , an LVM logical volume also with an ext4 file system, is mounted on / for both reading and writing:
The output of the previous command would be similar to the following:
Alternatively, you can use the cat /proc/mounts command to display information about mounted file systems.
The df -h command displays information about file systems and their use of disk space:
To attach or bind a block device at multiple mount points, use the mount -B command.
You can also remount part of a directory hierarchy, which need not be a complete file system, somewhere else. For example, you would use the following command to mount /var/projects/project1 on /mnt , for example:
Each directory hierarchy acts as a mirror of the other. The same files are accessible in either location. However, any submounts are not replicated. These mirrors do not provide data redundancy.
To mount a file over another file, you would use the following command:
In the previous example, the /etc/hosts and /mnt/foo mount points represent the same file. The existing file that acts as a mount point is not accessible until you unmount the overlying file.
To include submounts in the mirror, use the -R option to execute a recursive bind.
When you use the -B or -R option, the file system mount options remain the same as those for the original mount point. To modify, the mount options, use a separate remount command, for example:
You can mark the submounts below a mount point as being shared, private, or slave . You can specify the following options:
Any mounts or unmounts below the specified mount point propagate to any mirrors that you create, and this mount hierarchy reflects mounts or unmount changes that you make to other mirrors.
mount —make-private mount_point
Any mounts or unmounts below the specified mount point do not propagate to other mirrors, nor does this mount hierarchy reflect mounts or unmount changes that you make to other mirrors.
mount —make-slave mount_point
Any mounts or unmounts below the specified mount point do not propagate to other mirrors, but this mount hierarchy does reflect mounts or unmount changes that you make to other mirrors.
To prevent a mount from being mirrored by using the -B or -R options, mark its mount point as being unbindable:
To move a mounted file system, directory hierarchy, or file between mount points, use the -M option, for example:
To unmount a file system, use the umount command:
Alternatively, you can specify the block device provided that it is mounted on just one mount point.
For more information, see the mount(8) and umount(8) manual pages.
2.2.2В Using Additional Options of the mount Command
You can further determine the mount command behavior by using the -o options , where options are a comma-separated list. Some of these options are as follows:
These options can also be entered in the /etc/fstab file.
Causes the file system to be mounted automatically by using the mount -a command.
Causes the execution of any binary files located in the file system.
The default number of available loop devices is 8. You can use the kernel boot parameter max_loop= N to configure up to 255 devices. Alternatively, add the following entry to /etc/modprobe.conf :
In the previous example, N is the number of loop devices that you require (from 0 to 255), and then reboot the system.
Prevents the file system from being mounted automatically when mount -a is issued.
Prevents the execution of any binary files located in the file system.
Prevents any user other than the root user from mounting or unmounting the file system.
Remounts the file system if it is already mounted. You would usually combine this option with another option such as ro or rw to change the behavior of a mounted file system.
Mounts a file system as read-only.
Mounts a file system for reading and writing.
Allows any user to mount or unmount the file system.
The following examples show different ways to use the mount -o options command syntax.
Mount the /dev/sdd1 file system as /test with read-only access and permit only the root user to mount or unmount the file system:
Mount an ISO image file on /mount/cdrom with read-only access by using the loop device:
Remount the /test file system with both read and write access, and do not permit the execution of any binary files that are located in the file system:
2.2.3В Mounting a File That Contains a File System Image
A loop device enables you to access a file as a block device. For example, you would mount a file that contains a DVD ISO image on the directory mount point /ISO as follows:
If required, create a permanent entry for the file system in the /etc/fstab file, for example:
2.2.4В About the File System Mount Table
The /etc/fstab file contains the file system mount table, which provides all of the information that the mount command requires to mount block devices or implement binding of mounts. If you add a file system, you must create the appropriate entry in the /etc/fstab file to ensure that the file system is mounted at boot time. The following are typical entries from this file:
The descriptions of each field in the previous output are as follows:
The first field indicates the device to mount, which is specified by the device name, UUID, or device label, or the specification of a remote file system. A UUID or device label is preferable to a device name if the device name could change, for example:
Note that the first field specifies the path of the file system, directory hierarchy, or file that is to be mounted on the mount point specified by the second field. The third and fourth fields are specified as none and bind .
The second field is either the mount point for a file system or swap to indicate a swap partition. The mount point must be a path to either a file or a directory.
The third field is the file system type, such as ext4 or swap .
The fourth field specifies any mount options.
The fifth column specifies whether the dump command should dump the file system ( 1 ) or not ( 0 ).
The sixth column identifies the order by which the fsck command performs a file system check at boot time. The root file system should have the value 1 , while other file systems have 2 . A value of 0 skips checking, as is appropriate for swap, for file systems that are not mounted at boot time, and for binding of existing mounts.
For bind mounts, only the first four fields are specified, for example:
For more information, see the fstab(5) manual page.
2.3В Configuring the Automounter
The automounter mounts file systems when they are accessed, rather than maintaining connections for those mounts at all times. When a file system becomes inactive for a certain period of time, the automounter unmounts it. Using automounting frees up system resources and improves system performance.
The automounter consists of two components: the autofs kernel module and the automount user-space daemon. It also references entries in /etc/auto.master , which is the automounter configuration file.
2.3.1В About the Automounter Configuration File
In the /etc/auto.master configuration file, each map entry specifies a mount point and a map file that contains definitions of the remote file systems that can be mounted, for example:
In the previous example, the /- , /misc , and /net entries are examples of a direct map, an indirect map, and a host map, respectively. Direct map entries always specify /- as the mount point. Host maps always specify the keyword -hosts instead of a map file.
A direct map contains definitions of directories that are automounted at the specified absolute path. In the example, the auto.direct map file might contain an entry similar to the following:
This entry is a directive to do the following:
Mount the file system /usr/man that is exported by host01 by specifying the ro and soft options.
Create the /usr/man mount point if it does not already exist. If the mount point exists , the mounted file system hides any existing files that it contains.
Because the default file system type is NFS, the previous example can be shortened to read as follows:
An indirect map contains definitions of directories or keys that are automounted relative to the mount point ( /misc ) that is specified in the /etc/auto.master file. For example, the /etc/auto.misc map file might contain entries similar to the following:
Note that the /misc directory must already exist; however, the automounter creates a mount point for the keys xyz , cd , and so on, if they do not already exist, and then removes them when it unmounts the file system.
For example, using the ls /misc/xyz command causes the automounter to the mount the /xyz directory, exported by host01 as /misc/xyz .
The cd and abc entries mount the following local file systems: an ISO image from the CD-ROM drive on /misc/cd and an ext3 file system from /dev/hda1 on /misc/abc . The fenetres entry mounts a Samba share as /misc/fenetres .
If a host map entry exists, and a command references an NFS server that is relative to the mount point ( /net ) by name, the automounter mounts all of the directories that the server exports below a subdirectory of the mount point named for the server. For example, the cd /net/host03 command causes the automounter to mount all exports from host03 below the /net/host03 directory. By default, the automounter uses the nosuid,nodev,intr mount options unless you override the options in the host map entry, as follows:
The name of the NFS server must be resolvable to an IP address in DNS or the /etc/hosts file.
For more information about NFS administration, see the Using NFS in Oracle Linux chapter in Oracle В® Linux 8: Managing Shared File Systems. See also the hosts.master(5) and auto.master(5) manual pages.
2.3.2В Installing and Enabling the Automounter
To configure a system to use automounting:
Install the autofs package and any other packages that are required to support remote file systems:
Edit the /etc/auto.master configuration file to define map entries that are appropriate to your file systems.
Start the autofs service, and configure the service to start following a system reboot:
You can configure various settings for autofs in the /etc/sysconfig/autofs file, including the idle timeout value after which a file system is automatically unmounted.
If you modify the /etc/auto.master or /etc/sysconfig/autofs file, restart the autofs service to re-read these files:
For more information, see the automount(8) and autofs(5) manual pages.
2.4В Creating a File System on a File Within Another File System
Create an empty file of the required size:
The output of the previous command would be as follows:
Create a file system on the file:
The output of the previous command would be as follows:
Mount the file as a file system by using a loop device:
The file appears as a normal file system when you run the sudo mount command:
If required, create a permanent entry for the file system in /etc/fstab :
2.5В About Access Control Lists
POSIX Access Control Lists (ACLs) provide a richer access control model than traditional UNIX Discretionary Access Control (DAC) that sets read, write, and execute permissions for the owner, group, and all other system users. You can configure ACLs that define access rights for more than just a single user or group, and specify rights for programs, processes, files, and directories. If you set a default ACL on a directory, its descendents inherit the same rights automatically. You can use ACLs with the btrfs , ext3 , ext4 , OCFS2 , and XFS file systems, as well as mounted NFS file systems.
An ACL consists of a set of rules that specify how a specific user or group can access the file or directory with which the ACL is associated. A regular ACL entry specifies access information for a single file or directory. A default ACL entry is set on directories only, and specifies default access information for any file within the directory that does not have an access ACL.
2.5.1В Enabling ACL Support
Ensure that the acl package is installed; and, if necessary install it as follows:
Edit the /etc/fstab file and change the entries for any file systems that you want to use ACLs so that they include the appropriate option that supports ACLs, for example:
For mounted Samba shares, use the cifsacl option instead of acl .
Remount the file systems:
2.5.2В Setting and Displaying ACLs
To add or modify the ACL rules for file, use the setfacl command with the following syntax:
ACL rules accept the following forms:
Sets the access ACL for the user specified by name or user ID. The permissions apply to the owner if a user is not specified.
[ d: ] g: group [ : permissions ]
Sets the access ACL for a group specified by name or group ID. The permissions apply to the owning group if a group is not specified.
[ d: ] m [ : ][ : permissions ]
Sets the effective rights mask, which is the union of all permissions of the owning group and all of the user and group entries.
[ d: ] o [ : ][ : permissions ]
Sets the access ACL for other (everyone else to whom no other rule applies).
The permissions are as follows: r , w , and x for read, write, and execute, respectively, as used with the chmod command.
The d: prefix is used to apply the rule to the default ACL for a directory.
To display a file’s ACL, use the getfacl command, for example:
The output of this command would be as follows:
If extended ACLs are active on a file, the ls -l command displays a plus sign ( + ) after the permissions:
The following examples show additional ways in which you would set and display ACLs for directories and files:
To grant read access to a file or directory by a user:
To display the name, owner, group, and ACL for a file or directory:
To remove write access to a file for all groups and users by modifying the effective rights mask rather than the ACL:
Note that the -x option removes rules for a user or group.
To remove the rules for a user from the ACL of a file use the following command:
To remove the rules for a group from the ACL of a file, use the following command:
Specifying the -b option removes all of the extended ACL entries from a file or directory, for example:
To copy the ACL of file f1 to file f2 , use the following command:
Set a default ACL of read and execute access for other on a directory as follows:
To promote the ACL settings of a directory to default ACL settings that can be inherited, use the following command:
Specify the -k option to remove the default ACL from a directory, for example:
For more information, see the acl(5) , setfacl(1) , and getfacl(1) manual pages.
2.6В About Disk Quotas
You can set disk quotas to restrict the amount of disk space ( blocks ) that users or groups can use, to limit the number of files ( inodes ) that users or groups can create, and to notify you when usage is reaching a specified limit. A hard limit specifies the maximum number of blocks or inodes that are available to a user or group on the file system. Users or groups can exceed a soft limit for a period of time, which is known as a grace period .
Oracle Linux 8 does not provide support for user and group disk quotas for a Btrfs file system. However, quota support at the subvolume level is available for a Btrfs file system as a technology preview in this release. For more information, see Section 3.6, “Using Quota Groups”.
For information about how to configure quotas for an XFS file system, see Section 5.8, “Managing Quotas on an XFS File System”.
2.6.1В Enabling Disk Quotas on File Systems
Install the quota package on the system, if it is not already installed:
Add the usrquota or grpquota options to the file system’s /etc/fstab entry:
Remount the file system:
Create the quota database files:
The previous command creates the files aquota.user and aquota.group in the root of the file system, which is /home in this example.
For more information, see the quotacheck(8) manual page.
2.6.2В Assigning Disk Quotas to Users and Groups
For a user, use the following command:
for a group, use the following command:
Running the previous command opens a text file opens in the default editor that is defined by the EDITOR environment variable, thus allowing you to specify the limits for the user or group, for example:
The blocks and inodes entries reflect the user’s current usage on a file system.
Setting a limit to 0 disables quota checking and enforcement for the corresponding blocks or inodes category.
Edit the soft and hard block limits for the number of blocks and inodes, then save the changes.
Alternatively, you can use the setquota command to configure quota limits from the command line. The -p option enables you to apply quota settings from one user or group to another user or group.
For more information, see the edquota(8) and setquota(8) manual pages.
2.6.3В Setting a Grace Period for Soft Limits
Run the following command to set a grace period for soft limits:
Running the previous command opens a text file in your default text editor, thus enabling you to specify the grace period, as shown in the following example:
Specify the grace periods for the soft limits on the number of blocks and inodes, then save the changes.
For more information, see the edquota(8) manual page.
2.6.4В Displaying Disk Quotas
To display a user’s disk usage, use the quota command without any options or arguments:
To display a group’s disk usage, add the -g option, use the following command:
To display information about file systems, where usage is over the quota limits, add the -q option, for example:
Users can also use the quota command to display disk usage for themselves and their group.
For more information, see the quota(1) manual page.
2.6.5В Enabling and Disabling Disk Quotas
To disable disk quotas for all users, groups on a specific file system, use the following command:
To disable disk quotas for all users, groups, and file systems, use the following command:
Reactivate disk quotas for all users, groups, and file systems as follows:
For more information, see the quotaon(1) manual page.
2.6.6В Reporting on Disk Quota Usage
To display the disk quota usage for a file system:
To display the disk quota usage for all file systems:
For more information, see the repquota(8) manual page.
2.6.7В Maintaining the Accuracy of Disk Quota Reporting
Uncontrolled system shutdowns can lead to inaccuracies in disk quota reports.
To rebuild the quota database for a file system:
Disable disk quotas for the file system:
Unmount the file system:
Rebuild the quota databases:
Mount the file system:
Enable disk quotas for the file system:
For more information, see the quotacheck(8) manual page.
Copyright В© 2020, 2021, Oracle and/or its affiliates. Legal Notices
Источник