05.1 – Create, mount, unmount, and use vfat, ext4, and xfs file systems
Overview
Creating, mounting, unmounting, and using different file systems is a fundamental skill for system administration. This guide covers VFAT, EXT4, and XFS file systems, which are commonly used in Linux environments.
Creating File Systems
VFAT (FAT32)
VFAT is commonly used for compatibility with Windows systems and removable media.
Create a VFAT File System
sudo mkfs.vfat /dev/sdb1EXT4
EXT4 is a widely used Linux file system known for its performance and reliability.
Create an EXT4 File System
sudo mkfs.ext4 /dev/sdb1XFS
XFS is a high-performance file system suitable for large files and high-capacity storage.
Create an XFS File System
sudo mkfs.xfs /dev/sdb1Mounting File Systems
Create a Mount Point
Before mounting a file system, create a directory to serve as the mount point.
sudo mkdir /mnt/mydataMount the File System
Mount VFAT
sudo mount -t vfat /dev/sdb1 /mnt/mydataMount EXT4
sudo mount -t ext4 /dev/sdb1 /mnt/mydataMount XFS
sudo mount -t xfs /dev/sdb1 /mnt/mydataVerify the Mount
Check if the file system is mounted:
df -h /mnt/mydataSample Output:
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 100G 1G 99G 1% /mnt/mydataUnmounting File Systems
Unmount the File System
To unmount a file system, use the umount command:
sudo umount /mnt/mydataVerify the Unmount
Ensure the file system is no longer mounted:
df -h /mnt/mydataUsing File Systems
VFAT
- Create a Directory:
sudo mkdir /mnt/mydata/vfat_dir- Copy Files:
sudo cp /path/to/file /mnt/mydata/vfat_dir/EXT4
- Create a Directory:
sudo mkdir /mnt/mydata/ext4_dir- Copy Files:
sudo cp /path/to/file /mnt/mydata/ext4_dir/XFS
- Create a Directory:
sudo mkdir /mnt/mydata/xfs_dir- Copy Files:
sudo cp /path/to/file /mnt/mydata/xfs_dir/Making Mounts Permanent
To ensure file systems are mounted at boot, add entries to /etc/fstab.
Edit /etc/fstab
sudo nano /etc/fstabAdd Entries
VFAT
/dev/sdb1 /mnt/mydata vfat defaults 0 0EXT4
/dev/sdb1 /mnt/mydata ext4 defaults 0 0XFS
/dev/sdb1 /mnt/mydata xfs defaults 0 0Apply Changes
Mount all file systems listed in /etc/fstab:
sudo mount -aPractical Examples
Example 1: Create and Use a VFAT File System
- Create a VFAT File System:
sudo mkfs.vfat /dev/sdb1- Create a Mount Point:
sudo mkdir /mnt/vfat_data- Mount the File System:
sudo mount -t vfat /dev/sdb1 /mnt/vfat_data- Copy Files:
sudo cp /path/to/file /mnt/vfat_data/- Unmount the File System:
sudo umount /mnt/vfat_dataExample 2: Create and Use an EXT4 File System
- Create an EXT4 File System:
sudo mkfs.ext4 /dev/sdb1- Create a Mount Point:
sudo mkdir /mnt/ext4_data- Mount the File System:
sudo mount -t ext4 /dev/sdb1 /mnt/ext4_data- Copy Files:
sudo cp /path/to/file /mnt/ext4_data/- Unmount the File System:
sudo umount /mnt/ext4_dataExample 3: Create and Use an XFS File System
- Create an XFS File System:
sudo mkfs.xfs /dev/sdb1- Create a Mount Point:
sudo mkdir /mnt/xfs_data- Mount the File System:
sudo mount -t xfs /dev/sdb1 /mnt/xfs_data- Copy Files:
sudo cp /path/to/file /mnt/xfs_data/- Unmount the File System:
sudo umount /mnt/xfs_dataAdditional Tips
- Check File System Type:
sudo blkid /dev/sdb1- View Mounted File Systems:
df -h- Check Disk Usage:
du -sh /mnt/mydata- Repair File Systems:
- EXT4:
sudo fsck.ext4 /dev/sdb1- XFS:
sudo xfs_repair /dev/sdb1Conclusion
Creating, mounting, unmounting, and using VFAT, EXT4, and XFS file systems are essential skills for system administration. Mastery of these tasks ensures efficient and flexible disk management, which is crucial for the RHCSA exam.
These notes should help you understand how to create, mount, unmount, and use VFAT, EXT4, and XFS file systems for the RHCSA exam.
05.2 – Mount and unmount network file systems using NFS
Overview
Network File System (NFS) allows a system to share directories and files with others over a network. This guide covers how to mount and unmount NFS shares, which is a crucial skill for system administration.
Prerequisites
- Ensure the NFS server is set up and the NFS service is running.
- The client system should have the
nfs-utilspackage installed.
Install nfs-utils
sudo yum install nfs-utilsMounting NFS File Systems
Step 1: Identify the NFS Share
Determine the NFS share you want to mount. This information is typically provided by the NFS server administrator.
Example NFS Share:
nfs-server:/exported/directoryStep 2: Create a Mount Point
Create a directory on the client system where the NFS share will be mounted.
sudo mkdir -p /mnt/nfs_shareStep 3: Mount the NFS Share
Use the mount command to mount the NFS share.
Syntax
sudo mount -t nfs <nfs_server>:<exported_directory> <mount_point>Example
sudo mount -t nfs nfs-server:/exported/directory /mnt/nfs_shareStep 4: Verify the Mount
Check if the NFS share is mounted:
df -h /mnt/nfs_shareSample Output:
Filesystem Size Used Avail Use% Mounted on
nfs-server:/exported/directory 100G 1G 99G 1% /mnt/nfs_shareMaking the Mount Permanent
To ensure the NFS share is mounted at boot, add an entry to /etc/fstab.
Edit /etc/fstab
sudo nano /etc/fstabAdd the NFS Entry
nfs-server:/exported/directory /mnt/nfs_share nfs defaults 0 0Apply Changes
Mount all file systems listed in /etc/fstab:
sudo mount -aVerify the Mount
Check if the NFS share is mounted:
df -h /mnt/nfs_shareUnmounting NFS File Systems
Step 1: Unmount the NFS Share
Use the umount command to unmount the NFS share.
sudo umount /mnt/nfs_shareStep 2: Verify the Unmount
Ensure the NFS share is no longer mounted:
df -h /mnt/nfs_sharePractical Examples
Example 1: Mount an NFS Share Temporarily
- Create a Mount Point:
sudo mkdir -p /mnt/nfs_temp- Mount the NFS Share:
sudo mount -t nfs nfs-server:/exported/temp /mnt/nfs_temp- Verify the Mount:
df -h /mnt/nfs_temp- Unmount the NFS Share:
sudo umount /mnt/nfs_tempExample 2: Mount an NFS Share Permanently
- Create a Mount Point:sudo mkdir -p /mnt/nfs_permanent
- Edit
/etc/fstab:sudo nano /etc/fstab - Add the NFS Entry:nfs-server:/exported/permanent /mnt/nfs_permanent nfs defaults 0 0
- Mount All File Systems:sudo mount -a
- Verify the Mount:df -h /mnt/nfs_permanent
Additional Tips
- Check NFS Server Exports:On the NFS server, view the exported directories:
sudo exportfs -v- Mount Options:
ro: Mount the NFS share as read-only.rw: Mount the NFS share as read-write.noexec: Prevent execution of binaries on the mounted file system.nosuid: Ignore set-user-identifier or set-group-identifier bits.
sudo mount -t nfs -o rw,noexec,nosuid nfs-server:/exported/directory /mnt/nfs_share- Troubleshooting:
- Check Mount Status:
sudo mount | grep nfs- View NFS Logs:
sudo journalctl -u nfs- Unmounting Busy File Systems:If the NFS share is busy, use
fuserto identify processes using the mount point:
sudo fuser -m /mnt/nfs_shareThen, force unmount:
sudo umount -l /mnt/nfs_shareConclusion
Mounting and unmounting NFS file systems is a crucial skill for managing networked storage in Linux environments. Mastery of these tasks ensures efficient and reliable access to shared resources, which is essential for the RHCSA exam.
These notes should help you understand how to mount and unmount network file systems using NFS for the RHCSA exam.
05.3 – Configure autofs
Overview
Autofs is a service in Linux that automatically mounts and unmounts file systems as needed. It is particularly useful for mounting network file systems like NFS on demand, reducing the need for manual mounting and unmounting.
Installing Autofs
Step 1: Install the Autofs Package
Ensure the autofs package is installed on your system.
sudo yum install autofsConfiguring Autofs
Step 2: Edit the Master Map File
The master map file /etc/auto.master defines the top-level directories that autofs will manage.
sudo nano /etc/auto.masterExample Entry in /etc/auto.master
/mnt/nfs /etc/auto.nfs --timeout=600/mnt/nfs: The directory where autofs will mount the file systems./etc/auto.nfs: The map file that contains the mount points and options.--timeout=600: The time (in seconds) after which an idle mount will be unmounted.
Step 3: Create the Map File
Create the map file referenced in /etc/auto.master. This file contains the specific mount points and options.
sudo nano /etc/auto.nfsExample Entries in /etc/auto.nfs
share1 -fstype=nfs,rw nfs-server:/exported/share1
share2 -fstype=nfs,ro nfs-server:/exported/share2share1: The directory under/mnt/nfswhere the NFS share will be mounted.-fstype=nfs,rw: The file system type and mount options.nfs-server:/exported/share1: The NFS server and exported directory.
Step 4: Start and Enable the Autofs Service
Start the autofs service and enable it to start at boot.
sudo systemctl start autofs
sudo systemctl enable autofsStep 5: Verify the Configuration
Check the status of the autofs service to ensure it is running.
sudo systemctl status autofsUsing Autofs
Accessing the Mount Points
When you access the directory specified in the master map file, autofs will automatically mount the file system.
ls /mnt/nfs/share1Verifying the Mount
Check if the file system is mounted.
df -h /mnt/nfs/share1Sample Output:
Filesystem Size Used Avail Use% Mounted on
nfs-server:/exported/share1 100G 1G 99G 1% /mnt/nfs/share1Unmounting Idle File Systems
Autofs will automatically unmount file systems after the specified timeout period if they are not in use.
Practical Examples
Example 1: Configure Autofs for NFS Shares
- Edit the Master Map File:
sudo nano /etc/auto.masterAdd the following entry:
/mnt/nfs /etc/auto.nfs --timeout=600- Create the Map File:
sudo nano /etc/auto.nfsAdd the following entries:
share1 -fstype=nfs,rw nfs-server:/exported/share1
share2 -fstype=nfs,ro nfs-server:/exported/share2- Start and Enable Autofs:
sudo systemctl start autofssudo systemctl enable autofs- Access the Mount Points:
ls /mnt/nfs/share1- Verify the Mount:
df -h /mnt/nfs/share1Example 2: Configure Autofs for Local Directories
- Edit the Master Map File:
sudo nano /etc/auto.masterAdd the following entry:
/mnt/local /etc/auto.local --timeout=300- Create the Map File:
sudo nano /etc/auto.localAdd the following entries:
data1 -fstype=ext4 :/dev/sdb1
data2 -fstype=xfs :/dev/sdc1- Start and Enable Autofs:
sudo systemctl start autofs
sudo systemctl enable autofs- Access the Mount Points:
ls /mnt/local/data1- Verify the Mount:
df -h /mnt/local/data1Additional Tips
- Reload Autofs Configuration:If you make changes to the configuration files, reload the autofs service:
sudo systemctl reload autofs- Debugging Autofs:Enable verbose logging for troubleshooting:
sudo automount -f -v- Check Active Mounts:List currently active autofs mounts:
sudo automount -m- Unmount Manually:If needed, manually unmount an autofs mount point:
sudo umount /mnt/nfs/share1Conclusion
Configuring autofs allows for automatic mounting and unmounting of file systems, which simplifies the management of network and local storage. Mastery of autofs configuration is essential for efficient system administration and is a key competency for the RHCSA exam.
These notes should help you understand how to configure autofs for the RHCSA exam.
05.4 – Extend existing logical volumes
Overview
Extending logical volumes (LVs) allows you to increase the size of a file system to accommodate more data. This process involves extending the LV and then resizing the file system to use the additional space. This guide covers the steps to extend LVs in a non-destructive manner.
Prerequisites
- Ensure there is enough free space in the volume group (VG) to extend the logical volume.
- Backup important data before making changes to disk partitions or logical volumes.
Steps to Extend a Logical Volume
Step 1: Check Available Space in the Volume Group
Use the vgs command to check the available space in the volume group.
sudo vgsSample Output:
VG #PV #LV #SN Attr VSize VFree
vg_data 2 3 0 wz--n- 100.00g 20.00gStep 2: Extend the Logical Volume
Use the lvextend command to extend the logical volume.
Syntax
sudo lvextend -L +<size> <lv_path>-L +<size>: The amount of space to add to the logical volume (e.g.,+10Gfor 10 GB).<lv_path>: The path to the logical volume (e.g.,/dev/vg_data/lv_data).
Example
Extend the logical volume by 10 GB:
sudo lvextend -L +10G /dev/vg_data/lv_dataSample Output:
Size of logical volume vg_data/lv_data changed from 20.00 GiB (5120 extents) to 30.00 GiB (7680 extents).
Logical volume vg_data/lv_data successfully resized.Step 3: Resize the File System
After extending the logical volume, resize the file system to use the additional space.
For EXT4 File Systems
sudo resize2fs /dev/vg_data/lv_dataSample Output:
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/vg_data/lv_data is mounted on /mnt/data; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 4
The filesystem on /dev/vg_data/lv_data is now 7864320 (4k) blocks long.For XFS File Systems
sudo xfs_growfs /mnt/dataSample Output:
meta-data=/dev/mapper/vg_data-lv_data isize=512 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=5242880, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 5242880 to 7864320Step 4: Verify the Changes
Check the size of the logical volume and the file system to ensure they have been resized correctly.
Verify Logical Volume Size
sudo lvsSample Output:
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv_data vg_data -wi-ao---- 30.00g
Verify File System Size
df -h /mnt/dataSample Output:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_data-lv_data 30G 1G 29G 4% /mnt/dataPractical Examples
Example 1: Extend an EXT4 Logical Volume
- Check Available Space in the Volume Group:
sudo vgs- Extend the Logical Volume by 5 GB:
sudo lvextend -L +5G /dev/vg_data/lv_data- Resize the EXT4 File System:
sudo resize2fs /dev/vg_data/lv_data- Verify the Changes:
sudo lvsdf -h /mnt/dataExample 2: Extend an XFS Logical Volume
- Check Available Space in the Volume Group:
sudo vgs- Extend the Logical Volume by 10 GB:
sudo lvextend -L +10G /dev/vg_data/lv_data- Resize the XFS File System:
sudo xfs_growfs /mnt/data- Verify the Changes:
sudo lvsdf -h /mnt/dataAdditional Tips
- Check Free Space in Volume Group:
sudo vgdisplay vg_data | grep "Free PE"- Extend Logical Volume to Use All Free Space:
sudo lvextend -l +100%FREE /dev/vg_data/lv_data- Monitor Disk Usage:Use
df -handlvsto monitor disk usage and logical volume status. - Backup Data:Always have recent backups before resizing logical volumes.
Conclusion
Extending existing logical volumes allows for flexible and dynamic disk management in Linux. Mastery of these tasks ensures efficient utilization of storage resources, which is essential for the RHCSA exam.
These notes should help you understand how to extend existing logical volumes for the RHCSA exam.
05.6 – Create and configure set-GID directories for collaboration
Overview
Set-GID (Set Group ID) directories are used to facilitate collaboration by ensuring that files created within the directory inherit the group ownership of the directory. This is useful in environments where multiple users need to share and collaborate on files.
Creating a Set-GID Directory
Step 1: Create the Directory
Create a directory that will be used for collaboration.
sudo mkdir /sharedStep 2: Set the Group Ownership
Change the group ownership of the directory to a specific group that all collaborating users are members of.
sudo chown :collaborators /shared- Replace
collaboratorswith the name of the group.
Step 3: Set the Set-GID Bit
Set the Set-GID bit on the directory to ensure that files created within the directory inherit the group ownership.
sudo chmod 2775 /shared2: Sets the Set-GID bit.7: Sets read, write, and execute permissions for the owner.7: Sets read, write, and execute permissions for the group.5: Sets read and execute permissions for others.
Verify the Set-GID Bit
Use the ls -ld command to verify that the Set-GID bit is set.
ls -ld /sharedSample Output:
drwxrwsr-x. 2 root collaborators 4096 Oct 1 12:00 /shared- The
sin the group permissions indicates that the Set-GID bit is set.
Adding Users to the Group
Step 1: Create the Group (If Necessary)
If the group does not already exist, create it.
sudo groupadd collaboratorsStep 2: Add Users to the Group
Add users to the group to grant them access to the shared directory.
sudo usermod -aG collaborators user1
sudo usermod -aG collaborators user2- Replace
user1anduser2with the usernames of the collaborating users.
Verify Group Membership
Use the groups command to verify that the users are members of the group.
groups user1Sample Output:
user1 : user1 collaboratorsConfiguring Default Permissions
Step 1: Set Default ACLs
Set default Access Control Lists (ACLs) to ensure that new files and directories created within the shared directory have the correct permissions.
sudo setfacl -d -m g::rwx /sharedsudo setfacl -d -m o::rx /shared-d: Sets default ACLs.-m: Modifies the ACL.g::rwx: Grants read, write, and execute permissions to the group.o::rx: Grants read and execute permissions to others.
Verify Default ACLs
Use the getfacl command to verify the default ACLs.
getfacl /sharedSample Output:
# file: shared
# owner: root
# group: collaborators
user::rwx
group::rwx
other::rx
default:user::rwx
default:group::rwx
default:other::rxPractical Examples
Example 1: Create a Set-GID Directory for a Project
- Create the Directory:
sudo mkdir /project- Set the Group Ownership:
sudo chown :projectteam /project
- Set the Set-GID Bit:
sudo chmod 2775 /project- Add Users to the Group:
sudo usermod -aG projectteam alice
sudo usermod -aG projectteam bob- Set Default ACLs:
sudo setfacl -d -m g::rwx /project
sudo setfacl -d -m o::rx /project- Verify the Configuration:
ls -ld /projectgetfacl /projectExample 2: Create a Shared Directory for a Department
- Create the Directory:
sudo mkdir /department- Set the Group Ownership:
sudo chown :deptgroup /department- Set the Set-GID Bit:
sudo chmod 2775 /department- Add Users to the Group:
sudo usermod -aG deptgroup john
sudo usermod -aG deptgroup jane- Set Default ACLs:
sudo setfacl -d -m g::rwx /department
sudo setfacl -d -m o::rx /department- Verify the Configuration:
ls -ld /departmentgetfacl /departmentAdditional Tips
- Check Effective Permissions:Use the
nameicommand to check the effective permissions of a path.
namei -l /shared/file.txt- Remove Users from the Group:To remove a user from the group:
sudo gpasswd -d user1 collaborators- Change Group Ownership Recursively:To change the group ownership of all files and directories within a directory:
sudo chown -R :collaborators /shared- Set Default ACLs Recursively:To set default ACLs for all existing files and directories within a directory:
sudo setfacl -R -d -m g::rwx /shared
sudo setfacl -R -d -m o::rx /sharedConclusion
Creating and configuring set-GID directories facilitates collaboration by ensuring that files created within the directory inherit the group ownership. This setup is essential for shared environments and is a key competency for the RHCSA exam.
These notes should help you understand how to create and configure set-GID directories for collaboration for the RHCSA exam
05.7 – Diagnose and correct file permission problems
Overview
File permissions in Linux control the access levels for files and directories. Diagnosing and correcting file permission problems is crucial for maintaining system security and functionality. This guide covers common permission issues and how to resolve them.
Understanding File Permissions
Permission Types
- Read (r): Allows reading the contents of a file or listing the contents of a directory.
- Write (w): Allows modifying the contents of a file or adding/removing files in a directory.
- Execute (x): Allows executing a file or accessing a directory.
Permission Representation
Permissions are represented in three sets: owner, group, and others.
- Example:
-rwxr-xr---: File type (e.g.,-for regular file,dfor directory).rwx: Owner permissions.r-x: Group permissions.r--: Others permissions.
Viewing Permissions
Use the ls -l command to view file and directory permissions.
ls -l /path/to/fileSample Output:
-rw-r--r-- 1 user group 1234 Oct 1 12:00 file.txtDiagnosing Permission Problems
Common Permission Issues
- Permission Denied: User does not have the required permissions to access a file or directory.
- Incorrect Group Ownership: User is not part of the group that owns the file or directory.
- Missing Execute Permission: Script or directory cannot be executed or accessed.
Checking Permissions
- Check File Permissions:
ls -l /path/to/file- Check Directory Permissions:
ls -ld /path/to/directory- Check Group Membership:
groups username- Check Effective Permissions:Use the
nameicommand to check the effective permissions of a path.
namei -l /path/to/fileCorrecting Permission Problems
Changing Permissions
Use the chmod command to change file and directory permissions.
Syntax
chmod [options] mode filemode: The new permissions (e.g.,755oru+rwx,g+rx,o+r).
Examples
- Grant Read, Write, and Execute Permissions to the Owner:
chmod u+rwx /path/to/file- Grant Read and Execute Permissions to the Group:
chmod g+rx /path/to/file- Set Permissions Using Numeric Mode:
chmod 755 /path/to/fileChanging Ownership
Use the chown command to change the owner and group of a file or directory.
Syntax
chown [options] owner:group fileExamples
- Change the Owner:
sudo chown user /path/to/file- Change the Group:
sudo chown :group /path/to/file- Change Both Owner and Group:
sudo chown user:group /path/to/fileChanging Group Ownership
Use the chgrp command to change the group ownership of a file or directory.
Syntax
chgrp [options] group fileExample
sudo chgrp group /path/to/filePractical Examples
Example 1: Fixing “Permission Denied” Error
- Diagnose the Problem:
ls -l /path/to/fileSample Output:
-rw-r----- 1 user group 1234 Oct 1 12:00 file.txt- Grant Read Permission to Others:
chmod o+r /path/to/file- Verify the Change:
ls -l /path/to/fileExample 2: Fixing Incorrect Group Ownership
- Diagnose the Problem:
ls -l /path/to/fileSample Output:
-rw-rw-r-- 1 user wronggroup 1234 Oct 1 12:00 file.txt- Change the Group Ownership:
sudo chown :correctgroup /path/to/file- Verify the Change:
ls -l /path/to/fileExample 3: Fixing Missing Execute Permission
- Diagnose the Problem:
ls -l /path/to/script.shSample Output:
-rw-r--r-- 1 user group 1234 Oct 1 12:00 script.sh- Grant Execute Permission to the Owner:
chmod u+x /path/to/script.sh- Verify the Change:
ls -l /path/to/script.shAdditional Tips
- Recursive Permission Changes:Use the
-Roption to change permissions recursively.
sudo chmod -R 755 /path/to/directory- Check Effective Permissions:Use the
nameicommand to check the effective permissions of a path.
namei -l /path/to/file- Use
sudofor Root Privileges:If you encounter permission issues as a regular user, usesudoto execute commands with root privileges.
sudo chmod 755 /path/to/file- Set Default Permissions with
umask:Use theumaskcommand to set default permissions for new files and directories.
umask 022Conclusion
Diagnosing and correcting file permission problems is essential for maintaining system security and functionality. Mastery of these tasks ensures that users have the appropriate access to files and directories, which is crucial for the RHCSA exam.
These notes should help you understand how to diagnose and correct file permission problems for the RHCSA exam.
Discover more from Altgr Blog
Subscribe to get the latest posts sent to your email.
