0% found this document useful (0 votes)
99 views21 pages

Linux Chapter 5

Uploaded by

jamespromiii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views21 pages

Linux Chapter 5

Uploaded by

jamespromiii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Book Title: eTextbook: COMPTIA Linux Guide to Linux Certification

Chapter 5. Linux Filesystem Administration


Hands-On Projects

Hands-On Projects
These projects should be completed in the order given. The hands-on projects

presented in this chapter should take a total of three hours to complete. The

requirements for this lab include:

A computer with Fedora 28 installed according to Hands-On Project 2-1

Project 5-1
In this hands-on project, you view and create device files.

Boot your Fedora Linux virtual machine. After your Linux system
1
has loaded, switch to a command-line terminal (tty5) by pressing
Ctrl+Alt+F5. Log in to the terminal using the user name of root

and the password of LINUXrocks!.

At the command prompt, type ls –l /dev/tty6 and press Enter.


2
What device does /dev/tty6 represent? Is this file a block or

character device file? Why? What are the major and minor

numbers for this file?

At the command prompt, type rm –f /dev/tty6 and press Enter.


3
Next, type ls –l /dev/tty6 at the command prompt and press Enter.

Was the file removed successfully?

271
Switch to tty6 by pressing Ctrl+Alt+F6 and attempt to log in to the
4
terminal using the user name of root and the password of

LINUXrocks!. Were you successful?

Switch back to tty5 by pressing Ctrl+Alt+F5, type the command


5
mknod /dev/tty6 c 4 6 at the command prompt, and press Enter.
What did this command do? Next, type ls –l /dev/tty6 at the

command prompt and press Enter. Was the file re-created

successfully?

Switch back to tty6 by pressing Ctrl+Alt+F6 and log in to the


6
terminal using the user name of root and the password of
LINUXrocks!. Why were you successful?

At the command prompt, type ls –l /dev/tty? and press Enter.


7
What is similar about all of these files? Is the major number

different for each file? Is the minor number different for each file?
Why?

At the command prompt, type find /dev and press Enter to list all
8
of the filenames under the /dev directory. Are there many files?

Next, type du –s /dev at the command prompt and press Enter.


How large in kilobytes are all files within the /dev directory? Why?

At the command prompt, type less /proc/devices and press Enter.


9
Which devices and major numbers are present on your system?
What character devices have a major number of 4? How does this

compare with what you observed in Step 2? Press q to exit the less
utility when finished.

Type exit and press Enter to log out of your shell.


10
Project 5-2
In this hands-on project, you practice mounting and viewing removable DVD

media.

Switch to the graphical terminal (tty1) by pressing Ctrl+Alt+F1


1
and log in to the GNOME desktop using your user account and the
password of LINUXrocks!.

In your virtualization software, attach the DVD ISO image for


2
Fedora Linux (Fedora-Workstation-Live-x86_64-28-1.1.iso) to the
DVD drive for the virtual machine. After you have completed this

action, view your Files application. Is there an icon that represents


your Fedora Live Desktop DVD in the left pane? Place your mouse

over this icon to view the mount point directory. Which directory
was your DVD automatically mounted to? Take a few moments to
explore the contents of the DVD within the Files application. When

finished, close the Files application.

Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5.


3
Log in to the terminal using the user name of root and the
password of LINUXrocks!.

At the command prompt, type du -hT and press Enter. Is your


4
Fedora DVD still mounted? What filesystem type is used? What
device file is used? Next, type ls -l /dev/cdrom and press Enter. Is
/dev/cdrom a symbolic link to this device file?

At the command prompt, type umount /dev/cdrom and press


5
Enter to unmount your Fedora DVD. Next, type du -hT and press

Enter to verify that it is no longer mounted.

272
At the command prompt, type cp /etc/hosts /mnt and press Enter.
6
Next, type ls /mnt and press Enter to verify that the /etc/hosts file

was successfully copied to the /mnt directory.

At the command prompt, type mount /dev/cdrom /mnt and press


