Difference between revisions of "OPS235 Lab 5 - CentOS7"

From CDOT Wiki
Jump to: navigation, search
Line 54: Line 54:
 
*[http://tldp.org/HOWTO/Partition/fdisk_partitioning.html fdisk]<br>
 
*[http://tldp.org/HOWTO/Partition/fdisk_partitioning.html fdisk]<br>
 
*[http://www.cyberciti.biz/faq/howto-format-create-linux-filesystem/ mkfs]
 
*[http://www.cyberciti.biz/faq/howto-format-create-linux-filesystem/ mkfs]
 +
*[http://man7.org/linux/man-pages/man5/fstab.5.html /etc/fstab]
  
 
|}
 
|}
Line 174: Line 175:
 
# Issue the '''mount''' command to verify that lv_archive logical volume has been unmounted.
 
# Issue the '''mount''' command to verify that lv_archive logical volume has been unmounted.
 
# Although you might have been successful un-mounting the lv_archive logical volume, can you think of any reasons why you might not be able to un-mount that logical volume?  
 
# Although you might have been successful un-mounting the lv_archive logical volume, can you think of any reasons why you might not be able to un-mount that logical volume?  
# Quickly view the tutorial about the /etc/fstab file to understand the purpose of this file and the major elements contain in this file.
+
# Quickly view the tutorial about the [http://man7.org/linux/man-pages/man5/fstab.5.html /etc/fstab] file to understand the purpose of this file and the major elements contain in this file.
  
 
'''Answer the Part 1 observations / questions in your lab log book.'''
 
'''Answer the Part 1 observations / questions in your lab log book.'''

Revision as of 06:56, 4 May 2015


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

Removable Hard Disk Pack (SATA)
USB key
(for backups)
Lab5 Log Book

My Toolkit (CLI Reference)

LVM Information: LVM Management Miscellaneous

INVESTIGATION 1: MANAGING FILE-SYSTEMS USING LVM

Note.png
VM Backups and Recovery
Most of these investigations will take place in your virtual machines. If you make a significant mistake, your virtual machine may not boot. Remember that you created backups of your virtual machines in Lab 2, and you can restore them if something goes wrong.

Remember: if you did not create backups for all of your VMs, then you don't have any restoration points to fall-back to!

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

The system-config-lvm application allows the Linux administrator to manage LVMs Graphically.
  1. Let's learn to administer (manage) our LVM graphically for our centos2 Virtual Machine.
  2. 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
  1. Open a shell as root and run the command: system-config-lvm
  2. 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.
  3. Determine the current LVM configuration by clicking on the appropriate element and reading the properties in the right-hand panel -- write down the answers:
    1. What are the names and sizes of the Volume Group?
    2. What is the name and size of the Physical Volumes?s
    3. What are the names and sizes of the Logical Volumess?
    4. Is there any space in the VG which is not allocated to a LV?
  4. Perform the following steps in this application to increase the size of the home file-system to 4 GB:
    1. On the left-hand side, click on the Logical Volume containing the home file-system.
    2. Click on Edit Properties.
    3. Change the size to 4 GB and click Ok.
    4. Verify that the home file-system has increased in size.
  5. Create a new 3G LV (LV Properties: linear) containing an ext4 filesystem named: lv_archive and mount it at: /archive
  6. 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:
    1. Issue the following command: cp -R /etc/* /archive
    2. Shrink the size of lv_archive to 1 GB. What happens?
    3. If you could not shrink the size of lv_archive, what do you think is the cause for the problem?


Answer Part 1 observations / questions in your lab log book.


Part 2: Managing LVM Via Command Line & Adding Virtual Hard Drives

You can add virtual hard disks for a VM by changing to the Details section for the VM (as opposed to console), click Add Hardware, fill information in the Add New Virtual Hardware dialog box and clicking Finish.

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:


  1. Perform this Part in your centos3 VM.
  2. Run the following commands and make note of the output:
ls /dev/vd*
pvs
vgs
lvs
df -h
  1. Record the size of the volume group and the amount of free space
  2. Open the centos3 virtual machine Details view.
  3. Go to the hardware details view
  4. Click Add Hardware and add a new storage device of 2GBs, make sure it's a VirtIO disk.
  5. Go back to the console view
  6. Issue the command: ls /dev/vd*, what has changed?
  7. Read the resource [ Partitioning with fdisk ] to learn how to properly create a partition with the fdisk command.
  8. Use fdisk to partition /dev/vdb with a Linux single partition that fills the whole disk.
  9. Check the messages printed when fdisk exits -- you may need to reboot the system in order for the new partition table to take effect.
  10. 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
Note.png
LVM Safeguards When Reducing File System Size
In older versions of LVM, the system administrator had to be careful when reducing the size of Linux file-systems using LVM. This usually required to separate operations:
  • Reducing the file-system to make room (resize2fs)
  • Reduce the logical volume by using the lvreduce command

This used to be performed to prevent a catastrophic loss of data if the logical volume was resize smaller than the available space on the file-system.
The newer LVM commands have "safeguards" to prevent destroying the file-system (thus making the resize2fs command obsolete).
  1. Now rerun the ls /dev/vd* , pvs , vgs , lvs and df -h commands.
  2. Record the size of the volume group and the amount of free space. What has changed and what caused those changes?
  3. Among the changes, note that your root file-system is now 2GB bigger, and you have not even rebooted your machine!
  4. Reduce the size of the lv_root partition by 1GB by issuing the following command:
    lvreduce vg_centos/lv_root --size -1G
  5. Confirm that the file system has been reduced.
  6. Increase the size of the lv_root partition by another 1GB by issuing the command:
    lvextend vg_centos/lv_root --size +1G
  7. <Confirm that the file system can been increased.
  8. Record the LVM Management commands in your lab log-book.


Answer Part 2 observations / questions in your lab log book.


INVESTIGATION 2: ADDITIONAL FILE-SYSTEM OPERATIONS

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).


Part 1: Mounting and Un-mounting Partitions

Using the mount command with no arguments displays file-systems that are already mounted. The Linux system administrator can use the mount and umount commands to connect and disconnect different partitions from the file-system to perform maintenance.
  1. Perform this Part in your centos2 VM.
  2. As you may recall in Part 1 of Investigation 1, we created another logical volume called lv_archive using the graphical application system-config-lvm. This logical volume should be mounted (connected) to our existing file-system (2GB).
  3. Issue the following command: mount
  4. What is the purposed of issuing this command without arguments? Can you see the lv_archive partition?
  5. Create a new directory called /archive.
  6. Issue the following command: mount /dev/vdb -t ext4 /archive
  7. Issue the mount command to verify that the lv_archive logical volume is mounted.
  8. Without changing to the /archive, list the contents of that directory.
  9. Issue the following command: umount /archive
  10. Issue the mount command to verify that lv_archive logical volume has been unmounted.
  11. Although you might have been successful un-mounting the lv_archive logical volume, can you think of any reasons why you might not be able to un-mount that logical volume?
  12. Quickly view the tutorial about the /etc/fstab file to understand the purpose of this file and the major elements contain in this file.

Answer the Part 1 observations / questions in your lab log book.


Part 2: Monitoring Disk Space

Another essential duty of a Linux system administrator is to anticipate problems and take preventative measures to avoid computer system problems before that occur.

Monitoring disk space activity helps provide Linux system administrators information to help take corrective action.

  1. x

Answer the Part 2 observations / questions in your lab log book.


INVESTIGATION 3: LOOKING AHEAD

Automating Routine Tasks (Scheduling The Running of Shell Script Via Crontab)

Idea.png
Bash Shell Scripting Tips:

  • Using awk to Manipulate Text:

    x

  • Scheduling Tasks: crontab:

    x

    </div>

We will now use shell scripting to help automate the task for a Linux adminstrator to create regular user accounts.


  1. Download, study, and run the following shell script. Issue the command:
    wget https://scs.senecac.on.ca/~murray.saul/monitor-disk-space.bash
  2. 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)

Important.png
Time for a new backup!
If you have successfully completed this lab, make a new backup of your virtual machines. Remember to also make a backup of the new second virtual disk drive on centos1 -- you now have two virtual disks on centos1, and therefore two image files, and therefore will need two backup files.

Arrange proof of the following on the screen:

x
x
x
x
x

Preparing for the Quizzes

  1. What is a VG? PV? LV?
  2. What is the total size of the "main" VG on your system?
  3. How do you create a LV?
  4. How do you delete an LV?
  5. How would you add the disk partition /dev/sdb7 to your volume group "main"?
  6. How would you increase the size of the root filesystem by 50 MB?
  7. What is the purpose of /etc/fstab?
Retrieved from "https://wiki.cdot.senecapolytechnic.ca/w/index.php?title=OPS235_Lab_5_-_CentOS7&oldid=110598"