Difference between revisions of "OPS235 Lab 5 - CentOS7"
Line 122: | Line 122: | ||
::<b><code><span style="color:#3366CC;font-size:1.2em;">df -h</span></code></b> | ::<b><code><span style="color:#3366CC;font-size:1.2em;">df -h</span></code></b> | ||
<ol> | <ol> | ||
− | <li value="3">Open the '''centos3 virtual machine <u>Details</u>''' view.</li> | + | <li value="3">Record the size of the volume group and the amount of free space</li> |
+ | <li>Open the '''centos3 virtual machine <u>Details</u>''' view.</li> | ||
<li>Go to the '''hardware details''' view</li> | <li>Go to the '''hardware details''' view</li> | ||
<li>Click '''Add Hardware''' and add a new storage device of '''2GBs''', make sure it's a '''VirtIO disk'''.</li> | <li>Click '''Add Hardware''' and add a new storage device of '''2GBs''', make sure it's a '''VirtIO disk'''.</li> | ||
<li>Go back to the '''console''' view</li> | <li>Go back to the '''console''' view</li> | ||
<li>Issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">ls /dev/vd*</span></code></b>, what has changed?</li> | <li>Issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">ls /dev/vd*</span></code></b>, what has changed?</li> | ||
− | <li>Now we'll make the new device | + | <li>Read the resource [ [http://tldp.org/HOWTO/Partition/fdisk_partitioning.html Partitioning with fdisk] ] to learn how to properly create a partition with the '''fdisk''' command.</li> |
+ | <li>Use '''fdisk''' to partition '''/dev/vdb''' with a Linux single partition that fills the whole disk.</li> | ||
+ | <li>Check the messages printed when <code>fdisk</code> exits -- you may need to reboot the system in order for the new partition table to take effect. <li>Now we'll make the new device a '''physical volume''', add it to the '''volume group''', and extend '''lv_root''':</li> | ||
</ol> | </ol> | ||
:: <b><code><span style="color:#3366CC;font-size:1.2em;">pvcreate /dev/vdb</span></code></b> | :: <b><code><span style="color:#3366CC;font-size:1.2em;">pvcreate /dev/vdb</span></code></b> | ||
Line 136: | Line 139: | ||
<ol> | <ol> | ||
− | <li value="9">Now rerun the '''ls /dev/vd*''' , '''pvs''' , '''vgs''' , '''lvs''' and '''df -h''' commands. What has changed and what caused those changes?</li> | + | <li value="9">Now rerun the '''ls /dev/vd*''' , '''pvs''' , '''vgs''' , '''lvs''' and '''df -h''' commands.</li> |
− | <li>Among the changes, note that your root file-system is now 2GB bigger | + | <li>Record the size of the volume group and the amount of free space. What has changed and what caused those changes?</li> |
+ | <li>Among the changes, note that your root file-system is now 2GB bigger, and you have not even rebooted your machine!</li> | ||
</ol> | </ol> | ||
Line 150: | Line 154: | ||
# Do the rest of this investigation in the command line. | # Do the rest of this investigation in the command line. | ||
# You should now have both <code>/dev/vda</code> and <code>/dev/vdb</code>. | # You should now have both <code>/dev/vda</code> and <code>/dev/vdb</code>. | ||
− | # | + | # (Hint: use a command that you learned in a previous lab). |
# Read the resource [http://tldp.org/HOWTO/Partition/fdisk_partitioning.html Partitioning with fdisk] to learn how to properly create a partition with the fdisk command. | # Read the resource [http://tldp.org/HOWTO/Partition/fdisk_partitioning.html Partitioning with fdisk] to learn how to properly create a partition with the fdisk command. | ||
# Use fdisk to partition /dev/vdb with a Linux single partition that fills the whole disk. | # Use fdisk to partition /dev/vdb with a Linux single partition that fills the whole disk. |
Revision as of 08:08, 3 May 2015
Contents
LAB PREPARATION
Purpose / Objectives of Lab 5
The purpose of this lab is to discuss how a Linux sys admin can manage partitions including adjusting the size of their Linux systems if space is required.
Main Topics:
- Using LVM to resize partitions graphically and via commands.
- Create, partition and format virtual hard disks to increase the size of a file system.
- Manually Connecting and Disconnecting Directories to existing partitions (mount, umount).
- Monitoring Disk Space (df -h).
- Create a Bash Shell Script to monitor and report low disk size (run periodically in crontab).
Minimum Required Materials
My Toolkit (CLI Reference)
LVM Information: | LVM Management | Miscellaneous |
INVESTIGATION 1: Adjusting File System Sizes with LVM
Monitoring and ensuring adequate space for a Linux file-system is considered to be an important task for a sys admin. An application called LVM is a very useful tool for Linux system adminstrators.
LVM (Logical Volume Management) is used to manage hard disk drives / partitions for Unix/Linux systems. LVM provides more flexibility than just working with hard disks / hard disk partitions. Volume Groups are areas used to define Physical Volumes (i.e. hard disks, disk partitions, or other forms of storage devices). Logical Volumes are then used to relate directories (mount points) to a specific physical volume or for a "range" or "span" of physical volumes.
Therefore, LVM allows more flexibility and growth potential for Linux systems (for example, having Logical volumes span multiple hard disks). CentOS uses LVM by default upon installation. Other Linux distributions may provide the capacity to install LVM, or later install and then use Logical Volume Management.
Part 1: Manage LVM Graphically
- Let's learn to administer (manage) our LVM graphically for our centos2 Virtual Machine.
- CentOS provides a tool called system-config-lvm to graphically administer LVM. Install the system-config-lvm application by issuing the command:
yum install system-config-lvm
- Open a shell as root and run the command:
system-config-lvm
- On the left-hand side, you can click on the Volume Group, Physical Volume and Logical Volumes and view their properties on the on the right-hand side.
- Determine the current LVM configuration by clicking on the appropriate element and reading the properties in the right-hand panel -- write down the answers:
- What are the names and sizes of the Volume Group?
- What is the name and size of the Physical Volumes?s
- What are the names and sizes of the Logical Volumess?
- Is there any space in the VG which is not allocated to a LV?
- Perform the following steps in this application to increase the size of the home file-system to 4 GB:
- On the left-hand side, click on the Logical Volume containing the home file-system.
- Click on Edit Properties.
- Change the size to 4 GB and click Ok.
- Verify that the home file-system has increased in size.
- Create a new 3G LV (LV Properties: linear) containing an ext4 filesystem named: lv_archive and mount it at: /archive
- Let's see what happens when we copy data over to lv_archive, and then reduce the size of lv_archive. Complete the following steps below:
- Issue the following command:
cp -R /etc/* /archive
- Shrink the size of lv_archive to 1 GB. What happens?
- If you could not shrink the size of lv_archive, what do you think is the cause for the problem?
- Issue the following command:
Answer Part 1 observations / questions in your lab log book.
Part 2: Managing LVM Via Command Line
Let's say that you have run out of disk space on your centos3 VM, you need more space on the root file-system, perhaps to host more webpages or a larger database or new software. What are your options? Getting a replacement hard-drive would probably require re-installation of the operating system and backup/restore of the data.
Because we're using LVM we can avoid this problem. We can add a new hard-drive (which will serve as a physical volume) to the volume group, and extend the root logical volume to make use of the new available space.
Perform the following operations to increase the size of lv_root in centos3:
- Perform this Part in your centos3 VM.
- Run the following commands and make note of the output:
ls /dev/vd*
pvs
vgs
lvs
df -h
- Record the size of the volume group and the amount of free space
- Open the centos3 virtual machine Details view.
- Go to the hardware details view
- Click Add Hardware and add a new storage device of 2GBs, make sure it's a VirtIO disk.
- Go back to the console view
- Issue the command:
ls /dev/vd*
, what has changed? - Read the resource [ Partitioning with fdisk ] to learn how to properly create a partition with the fdisk command.
- Use fdisk to partition /dev/vdb with a Linux single partition that fills the whole disk.
- Check the messages printed when
fdisk
exits -- you may need to reboot the system in order for the new partition table to take effect. - Now we'll make the new device a physical volume, add it to the volume group, and extend lv_root:
-
pvcreate /dev/vdb
-
-
vgextend vg_centos3 /dev/vdb
-
-
lvextend -L +2G -r vg_centos3/lv_root
-
- Now rerun the ls /dev/vd* , pvs , vgs , lvs and df -h commands.
- Record the size of the volume group and the amount of free space. What has changed and what caused those changes?
- Among the changes, note that your root file-system is now 2GB bigger, and you have not even rebooted your machine!
!! increase & shrink LV via command line!!
Answer Part 2 observations / questions in your lab log book.
Part 3: Manually Creating, Formatting Partition & Add to an Existing Volume Group
- Add an additional 2 GB virtual disk to your centos1 system, we will use it as an additional physical volume.
- Do the rest of this investigation in the command line.
- You should now have both
/dev/vda
and/dev/vdb
. - (Hint: use a command that you learned in a previous lab).
- Read the resource Partitioning with fdisk to learn how to properly create a partition with the fdisk command.
- Use fdisk to partition /dev/vdb with a Linux single partition that fills the whole disk.
- Check the messages printed when
fdisk
exits -- you may need to reboot the system in order for the new partition table to take effect. - Mark vdb1 as a physical volume usable by LVM.
- Add the new physical volume to the existing volume group.
- Verify that the volume group is larger and has more free space.
Answer Part 3 observations / questions in your lab log book.
INVESTIGATION 2: Mounting / Un-Mounting File-systems & Monitoring Disk Space
We take for granted that a file-system must be mounted (for example the root partition) in order for a Linux system to be usable upon system start-up. The /etc/fstab (file system table) contains entries to mount various file systems automatically upon start-up of the Linux system.
The Linux sys admin also has the ability to manually mount (connect) and un-mount (disconnect) partitions in order to perform maintenance on the file system (for example un-mounting the /home partition to install software and prevent users from logging in during that process).
We will now learn how to perform these operations (including monitoring of disk space usage) in Part 1.
Part 1: Mounting and Un-mounting Partitions
- x
Answer the Part 1 observations / questions in your lab log book.
Part 2: Monitoring Disk Space
- x
Answer the Part 2 observations / questions in your lab log book.
INVESTIGATION 3: LOOKING AHEAD
Automating Routine Tasks (Shell Scripting and Using Crontab)
We will now use shell scripting to help automate the task for a Linux adminstrator to create regular user accounts.
- Download, study, and run the following shell script. Issue the command:
wget https://scs.senecac.on.ca/~murray.saul/monitor-disk-space.bash
- Try to understand what these Bash Shell scripts do, and then run the script as root.
Setup crontab
Answer Investigation 3 observations / questions in your lab log book.
LAB 5 SIGN-OFF (SHOW INSTRUCTOR)
Arrange proof of the following on the screen:
- ✓ x
- ✓ x
- ✓ x
- ✓ x
- ✓ x
Preparing for the Quizzes
- What is a VG? PV? LV?
- What is the total size of the "main" VG on your system?
- How do you create a LV?
- How do you delete an LV?
- How would you add the disk partition /dev/sdb7 to your volume group "main"?
- How would you increase the size of the root filesystem by 50 MB?
- What is the purpose of /etc/fstab?