7
Enter. What warning did you receive? Next, type du -hT and press
Enter to verify that your Fedora DVD is mounted to the /mnt

directory.

At the command prompt, type mount and press Enter and view
8
the output. Next, type cat /etc/mtab and press Enter. Is the output
shown by these commands more verbose than in Step 7?

At the command prompt, type cd /mnt and press Enter. Next, type
9
ls -F and press Enter. Are the contents of the DVD the same as Step
2?

At the command prompt, type umount /mnt and press Enter.


10
What error did you receive? Next, type fuser -u /mnt and press

Enter. Note that you are currently using the /mnt directory, which
prevents unmounting.

At the command prompt, type cd and press Enter to return to


11
your home directory and then type umount /mnt and press Enter

to unmount your Fedora DVD.

At the command prompt, type ls /mnt and press Enter. Is the copy
12
of /etc/hosts available again after the Fedora DVD was unmounted?

Type exit and press Enter to log out of your shell.


13

Project 5-3
In this hands-on project, you work with standard hard disk partitions. You will
first create a hard disk partition using the fdisk utility. Next, you create an ext4
filesystem on the partition and mount it to the directory tree. Finally, you use

the /etc/fstab file to automatically mount the partition at boot time.

Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5


1
and log in to the terminal using the user name of root and the
password of LINUXrocks!.

At the command prompt, type lsblk and press Enter. What block
2
device holds the partitions that you created during Fedora
installation? Also note that you have three partitions under this
block device: the first partition is mounted to the /boot directory,
the second partition is used as Linux swap and the third partition

is mounted to the / directory.

At the command prompt, type fdisk /dev/sda and press Enter. At


3
the fdisk prompt, type m and press Enter to view the various fdisk
commands.

At the fdisk prompt, type p and press Enter to view the partition
4
table on your hard disk. Do the partitions match the output from
Step 2?

At the fdisk prompt, type n and press Enter to create a new


5
partition. Next, type e to select an extended partition and press
Enter. When prompted for the start sector, observe the valid
range within the brackets and press Enter to select the default (the
first available sector). When prompted for the end cylinder,
observe the valid range within the brackets and press Enter to
select the default (the last available sector).

273
At the fdisk prompt, type p and press Enter to view the partition
6
table on your hard disk. How many partitions are present? What
type of partition is /dev/sda4?

At the fdisk prompt, type n and press Enter to create a new


7
partition. Note that logical drive is automatically selected as the
partition type because all available primary partitions have been
used and there is already an extended partition. When prompted
for the start sector, observe the valid range within the brackets
and press Enter to select the default (the first available sector).
When prompted for the end cylinder, type +1GB and press Enter.

At the fdisk prompt, type p and press Enter to view the partition
8
table on your hard disk. How many partitions are present? What
type of partition is /dev/sda5?

At the fdisk prompt, type l and press Enter to view the different
9
partition types. What type is used for Linux swap? Which
character would you type at the fdisk prompt to change the type of
partition?

At the fdisk prompt, type w and press Enter to save the changes to
10
the hard disk and exit the fdisk utility.

At the command prompt, type reboot and press Enter to reboot


11
your machine and ensure that the partition table was read into
memory correctly. After your Linux system has been loaded,
switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5
and log in to the terminal using the user name of root and the
password of LINUXrocks!.

At the command prompt, type mkfs –t ext4 /dev/sda5 and press


12
Enter to format the first logical drive on your first hard disk with
the ext4 filesystem.
At the command prompt, type mkdir /newmount and press Enter
13
to create a mount point directory under the / directory for
mounting the third partition on your first hard disk.

At the command prompt, type mount –t ext4 /dev/sda5


14
/newmount and press Enter to mount the filesystem on your first
logical drive in the extended partition to the /newmount directory.

Next, type the df -hT command and press Enter to verify that the
filesystem was mounted correctly.

At the command prompt, type ls –F /newmount and press Enter.


