RHCSA Exam Preparation by Practice

This page is not complete!!!

I do not work more on this page as we expect the release of RHEL 8 based on Fedora 27 very soon.


Module 03, Configure local storage

We will cover all Red Hat objectives for exam EX200 in this module.

  1. List, create, delete partitions on MBR and GPT disks
  2. Create and remove physical volumes, assign physical volumes to volume groups, and create and delete logical volumes
  3. Configure systems to mount file systems at boot by Universally Unique ID (UUID) or label
  4. Add new partitions and logical volumes, and swap to a system non-destructively

Practice Exercise 0

In this exercise we want to examine the filesystem on our host.

  • Use mount command to check which filesystems are mounted now. You may see a mix and match of different file systems: Physical, Logical, NFS and finally pseudo-filesystems. Pseudo-filesystems are kind of fake filesystems that look like filesystems to make your life easier. This allows applications and users to fetch information from and set values in the kernel using regular file-system I/O operation. The most famous one in RHEL 7 is /proc.

You can filter the output like this to get the physical filesystems only:

# mount | grep '^/dev'

Note: /etc/fstab is the configuration file for most physical (and sometimes NFS) filesystems.

# cat /etc/fstab
  • Look at on the first three fields of the /etc/fstab file for now, you see the same three types of entries as you see in the mount command's output.

The 1st field represents the device (device file, uuid or label), the 2nd shows you the mount point (which is a directory the filesystem is mounted at in your FHS) and the 3rd one is the filesystem type.

# mount | grep '^/dev' | grep tmp
/dev/sda5 on /tmp type xfs (rw,nosuid,nodev,relatime,seclabel,attr2,inode64,noquota)
# grep tmp /etc/fstab
UUID=XYZ       /tmp        xfs     defaults,nodev,nosuid       0 0

As you see for the the filesystems that are represented by their labels or uuids, the mount point is shown on the output of the mount command. This is one of the easiest ways that you can identify the physical device corresponding to a label or uuid.

Another way is to check the symlink of the uuid file:

$ ls -l /dev/disk/by-uuid/XYZ
lrwxrwxrwx. 1 root root 10 Apr 19 20:11 /dev/disk/by-uuid/XYZ -> ../../sda6

sda6 represents the 6th partition on the 1st disk drive. Another example might be sdc4 which means 4th partition on the third physical disk drive. You will see vda instead of sda on the RHCSA exam as they use virtual machines and vda represents virtual disk. the same rule applies here so vdb8 meant the 8th partition on the 2nd virtual drive.

You may find some entries in /dev/disk/by-label as well if some devices represented to the system by their labels.

Note: Do not try to cat these files. Just ls -l them to show the symlink. You may see another thing in your fstab file like this:

$ mount | grep '^/dev' | grep tmp
/dev/mapper/VG1-tmp on /tmp type ext4 (rw,relatime,seclabel,data=ordered) 
$ grep tmp /etc/fstab
/dev/mapper/VG1-tmp              /tmp    ext4    defaults      0 0

These are nothing but logical volumes which usually appear in fstab by their names starting with /dev/mapper. This names are also symlinks.

$ ls -l /dev/mapper/VG1-tmp
lrwxrwxrwx. 1 root root 7 Apr 25 20:23 /dev/mapper/VG1-tmp -> ../dm-1

Logical volumes also have uuid but it is recommended not to use uuid for logical volumes.

  • Run ls -l on a physical partition:
$ ls -l /dev/sda[1-5]
brw-rw----. 1 root disk 8, 1 Apr 19 20:11 /dev/sda1
brw-rw----. 1 root disk 8, 2 Apr 19 20:11 /dev/sda2
brw-rw----. 1 root disk 8, 3 Apr 19 20:11 /dev/sda3
brw-rw----. 1 root disk 8, 4 Apr 19 20:11 /dev/sda4
brw-rw----. 1 root disk 8, 5 Apr 19 20:11 /dev/sda5

You see that it does not show the size in the 5th field (check the behavior of ls -l on another file). It shows major device number (8), minor device number (1 to 5 in this case) instead. When accessing a device file, the major number selects which device driver is being called to perform the input/output operation. This call is being done with the minor number as a parameter and it is entirely up to the driver how the minor number is being interpreted. The driver documentation may describe how the driver uses the minor number.

  • Now, go ahead and consult the fstab man page. Take a brief look and find out the meaning of each of the six fields of fstab file.
# man fstab

