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.
We will cover all Red Hat objectives for exam EX200 in this module.
In this exercise we want to examine the filesystem on our host.
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/fstabThe 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/fstabUUID=XYZ /tmp xfs defaults,nodev,nosuid 0 0As 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/XYZlrwxrwxrwx. 1 root root 10 Apr 19 20:11 /dev/disk/by-uuid/XYZ -> ../../sda6sda6 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 0These 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-tmplrwxrwxrwx. 1 root root 7 Apr 25 20:23 /dev/mapper/VG1-tmp -> ../dm-1Logical volumes also have uuid but it is recommended not to use uuid for logical volumes.
$ ls -l /dev/sda[1-5]brw-rw----. 1 root disk 8, 1 Apr 19 20:11 /dev/sda1brw-rw----. 1 root disk 8, 2 Apr 19 20:11 /dev/sda2brw-rw----. 1 root disk 8, 3 Apr 19 20:11 /dev/sda3brw-rw----. 1 root disk 8, 4 Apr 19 20:11 /dev/sda4brw-rw----. 1 root disk 8, 5 Apr 19 20:11 /dev/sda5You 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.
# man fstabThe 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.
$ df /dev/sda2Filesystem 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/sda2Filesystem 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 :)
# systemctl --type=mount list-unitsYou see some mount units that came from the information in fstab file:
# systemctl --type=mount list-unitsUNIT LOAD ACTIVE SUB DESCRIPTION-.mount loaded active mounted /boot-efi.mount loaded active mounted /boot/efitmp.mount loaded active mounted /tmpIf 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)The goal of this is to change the filesystem mount point.
# mkdir /new# ls /dev/sd*/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdc /dev/sdd# parted /dev/sdc mklabel gpt mkpart P1 ext4 1MiB 1000MiBNote: 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.
# mkfs.ext4 /dev/sdc1mke2fs 1.42.9 (28-Dec-2013)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks64000 inodes, 255744 blocks12787 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=2621440008 block groups32768 blocks per group, 32768 fragments per group8000 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376Allocating group tables: doneWriting inode tables: doneCreating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: done# mount /dev/sdc1 /new# mkdir /new/tmp# chmod 1777 /new/tmp$ echo "test bar 456" > /new/tmp/bar$ 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 /newumount: /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 /newCOMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEbash 2684 admin cwd DIR 8,33 4096 12 /new/tmpbash 2750 root cwd DIR 8,33 4096 12 /new/tmpbash 2994 admin cwd DIR 8,33 4096 12 /new/tmpbash 3017 root cwd DIR 8,33 4096 12 /new/tmplsof 3026 root cwd DIR 8,33 4096 12 /new/tmplsof 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.. bashNone 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 fuserAnd
# yum whatprovides lsofThen install those packages (if needed).
# mkdir /mnt/p1# umount /new# mount /dev/sdc1 /mnt/p1# echo "Foo TEST 123" > /new/foo# cat /new/fooNow unmount the drive from /mnt/p1 and mount it back under /new.
# umount /mnt/p1# mount /dev/sdc1 /newCan you see that your file bar in its original location? What about foo? Where is that?
For this exercise you will need a non-blank CD or DVD.
If you plug a flash drive, another process helps the kernel which is called hald.
$ udisksctl monitormounted 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.
You can see the udisksctl info corresponding to the eject and unmount.
In this exercise you need a USB flash drive whose contents you are willing to destroy!
# umount /dev/sdb1Then create an ext3 filesystem on it. You may run:
# mkfs.ext3 /dev/sdb1It may take a minute or so to create the filesystem on a pen drive. Be patient!
working. So you just found that chown and chmod might not work on all types of filesystems.
# mkfs -t vfat /dev/sdb1Note: 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.
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.
# parted /dev/sdcGNU Parted 3.1Using /dev/sdcWelcome to GNU Parted! Type 'help' to view a list of commands.(parted) printModel: VMware, VMware Virtual S (scsi)Disk /dev/sdc: 21.5GBSector size (logical/physical): 512B/512BPartition Table: msdosDisk Flags:Number Start End Size Type File system Flags(parted) mkpartPartition type? primary/extended? primaryFile system type? [ext2]?Start? 1MiBEnd? 1000MiB(parted) printModel: VMware, VMware Virtual S (scsi)Disk /dev/sdc: 21.5GBSector size (logical/physical): 512B/512BPartition Table: msdosDisk Flags:Number Start End Size Type File system Flags 1 1049kB 1049MB 1048MB primaryIn 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.
(parted) mkpartPartition type? primary/extended? primaryFile system type? [ext2]?Start? 1001MiBEnd? 5000MiB(parted) mkpartPartition type? primary/extended? extendedStart? 5001MiBEnd? -1s(parted) printModel: VMware, VMware Virtual S (scsi)Disk /dev/sdc: 21.5GBSector size (logical/physical): 512B/512BPartition Table: msdosDisk 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(parted) unit MiB(parted) printModel: VMware, VMware Virtual S (scsi)Disk /dev/sdc: 20480MiBSector size (logical/physical): 512B/512BPartition Table: msdosDisk 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) mkpartPartition type? primary/logical? logicalFile system type? [ext2]?Start? 5002MiBEnd? 6000MiB(parted) printModel: VMware, VMware Virtual S (scsi)Disk /dev/sdc: 20480MiBSector size (logical/physical): 512B/512BPartition Table: msdosDisk 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 logicalIf 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.
# mkdir /mnt/newoptNow 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.
# cp -rv --preserve=all . /mnt/newopt# restorecon -R /optIn 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.
# fuser -mv /bootYou should see your current shell process. Perform the same experiment using
# lsof /bootNote: If you are checking an ext4 filesystem, you should add -f option to check the filesystem (assuming it was unmounted cleanly last time.)
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.
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:
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