15
Is the lost+found directory present? Next, type cp /etc/hosts
/newmount at the command prompt and press Enter to copy the
hosts file to the new partition. Verify that the copy was successful
by typing the ls –F /newmount command at the command prompt
again, and press Enter.

At the command prompt, type umount /newmount and press


16
Enter. Next, type the df -hT command and press Enter to verify
that the filesystem was unmounted correctly.

At the command prompt, type vi /etc/fstab and press Enter.


17
Observe the contents of the file. Add a line to the bottom of the file
as shown below:

Save your changes and quit the vi editor.


18

274
At the command prompt, type reboot and press Enter. After your
19
Linux system has been loaded, switch to a command-line terminal
(tty5) by pressing Ctrl+Alt+F5 and log in to the terminal using the
user name of root and the password of LINUXrocks!.
At the command prompt, type mount and press Enter. Is your
20
new filesystem mounted? Why?

At the command prompt, type umount /newmount and press


21
Enter. Next, type the df -hT command to verify that the filesystem
was unmounted correctly.

At the command prompt, type mount -a and press Enter. Next,


22
type the df -hT command and press Enter. Is the third partition on
your hard disk mounted? Why?

Type exit and press Enter to log out of your shell.


23

Project 5-4
In this hands-on project, you create two new partitions using the GNU Parted
utility, and configure the LVM to host an LV using the space within. During this
process, you will learn how to create PVs, VGs, and LVs, as well as add storage

to extend a VG and LV. Finally, you will edit the /etc/fstab file to ensure that
your LV is mounted at boot time.

Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5


1
and log in to the terminal using the user name of root and the
password of LINUXrocks!.

At the command prompt, type parted /dev/sda and press Enter. At


2
the parted prompt, type help and press Enter to view the
available commands.
At the parted prompt, type print and press Enter. Write down the
3
End value for your first logical drive (/dev/sda5):
(A). Next, write down the End value for your

extended partition (/dev/sda4): (B). These

two values represent the start and end of the remainder of the free
space on your virtual hard disk.

At the parted prompt, type mkpart and press Enter to accept the
4
default of logical drive. Press Enter again to accept the default
partition type (Linux ext2). When prompted for the Start of the
new partition, enter the (A) value you recorded in Step 3 and press
Enter. When prompted for the End of the new partition, enter the
(A) value you recorded in Step 3 plus 1GB and press Enter to

create a 1GB partition.

At the parted prompt, type p and press Enter to view the partition
5
table on your hard disk. What type of partition is /dev/sda6? Write
down the End value for your second logical drive (/dev/sda6):
(C).

At the parted prompt, type mkpart and press Enter to accept the
6
default of logical drive. Press Enter again to accept the default
partition type (Linux ext2). When prompted for the Start of the
new partition, enter the (C) value you recorded in Step 5 and press
Enter. When prompted for the End of the new partition, enter the
(C) value you recorded in Step 5 plus 1GB and press Enter to
create another 1GB partition.

At the parted prompt, type quit and press Enter to save the
7
changes to the hard disk and exit the GNU Parted utility.
At the command prompt, type reboot and press Enter to reboot
8
your machine and ensure that the partition table was read into
memory correctly. After your Linux system has been loaded,

switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5


and log in to the terminal using the user name of root and the
password of LINUXrocks!.

275
At the command prompt, type pvcreate /dev/sda6 and press
9
Enter. Next, type pvscan and press Enter to verify the creation of
your PV. Following this, type pvdisplay and press Enter to view
the PE size chosen as well as the total size of the PV.

At the command prompt, type vgcreate vg00 /dev/sda6 and press


10
Enter. Next, type vgscan and press Enter to verify the creation of

your vg00 VG. Following this, type vgdisplay and press Enter to
view the PE size chosen as well as the total size of your VG.

At the command prompt, type lvcreate –L 0.9GB –n newdata vg00