The 5th field is used by the dump command which is obsolete on lots of Linux distributions. If the filesystem is ext2, ext3 or ext4, the last field is used by fsck to determine the order of filesystem check during boot process. 0 means "do not check", 1 means "this is the root filesystem and check it first please", and 2 means "this entry does not represent root so check it after the root". Also look for the defaults meaning when it appears as a mount option in fstab file. You may find more in mount man page about it.

Then search for MOUNT OPTIONS in the mount man page. Check the meaning of the followings mount options: auto/noauto, dev/nodev, exec/noexec, suid/nosuid, ro/rw.

These are filesystem-independent mount options. Now search forward for ext4 and then xfs to find the ext4-specific and xfs-specific options and read the options very quickly.

  • Examine the size of the root filesystem. You see the free blocks available on it.
$ df /dev/sda2
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda2       73364480 34002980  39361500  47% /

You will get a human-readable output by using -h option:

$ df -h /dev/sda2
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        70G   33G   38G  47% /

Now try to find number of free inodes on it. Consult df man page to find that you have to use -i option for it :)

  • Find the uuid of some of your physical partitions using blkid command or lsblk -f.
  • Compare the mount command output to the contents of /proc/mounts text file as well as the content of /etc/mtab file. Do you see any differences?
  • To check the filesystem type of a partition you can use mount. Can you use df for the same purpose? What if you have an unmounted partition on your system and you want to find the filesystem type without mounting it? Can you Google and find a command to do so?
  • In RHEL 7, systemd governs filesystems as well. in another word systemd reads fstab enteries at boot and converts them to what is called systemd mount units. You can see them easily by running the following command:
# systemctl --type=mount list-units

You see some mount units that came from the information in fstab file:

# systemctl --type=mount list-units
UNIT                          LOAD   ACTIVE SUB     DESCRIPTION
-.mount                       loaded active mounted /
boot-efi.mount                loaded active mounted /boot/efi
tmp.mount                     loaded active mounted /tmp

If you need more info on a single mount unit you can run:

# systemctl status tmp.mount
● tmp.mount - /tmp
   Loaded: loaded (/etc/fstab; disabled; vendor preset: disabled)
   Active: active (mounted) since Wed 2017-04-19 20:11:57 PDT; 6 days ago
    Where: /tmp
     What: /dev/sda6
     Docs: man:fstab(5)
           man:systemd-fstab-generator(8)
  Process: 714 ExecMount=/bin/mount /dev/disk/by-uuid/XYZ /tmp -t xfs -o defaults,nodev,nosuid (code=exited, status=0/SUCCESS)

Practice Exercise 1

The goal of this is to change the filesystem mount point.

  • Create a directory by root at /new/
# mkdir /new
  • Create new disk(s) on your virtual machine. Now you can list it on your Linux box:
# ls /dev/sd*
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdc  /dev/sdd
  • Use fdisk -l to see the detailed results. If you want less information cat the content of /proc/partitions
  • Now go ahead and create a gpt partition on one of those new drives:
# parted /dev/sdc mklabel gpt mkpart P1 ext4 1MiB 1000MiB

Note: If you want to create an MBR partition use msdos instead of gpt. Then it will ask you whether you want a Primary or an Extended partition.

  • Run fdisk -l again. Do you see sdc1 now? Run cat /proc/partitions. Do you see it?
  • Make an ext4 filesystem on it
# mkfs.ext4 /dev/sdc1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
64000 inodes, 255744 blocks
12787 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=262144000
8 block groups
32768 blocks per group, 32768 fragments per group
8000 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
  • And mount it under /new
# mount /dev/sdc1 /new
  • Run mount or df to see if you can see the mount point.
  • Create a directory by root at /new/tmp/ and change its permissions to 1777.
# mkdir /new/tmp
# chmod 1777 /new/tmp
  • Exit as root and using a nonroot user then make a file /new/tmp/bar and place some text on it.
$ echo "test bar 456" > /new/tmp/bar
  • Change your directory to /new/tmp/ and then become root using su not su -
$ cd /new/tmp/
# su 

You should still be in /new/tmp directory because you used su. Now try to unmount /new. You would face an error:

# umount /new
umount: /new: target is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

Because you are inside the directory it shows that the device is busy. You can use lsof or fuser as directed in the error message to see who is using the mount point:

# lsof /new
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
bash    2684 admin  cwd    DIR   8,33     4096   12 /new/tmp
bash    2750  root  cwd    DIR   8,33     4096   12 /new/tmp
bash    2994 admin  cwd    DIR   8,33     4096   12 /new/tmp
bash    3017  root  cwd    DIR   8,33     4096   12 /new/tmp
lsof    3026  root  cwd    DIR   8,33     4096   12 /new/tmp
lsof    3027  root  cwd    DIR   8,33     4096   12 /new/tmp
# fuser -mv /new
                     USER        PID ACCESS COMMAND
/new:                root     kernel mount /new
                     admin      2684 ..c.. bash
                     root       2750 ..c.. bash
                     admin      2994 ..c.. bash
                     root       3017 ..c.. bash

None of those commands were found on my Linux machine as my installation was minimal and corresponding packages were not installed on my test machine. To find which packages are needed run:

# yum whatprovides fuser

And

# yum whatprovides lsof

Then install those packages (if needed).

  • Switch to root again and create a directory by root at /mnt/p1
# mkdir /mnt/p1
  • Switch back to root. Unmount your new device from /new and mount it under /mnt/p1.
# umount /new
# mount /dev/sdc1 /mnt/p1
  • Now check the contents of /new and /mnt/p1. Where is the file bar now? Did you expect it?
  • Let's do some funny thing. Make a file under /new/, put some text on it and test to see it:
# echo "Foo TEST 123" > /new/foo
# cat /new/foo

Now unmount the drive from /mnt/p1 and mount it back under /new.

# umount /mnt/p1
# mount /dev/sdc1 /new

Can you see that your file bar in its original location? What about foo? Where is that?

Practice Exercise 2

For this exercise you will need a non-blank CD or DVD.

  • Log onto the graphical console and check fstab. You should see no line refers to the CD/DVD derive. Now examine the output of mount command and you will see the same thing. That is because removable devices are treated differently. When you insert a removable device the kernel creates the device if needed by getting help from udev.

If you plug a flash drive, another process helps the kernel which is called hald.

  • Open a terminal window and as a nonroot user run the following command:
$ udisksctl monitor
  • Put the CD/DVD inside the CD/DVD drive and close the door. You will see a udisks event. udisksctl will identify the device

mounted as a block-device and shows the mount point for you. The graphical file browser may open a window for you to the device. The device icon should also appear on your desktop.

  • Examine the output of mount and find the mount point and device of the CD/DVD.
  • In a terminal, cd to the mount point and list the contents of the CD/DVD. Then change directory off of the CD/DVD so you can eject it.
  • Eject the removable using the graphical interface by right clicking on the CD icon and selecting eject.

You can see the udisksctl info corresponding to the eject and unmount.

  • Search the web to find how can you eject the CD/DVD by commands. Can you unmount a CD or DVD? Try it.

Practice Exercise 3

In this exercise you need a USB flash drive whose contents you are willing to destroy!

  • Start udisksctl monitor in a terminal window.
  • List the names of the disk devices in your /dev directory.
  • Inset the Flash derive. Check if you can see the file it uses and the mount point it creates in the output of udisksctl then list the disk devices in /dev now to see the newly created device files for the disk and its partition(s). You can check it in /proc/mounts file or by using command mount. If the flash drive is formatted for MS Windows OS (as they usually are), the filesystem type will be vfat or msdos. Go ahead and do the following steps:
  1. cd to the flash drives's mount point. Become root by using su (not su -). Create a file on the device and list its attributes using ls -l.
  2. Change the owner of the file to a nonroot user. What happens?
  3. Change the permissions of the file to 600. Then list the permissions.
  4. Exit root and change you directory back to your home directory.
  • Now we want to reformat the device for Linux. Become root and unmount the flash drive but do not physically remove it. You may run:
# umount /dev/sdb1

Then create an ext3 filesystem on it. You may run:

# mkfs.ext3 /dev/sdb1

It may take a minute or so to create the filesystem on a pen drive. Be patient!

  • When mkfs is finished, type sync, then wait a few seconds and finally remove the drive.
  • Reinsert the device and verify that the filesystem is ext3. How do you do that?
  • Still as root, cd to the mount point of the flash drive and create a file. Verify that chown and chmod commands are now

working. So you just found that chown and chmod might not work on all types of filesystems.

  • cd off the drive's mount point, unmount the device by using umount, wait a few seconds and finally remove it.
  • If you want that your flash drive be recognized again by an MS Windows OS, convert it to a vfat again. Reinsert it and run the following command:
# mkfs -t vfat /dev/sdb1

Note: If you want to transfer your date between two Linux machines using a flash drive, you'd better format it as ext or xfs not vfat. As you understood, vfat file system does not preserve your Linux file attributes like the owner and its permissions. An alternate method is to use a tar archive to transfer your files using a vfat-formatted flash drive. The archive contains the permissions of all files so that you do not have to rely on the filesystem to preserve them.

Practice Exercise 4

In this exercise you will separate out your /opt partition, placing it on a physical partition. Your system might have /opt on the / partition not on a separate disk. We chose /opt as it is not critical for booting.

  • Check the output of mount to determine the devices of your disks. If a partition's device is /dev/sda1, the disk's device is /dev/sda. Now start parted on interactive mode for your disk device. I chose a new disk that I created in my vmaware. In parted prompt print the partition table. You can switch units if you like using the unit command.
# parted /dev/sdc
GNU Parted 3.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number  Start  End  Size  Type  File system  Flags

(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]?
Start? 1MiB
End? 1000MiB
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number  Start   End     Size    Type     File system  Flags
 1      1049kB  1049MB  1048MB  primary

In simple msdos (mbr) partition table, the disk has room only for four primary partitions. The first 3 primary partitions are used as real partitions. If more partitions are needed, the partition table must be extended. They way it works is changing the last primary partition to an extended partition and allocating the rest of the disk to it. Then we can can many logical partition on the that extended partition. If you have a disk with GPT partition table you can have more than 3 primary partitions.

  • Now go ahead and make another primary partition. Assign about 4BG for the size:
(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]?
Start? 1001MiB
End? 5000MiB
  • And finally create an extended partition using all available disk space. Use -1s for the End to show you want it to the last sector of the disk. This syntax is very useful in Parted. Try to keep it mind.
(parted) mkpart
Partition type?  primary/extended? extended
Start? 5001MiB
End? -1s
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number  Start   End     Size    Type      File system  Flags
 1      1049kB  1049MB  1048MB  primary
 2      1050MB  5243MB  4193MB  primary
 3      5244MB  21.5GB  16.2GB  extended               lba
  • Now you can create logical partitions in your extended partition. try to create 5 to 6 logical partitions on your logical drive. You'd better change the unit size first.
(parted) unit MiB
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number  Start    End       Size      Type      File system  Flags
 1      1.00MiB  1000MiB   999MiB    primary
 2      1001MiB  5000MiB   3999MiB   primary
 3      5001MiB  20480MiB  15479MiB  extended               lba
(parted) mkpart
Partition type?  primary/logical? logical
File system type?  [ext2]?
Start? 5002MiB
End? 6000MiB