11
and press Enter to create a 0.9GB LV called newdata from the vg00
VG. Why couldn’t you specify a 1GB size for your LV? Next, type
lvscan and press Enter to verify the creation of your LV. Following
this, type lvdisplay and press Enter to view the path to the LV
device file as well as the total size of your LV.

At the command prompt, type mkfs –t ext4 /dev/vg00/newdata


12
and press Enter to format the newdata LV using the ext4

filesystem. Next, type mkdir /newdata and press Enter to create a


mount point for the newdata LV. Following this, type mount
/dev/vg00/newdata /newdata and press Enter to mount the
newdata LV to the /newdata directory.
At the command prompt, type df -hT and press Enter to verify
13
that your LV is mounted via the device mapper. Next, type ls -l
/dev/vg00/newdata and press Enter, noting it is a symbolic link to
a device mapper device file. Following this, type lsblk and press
Enter to note the relationship between your LV and your PV
(/dev/sda6).

At the command prompt, type ls –F /newdata and press Enter. Is


14
there a lost+found directory available? Why?

At the command prompt, type pvcreate /dev/sda7 and press


15
Enter. Next, type pvscan and press Enter to verify the creation of
your PV. Following this, type pvdisplay and press Enter to view
the PE size chosen as well as the total size of the PV.

At the command prompt, type vgextend vg00 /dev/sda7 and press


16
Enter. Next, type vgdisplay and press Enter to view the PE size
chosen as well as note that the total size of your VG reflects both
PVs.

At the command prompt, type lvextend –L +0.9GB -r


17
/dev/vg00/newdata and press Enter to extend your newdata LV by
another 0.9GB. Next, type lvdisplay and press Enter, noting the
size has doubled. Following this, type df -hT and press Enter,
noting the ext4 filesystem was automatically resized to match the
new LV capacity.

At the command prompt, type lsblk and press Enter to note the
18
relationship between your LV and your two PVs (/dev/sda6 and
/dev/sda7).
At the command prompt, type vi /etc/fstab and press Enter. Add
19
the following line to the bottom of the file to ensure that the
newdata LV is mounted at boot time:

276
Save your changes and quit the vi editor.
20

At the command prompt, type reboot and press Enter. After your
21
Linux system has been loaded, switch to a command-line terminal
(tty5) by pressing Ctrl+Alt+F5 and log in to the terminal using the
user name of root and the password of LINUXrocks!.

At the command prompt, type df -hT and press Enter to verify


22
that your LV was automatically mounted at boot time.

Type exit and press Enter to log out of your shell.


23

Project 5-5
In this hands-on project, you view disk usage and check filesystems for errors.

Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5


1
and log in to the terminal using the user name of root and the
password of LINUXrocks!.

At the command prompt, type df -hT and press Enter. What


2
nonvirtual filesystems are displayed? Can you see the swap
partition? Why?
At the command prompt, type dumpe2fs –h /dev/vg00/newdata |
3
more and press Enter. How many inodes are available to this
filesystem? How many inodes are free to be used? Why?

At the command prompt, type fsck /dev/vg00/newdata and press


4
Enter. What error message do you receive and why?

At the command prompt, type umount /newdata and press Enter.


5
Next, type fsck /dev/vg00/newdata and press Enter. How long did
the filesystem check take and why?

At the command prompt, type fsck –f /dev/vg00/newdata and


6
press Enter. How long did the filesystem check take and why?

At the command prompt, type e2fsck –c /dev/vg00/newdata and


7
press Enter. What does this command do?

At the command prompt, type tune2fs –i 0 /dev/vg00/newdata


8
and press Enter to change the interval for forced checks such that
they are avoided. Is this a good idea for the ext4 filesystem? Why?

At the command prompt, type mount /dev/vg00/newdata and


9
press Enter. Next, type the df -hT command and press Enter to
verify that the filesystem was mounted correctly. Why did the
mount command work even though you didn’t specify the mount
point directory?

Type exit and press Enter to log out of your shell.


10

Project 5-6
In this hands-on project, you enable, set, and view disk quotas for the
/newmount filesystem created earlier in Project 5-3.
Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5
1
and log in to the terminal using the user name of root and the
password of LINUXrocks!.

277
At the command prompt, type chmod 777 /newmount to give all
2
users the ability to create files within the /newmount directory.

Switch to tty6 by pressing Ctrl+Alt+F6 and log in to the terminal


3
using the user name of user1 and the password of LINUXrocks!.

At the command prompt, type touch /newmount/samplefile and


4
press Enter to create a file in /newmount that is owned by the user
user1.

Type exit and press Enter to log out of your shell.


5

Switch back to tty5 by pressing Ctrl+Alt+F5 and note that you are
6
still logged in as the root user on this terminal.

At the command prompt, type vi /etc/fstab and press Enter.


7
Observe the options for the /newmount filesystem. Change the line
that mounts /dev/sda5 to the following:

Save your changes and quit the vi editor.


8

Remount the filesystem as read-write by typing the command


9
mount /newmount –o remount,rw and press Enter.
At the command prompt, type quotacheck –mavugf –F vfsv0 and
10
press Enter. Ignore any warnings that appear. What does this
command do? Next, type ls –l /newmount and press Enter. What
are the sizes of the aquota.user and aquota.group files? What are
these files used for?

At the command prompt, type quotaon -avug and press Enter to


11
activate quotas for all partitions that have quota options defined
within /etc/fstab.

At the command prompt, type edquota –u user1 and press Enter.


12
Are there any quota limits applied to the user user1 by default?
Change the value of the soft quota for blocks to 50000 and the
value of the hard quota for blocks to 60000 . Similarly, change the
value of the soft quota for inodes to 300 and the value of the hard
quota for inodes to 400 . How many files and directories can user1
create on this partition? How much space can user1 use in total on
this partition?

Save your changes and quit the vi editor.


13

At the command prompt, type edquota –u -t and press Enter.


14
Change the time limit for users who extend the soft limit to 5 days
for both inodes and blocks.

Save your changes and quit the vi editor.


15

At the command prompt, type repquota /newmount and press


16
Enter. Are the quota changes you made for the user user1 visible?
How many files has user1 stored on this volume so far? What is
the total size of those files (in 1KB blocks) and why?
At the command prompt, type quota –u user1 and press Enter.
17
How do the values compare with those from the previous step?

Type exit and press Enter to log out of your shell.


18

278

Project 5-7
In this hands-on project, you create a new partition using the cfdisk utility,
format and check an XFS filesystem on that partition, as well as mount the
filesystem using a GUID at boot time.

Switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5


1
and log in to the terminal using the user name of root and the
password of LINUXrocks!.

At the command prompt, type cfdisk /dev/sda and press Enter.


2
Highlight the Free space within the cfdisk utility and select New.
Specify a partition size of 2G and press Enter. Note that cfdisk

creates the next logical drive (/dev/sda8) of type Linux (83).

Select Write to save your changes; type yes and press Enter when
3
prompted to confirm. Next, select Quit to save your changes and
exit the cfdisk utility.

At the command prompt, type reboot and press Enter to reboot


4
your machine and ensure that the partition table was read into
memory correctly. After your Linux system has been loaded,
switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5
and log in to the terminal using the user name of root and the
password of LINUXrocks!.
At the command prompt, type mkfs -t xfs /dev/sda8 and press
5
Enter. Next, type mkdir /xfsmount and press Enter to create a
mount point directory for your filesystem. Following this, type
mount /dev/sda8 /xfsmount and press Enter.

At the command prompt, type df -hT and press Enter to verify


6
that your XFS filesystem was mounted successfully. Next, type ls
/xfsmount and press Enter. Why is there no lost+found directory?

At the command prompt, type umount /xfsmount and press


7
Enter. Next, type fsck -f /dev/sda8 and press Enter. Why did you
receive an error? Following this, type xfs_repair /dev/sda8 and
press Enter.