(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number  Start    End       Size      Type      File system  Flags
 1      1.00MiB  1000MiB   999MiB    primary
 2      1001MiB  5000MiB   3999MiB   primary
 3      5001MiB  20480MiB  15479MiB  extended               lba
 5      5002MiB  6000MiB   998MiB    logical

If your new partition table appears OK, quit parted by typing quit. Otherwise, use rm command in parted prompt to remove your partitions and recreate new one(s).

The physical partition is ready now. Next step would be creating a filesystem ob the new physical partition.

  • Create an ext4 filesystem on it. Then add a label to the partition using e2label command.
  • Create a directory under /mnt by root user:
# mkdir /mnt/newopt
  • Go ahead and mount the partition manually under the directory you created to see if everything is fine or not.
  • Run the df command to see size of new filesystem. You will notice that there is less kiB available than shown by parted or mkfs! This is mostly because of the space that is used for inodes or the journal.
  • Unmount the new filesystem.
  • Rename the /etc/fstab file to /etc/fstab.original. Then copy it back to /etc/fstab and edit it using vi. Do not use nano to edit fstab.
  • Duplicate the line for /boot, editing it for your /opt filesystem to mount the correct filesystem type at /mnt/newopt by using device UUDI not the device name. To find the UUID try to use one (or all of) these commands:
  1. tune2fs -l
  2. blkid device
  3. ls -l /dev/disk/by-uuid
  • Mount the new /opt automatically using mount -a and check the result using df or mount command.
  • Now try to do the same thing using an xfs filesystem:
  1. Unmount the filesystem.
  2. Create an xfs filesystem. use mkfs -t xfs and add -L opt to the mkfs options because you can not use e2label on an xfs. You also need to add the -foption to overwrite an existing filesystem. Then correct your fstab entry and do a test mount by using mount -a.

Now we are near the final step to use the new filesystem as /opt. We have to finish this exercise in in rescue mode where the filesystem is not in-use.

  • Reboot your machine to rescue mode (not emergency mode).
  • Run lsof /opt in order to make sure there are any files open on /opt.
  • Edit /etc/fstab and change the /mnt/newopt directory to /opt now.
  • cd to /opt and copy the contents of /opt to the new directory:
# cp -rv --preserve=all . /mnt/newopt
  • Check the permissions, owner, and group of the current /opt. Change the permissions, owner and group of /mnt/newopt to match /opt. Then remove the /opt directory using rm -r and finally create a new empty /opt directory.
  • Unmount /mnt/opt, then type mount -a to mpunt all entries in fstab. Check /proc/mounts to ensure it is mounted.
  • Restore the SELinux contexts to the new /opt using
# restorecon -R /opt
  • Reboot your system and check that the new filesystem is mounted correctly.

Practice Exercise 5

In this exercise we want to practice using fsck tool. We will also practice unmounting filesystems and investigating who is using them. This exercise assumes you have done the previous practice exercise and separated the /opt filesystem.

  • Change your directory to /boot and try to unmount it. It will fail because it says filesystem is busy.
  • Discover who is using the /boot filesystem
# fuser -mv /boot

You should see your current shell process. Perform the same experiment using

# lsof /boot
  • Change your directory to somewhere else and see the output of lsof again.
  • Unmount /boot now and check the file system using fsck tool. They output will say you to use another tool called xfs_repair.

Note: If you are checking an ext4 filesystem, you should add -f option to check the filesystem (assuming it was unmounted cleanly last time.)

  • Remount /boot.
  • For more interesting output of lsof, run it on the /var filesystem. Can you interpret the output?
  • Try to unmount /var. What do you face?
  • Run fsck on the device of your newly created /opt. Yes. you have to unmount it.
  • Remount /opt when you are finished. Make sure both /boot and /opt are mounted. Then reboot your system and verify everything is OK.

Practice Exercise 6

In this exercise we will create two new traditional partitions, create a new volume group, and two new logical volumes. We will then resize an xfs logical volume while it is in-use.

  • Using parted, create two new partitions: one with the size of about 2 GB , and one with the size one GB.
  • Mark the new partitions as physical volumes for the logical volume manager using pvcreate.
  • Create a new Volume Group using both new physical volumes and name it VGTEST. Then show the status of VG by using vgs command.
  • Create a new LV of size 800MiB from your Volume Group and name it lvtest. Look under /dev/mapper for the name of your logical volume. The name in /dev/mapper would be VGTEST-lvtest.
  • Crete an ext4 file system on it, create a directory under /mnt and mount your newly created LV under it using its UUID or label.
  • Create a second LV of size 500MB (call it lvtest2) and create an xfs on it then mount it under another directory under /mnt.
  • Check the status of your VG using vgs, and of your LV using lvs.
  • Check out the status of your newly created xfs using xfs_info giving it the device file /dev/mapper/VGTEST-lvtest2.
  • Using lvextend, extend the size of your logical.
  • Using xfs_growfs, resize the filesystem to fill the entire LV.
  • Run xfs_info again to see the results.

Note: You can increase the size of an xfs filesystem. However, you cannot decrease its size. This rule does not apply to an ext filesystems. Let's do it:

  • Copy the contents of the /usr/sbin/ to the newly created ext4 filesystem at VGTEST-lvtest.
  • Unmount your newly creted ext4 filesystem. Resize it using resize2fs to 400 MiB.
  • Resize the Resize your logical volume , giving it a size about 410 MiB. Then run resize2fs again in order to fill up the existing LV completely.
  • Check the filesystem using fsck -f. Then mount it and check the data you copied is still there.

Note: You can leave the filesystem mounted while you increase its size (for ext4 and xfs). however, you have to unmount the filesystem to decrease its size.

Let's try to increase the size of a VG and an ext4 filesystem when it is in-use.

Up to 4d page 7

Module 04, Create and configure file systems

  1. Create and configure file systems
  2. Create, mount, unmount, and use vfat, ext4, and xfs file systems
  3. Mount and unmount CIFS and NFS network file systems
  4. Extend existing logical volumes
  5. Create and configure set-GID directories for collaboration
  6. Create and manage Access Control Lists (ACLs)
  7. Diagnose and correct file permission problems