At the command prompt, type blkid and press Enter. Record the
8
UUID of your XFS filesystem (/dev/sda8): .

At the command prompt, type vi /etc/fstab and press Enter. Add


9
the following line to the bottom of the file, where filesystemUUID
is the UUID that you recorded in the previous step:

Save your changes and quit the vi editor.


10

At the command prompt, type reboot and press Enter to reboot


11
your machine and ensure that the partition table was read into
memory correctly. After your Linux system has been loaded,
switch to a command-line terminal (tty5) by pressing Ctrl+Alt+F5
and log in to the terminal using the user name of root and the
password of LINUXrocks!.
At the command prompt, type df -hT and press Enter. Is your XFS
12
filesystem mounted?

Type exit and press Enter to log out of your shell.


13
Book Title: eTextbook: COMPTIA Linux Guide to Linux Certification
Chapter 5. Linux Filesystem Administration
Discovery Exercises

Discovery Exercises
279
1. Answer the following questions regarding your system using the

commands listed in this chapter. For each question, write the

command you used to obtain the answer. If there are multiple


commands that can be used to obtain the answer, list all of the

commands available.

a. What are the total number of inodes in the root filesystem? How

many are currently utilized? How many are available for use?

b. What filesystems are currently mounted on your system?

c. What filesystems are available to be mounted on your system?

d. What filesystems will be automatically mounted at boot time?

2. Power off your virtual machine. Next, use your virtualization

software to add a second 8GB hard disk to your virtual machine that

will be recognized as /dev/sdb. Create two 4GB partitions on this


device.

a. For the first partition, use the appropriate commands to add the
available space to the vg00 VG that you created in Project 5-4,

and extend your newdata LV to use the additional space.

b. For the second partition, create an exFAT filesystem and mount

it to the /exFATdata directory. Modify the /etc/fstab file to mount


the filesystem automatically at boot time by label. Finally,

perform a filesystem check on your new exFAT filesystem.

3. Provided that your virtualization software allows for USB device pass-

through, connect a USB flash memory drive to your system. Use the
appropriate commands to locate the device file used by the device,

mount the filesystem to a directory of your choice, and check the

filesystem for errors. Finally, add a line to /etc/fstab to ensure that the

filesystem can be easily mounted in the future (this line should not
automount the filesystem at boot time).

4. Provided that your virtualization software supports the creation of


NVMe SSDs, attach an NVMe controller and SSD to your virtual

machine and create a partition within the first namespace that is


formatted using XFS. Next, create a mount point directory for it called
/SSD and mount your new filesystem to this directory, ensuring that it

is mounted automatically by UUID at boot time from the appropriate


entry within /etc/fstab. Note that Oracle VirtualBox requires that you
first download and install the Oracle VirtualBox Extension Pack in

order to obtain NVMe support.

5. Use the Internet to gather information on four filesystems compatible


with Linux. For each filesystem, list the situations for which the
filesystem was designed and the key features that the filesystem

provides.

6. You have a Linux system that has a 1000GB SSD, which has a 90GB

partition containing an ext4 filesystem mounted to the / directory and


a 4GB swap partition. Currently, this Linux system is only used by a
few users for storing small files; however, the department manager

wants to upgrade this system and use it to run a database application


that will be used by 100 users. The database application and the
280
associated data will take up over 200GB of hard disk space. In
addition, these 100 users will store their personal files on the hard
disk of the system. Each user must have a maximum of 5GB of storage

space. The department manager has made it very clear that this
system must not exhibit any downtime as a result of hard disk errors.
How much hard disk space will you require, and what partitions

would you need to ensure that the system will perform as needed?
Where would these partitions be mounted? What quotas would you
implement? What commands would you need to run and what

entries to /etc/fstab would you need to create? Justify your answers.

7. You have several filesystems on your hard disk that are mounted to

separate directories on the Linux directory tree. The /dev/sdc6


filesystem was unable to be mounted at boot time. What could have
caused this? What commands could you use to find more information

about the nature of the problem?

You might also like