Changes

Jump to: navigation, search

OPS235 Lab 5 - CentOS7

8,291 bytes added, 12:15, 27 November 2019
no edit summary
=Logical Volume Management and Software Package Management={{Admon/caution|THIS IS AN OLD VERSION OF THE LAB|'''This is an archived version. Do not use this in your OPS235 course.'''}}[[Category:OPS235]]
==Introduction=LAB PREPARATION=
In this lab you're going to==Purpose / Objectives of Lab 5==[[Image:disk-space.png|thumb|right|150px|Monitoring disk space and taking corrective action before problems arise is a critical operation for a system administrator.]]
:* Learn how to add and remove software packages on your different Linux systems.
:* Learn how to properly adjust your various Linux file systems by using and managing LVM both graphically (centos2) as well as command line (centos3).
== Required Materials The purpose of this lab is to demonstrate how a Linux system administrator can monitor hard disk space availability, and to manage file system size via the Logical Volume Manager (Bring LVM) application. This lab will also demonstrate how to All Labsmanually mount (i.e. connect) ==and unmount (disconnect) partitions to file system directories, and demonstrate how to have partitions automatically mounted to directories upon Linux system startup.
* CentOS 6.5 x86_64 Live DVD* CentOS 6.5 x86_64 Installation DVD1* SATA Hard Disk (in removable disk tray)* USB Memory Stick* Lab Logbook<u>Main Objectives</u>
==Prerequisites==:* Using '''LVM''' to '''resize partitions graphically and via command-line'''.:* Create, partition and format '''virtual hard disks''' to increase the size of a file system.:* Manually connect and disconnect directories (mount points) 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''').
* Completion and Instructor "Sign-off" of Lab 2: [[OPS235 Lab 2 - CentOS6]]
==Linux Command Online ReferenceMinimum Required Materials==Each Link below displays online manpages for each command (via [http://linuxmanpages.com/ http://linuxmanpages.com]):{|cellpadding="15" width="40%"
{|width="100%" cellpadding="5"
|'''LVM Information Utilities:'''
|'''LVM Management Utilities:'''
|'''Additional Utilities:'''
|- valign="top"
|
*[http://linuxmanpages.com/man8/vgs.8.php vgs]
*[http://linuxmanpages.com/man8/lvs.8.php lvs]
*[http://linuxmanpages.com/man8/pvs.8.php pvs]
*[http://linuxmanpages.com/man8/vgdisplay.8.php vgdisplay]
*[http://linuxmanpages.com/man8/lvdisplay.8.php lvdisplay]
*[http://linuxmanpages.com/man8/pvdisplay.8.php pvdisplay]
|
*[http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-system-config-lvm.html system-config-lvm] (Tutorial)
*[http://linuxmanpages.com/man8/lvextend.8.php lvextend]
*[http://linuxmanpages.com/man8/resize2fs.8.php resize2fs]
*[http://linuxmanpages.com/man8/lvcreate.8.php lvcreate]
*[http://linuxmanpages.com/man8/lvreduce.8.php lvreduce]
*[http://linuxmanpages.com/man8/pvcreate.8.php pvcreate]
*[http://linuxmanpages.com/man8/vgextend.8.php vgextend]
|
*[http://linuxmanpages.com/man8/mount.8.php mount]
*[http://linuxmanpages.com/man8/umount.8.php umount]
*[http://linuxmanpages.com/man8/yum.8.php yum]
*[http://linuxmanpages.com/man8/rpm.8.php rpm]
|}
|width==Resources on the web==Additional links to tutorials and HOWTOs"10%" | [[Image:'''Please read this page to get an overview of LVM:'''harddrive.png|thumb|left|85px|<br /b>Removable Hard Disk Pack<br /b>:* [[Logical Volume Management]] ('''Note:''' It is recommended to return to this guide as a reference when performing the next several investigationsSATA):* [http://fedoranews.org/alex/tutorial/rpm/ Using the RPM Utility]:* [http://www.centos.org/docs/5/html/yum/ Using the YUM Utility]
|width="10%" |[[Image:ubs-key.png|thumb|left|85px|<b>USB key</b><br>(for backups)]]
|width="10%" |[[Image:log-book.png|thumb|left|70px|<b>Lab5 Log Book</b>]]
=Logical Volume Management (Introduction)=|}
== Check Current LVM Information Prior to Performing Investigations My Toolkit (CLI Reference)==
'''{|width="50%" cellpadding="15"|- valign="top"|width="10%" |<u>LVM''' ('''Logical Volume Management''') is used to manage hard disk drives Information:</u>*[http://man7.org/linux/man-pages/man8/vgs.8.html vgs]<br>*[http://man7.org/linux/man-pages/man8/pvs.8.html pvs]<br>*[http://man7.org/linux/man-pages/man8/lvs.8.html lvs]<br>*[http://man7.org/linux/man-pages/man8/vgdisplay.8.html vgdisplay]<br>*[http:/ partitions for Unix/Linux systemsman7. LVM provides more flexibility than just working with hard disks org/linux/man-pages/man8/ hard disk partitionspvdisplay.8. '''Volume Groups''' are areas used to define '''Physical Volumes''' (ihtml pvdisplay]<br>*[http://man7.eorg/linux/man-pages/man8/lvdisplay. hard disks, disk partitions, or other forms of storage devices)8. '''Logical Volumes''' are then used to relate directories (mount points) to a specific physical volume or for a html lvdisplay]<br>|width="range10%" or |<u>LVM Management</u>*[http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-system-config-lvm.html system-config-lvm]<br>*[http://man7.org/linux/man-pages/man8/lvextend.8.html lvextend]<br>*[http://man7.org/linux/man-pages/man8/lvcreate.8.html lvcreate]<br>*[http://man7.org/linux/man-pages/man8/lvreduce.8.html lvreduce]<br>*[http://man7.org/linux/man-pages/man8/pvcreate.8.html pvcreate]<br>*[http://man7.org/linux/man-pages/man8/vgextend.8.html vgextend]<br>|width="span10%" of physical volumes|<u>Miscellaneous</u>*[http://man7.org/linux/man-pages/man8/mount.8.html mount]<br>*[http://man7.org/linux/man-pages/man8/umount.8.html umount]<br>*[http://man7.org/linux/man-pages/man1/df.1.html df]<br>*[http://man7.org/linux/man-pages/man1/du.1.html du]<br>*[http://www.lehman.cuny.edu/cgi-bin/man-cgi?awk+1 awk]<br>*[http://tldp.org/HOWTO/Partition/fdisk_partitioning.html fdisk]<br>*[http://www.cyberciti.biz/faq/howto-format-create-linux-filesystem/ mkfs]*[http://man7.org/linux/man-pages/man5/fstab.5.html /etc/fstab]*[http://code.tutsplus.com/tutorials/scheduling-tasks-with-cron-jobs--net-8800 Using crontab]
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.|}
'''Although the concept of =INVESTIGATION 1: MANAGING FILE-SYSTEMS USING LVM is simple, it takes practice and preparation (or ={| width="40%" align="right" cellpadding="10"|- valign="thinking aheadtop") |{{Admon/note|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 order to correctly use this valuable toolLab 2, and you can restore them if something goes wrong.<br /><br />'''. It is important Remember: if you did not create backups for students to gain an understanding all of LVMyour VMs, then you don't have any restoration points to fall-back to!'''|}}|}Monitoring and how ensuring adequate space for a Linux file-system is considered to manage their filesystems using be a critical task for any system administrator. An application called '''LVM. It ''' is recommended a very useful tool for students Linux system administrators to read easily manage file systems - even when the following resource prior to this lab and/or return to the following resource while performing this lab: [[Logical Volume Management]]computer system is running!
At this point'''LVM''' ('''Logical Volume Management''') is used to manage hard disk drives / partitions for Linux and Unix systems. LVM provides more flexibility than just partitioning hard disks. '''Volume Groups''' are areas used to define '''Physical Volumes''' (i.e. hard disks, having completed [[OPS235 Lab 2 - CentOS6|Lab 2]] you should have roughly the following disk partitions, or other forms of storage setup: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.
LVM allows more flexibility and growth potential for Linux systems ('''Note:''' These results are output from the '''vgs'''for example, '''pvs''', and '''lvs''' commands that having Logical volumes span multiple hard disks). CentOS uses LVM by default upon installation. Other Linux distributions may provide volume group, physical volume and logical volume information for each of the virtual machines that you created in lab2. Before proceedingcapacity to install LVM, check these values with your own system to see if you are generally "on the right track".)
* '''centos1'''
VG #PV #LV #SN Attr VSize VFree vg_centos1 1 2 0 wz--n- 9.50g 0  PV VG Fmt Attr PSize PFree /dev/vda3 vg_centos1 lvm2 a-- 9.50g 0  LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv_root vg_centos1 -wi-ao 8.03g lv_swap vg_centos1 -wi-ao 1.47g  * '''centos2'''  VG #PV #LV #SN Attr VSize VFree vg_centos2 1 3 0 wz--n- 19.51g 7.77g  PV VG Fmt Attr PSize PFree /dev/vda2 vg_centos2 lvm2 a-- 19.51g 7.77g  LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert lv_home vg_centos2 -wi-ao---- 1.95g lv_root vg_centos2 -wi-ao---- 7.81g lv_swap vg_centos2 -wi-ao---- === Part 1.97g  * '''centos3 (Note: This VM has no GUI installed)''' VG #PV #LV #SN Attr VSize VFree vg_centos3 1 3 0 wz--n- 14.51g 4.54g  PV VG Fmt Attr PSize PFree /dev/vda3 vg_centos3 lvm2 a-- 14.51g 4.54g  LV VG Attr LSize Origin Snap% Move Log Copy% Convert lv_home vg_centos3 -wi-ao---- 1.00g lv_root vg_centos3 -wi-ao---- 8.00g lv_swap vg_centos3 -wi-ao---- 992.00m * '''c6host (i.e. "removable hard disk" or "disk pack")''' Does not use Manage LVM. Confirm this using the same commands used above. {{Admon/note|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.<br /><br />'''Remember: if you did not create backups for all of your VMs, then you don't have any restoration points to fall-back to!'''|}} =Graphically= Investigation 4: Extend the size of lv_root using command-line tools == Perform this investigation in centos3. Let's say that you have run out of disk space on your computer (centos3), you need more space on the root filesystem, perhaps to host more webpages or a larger database or new software. What are your options? Getting a replacement harddrive would probably require reinstallation of the operating system and backup/restore of the data. Because we're using LVM though - we can avoid that. We can add a new harddrive (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:''' <u>'''<font>Steps:</font>'''</u>
[[Image:lvm1.png|thumb|500px|right|The '''system-config-lvm''' application allows the Linux system administrator to manage LVMs Graphically. Your LVM information for '''centos2''' VM should be similarly displayed.]]
# Let's learn to administer (manage) our LVM graphically for our '''centos2''' Virtual Machine.
# Launch your '''centos2''' VM and open a shell terminal.
# CentOS provides a tool called '''system-config-lvm''' to graphically administer LVM.<br><br>'''NOTE:''' This tool may be replaced by a future graphical LVM management tool and is NOT currently available in the default repositories. We will now perform a "work-around" in order to make the system-config-lvm utility work in our system.<br><br>
# Issue the following command to download the system-config-lvm rpm:<br><b><code><span style="color:#3366CC;font-size:1.2em;">wget https://kojipkgs.fedoraproject.org//packages/system-config-lvm/1.1.18/1.fc19/noarch/system-config-lvm-1.1.18-1.fc19.noarch.rpm</span></code></b><br>(Although it is an rpm file for the Fedora Distribution, it will also work for Centos7).<br><br>
# Make certain that you are logged in as '''root'''.
# Try issuing the command: <b><code><span style="color:#3366CC;font-size:1.2em;">rpm -i ./system-config-lvm-1.1.18-1.fc19.noarch.rpm</span></code></b><br>You should notice an error.
# Use the '''yum install''' command to resolve the following dependencies:<ul><li><b><code><span style="color:#3366CC;font-size:1.2em;">yum install gnome-python2-bonobo</span></code></b></li><li><b><code><span style="color:#3366CC;font-size:1.2em;">yum install gnome-python2-gnome</span></code></b></li><li><b><code><span style="color:#3366CC;font-size:1.2em;">yum install usermode-gtk</span></code></b></li></ul><br>
<ol>
<livalue="8">Run Re-issue the following commands and make note of the outputcommand:</lib> <code>ls <span style="color:#3366CC;font-size:1.2em;">rpm -i ./dev/vd* pvs vgs lvs df system-config-lvm-1.1.18-h1.fc19.noarch.rpm</code> <lispan>Open the centos3 virtual machine console</licode> <li>Go to the hardware details view</lib> <libr>Click "Add Hardware" and add a new storage device of 2GBs, make sure it's a VirtIO diskIt should work this time.</li> <li>Go back to the console view</li> <li>Run the same ls command (performed in step 1), what's changed?: </lib> <licode>Now we'll make the new device as a physical volume, add it to the volume group, and extend lv_root<span style="color:#3366CC;font-size:</li1.2em;"> <code>pvcreate /dev/vdb  vgextend vg_centos3 /dev/vdb  lvextend system-L +2G config-r vg_centos3lvm</lv_rootspan></code> <li/b>Now rerun the ls/pvs/vgs/lvs/df commands. What has changed and what caused those changes?</li> <li>Among On the changesleft-hand side, note that your root filesystem is now 2GB bigger - and you have not even rebooted your machine!</li></ol> '''Answer can click on the Investigation 4 observations / questions in your lab log book.''' == Investigation 5: How is LVM managed using system-config-lvm? == Volume Group'''Perform this investigation on the VM named , ''<u>centos2</u>'Physical Volume'.''and '[[Image:Ops235_lab4_1.png|thumb|right|Screenshot of system-config-lvm in CentOS. Click to enlarge.]]# Let's learn to administer (manage) our LVM graphically for our 'Logical Volumes''centos2''' Virtual Machine.<br />CentOS provides a tool called <code>system-configand view their properties on the on the right-lvm</code> to graphically administer LVMhand side. The package is not installed by default, so you will need to install it by issuing: (<code>yum install system-config-lvm</codeli>).<ol> <li value="2">Use this tool to determine Determine the current LVM configuration by clicking on the appropriate element and reading the properties in the right-hand panel -- write down the answers:
<ol type="a">
<li>What are the names and sizes of the '''PVVolume Group'''s?</li> <li>What is the name and size of the '''VGPhysical Volumes'''?</li> <li>What are the names and sizes of the '''LVLogical Volumes'''s?</li> <li>Is there any space in the VG which is not allocated to a LV?<br><br></li>
</ol>
</li>
<li>Increase the size of the Click on '''Logical View''' (i.e. above home file-system to , root, swap) and then click '''4 GBCreate New Logical Volume''': button. What happens? Why do you think this happened?<ol type="a"br> <libr>Click on the LV containing We will now create another partition ('''/dev/vda3''') using the '''homefdisk''' utility, format this newly-created partition so we can create another logical volume called '''archive''' filesystem.<br><br> </li> <li>Click on Quit the '''system-config-lvm'Edit Properties''application.</li> <li>Change In the terminal as root, issue the command: <b><code><span style="color:#3366CC;font-size to :1.2em;">ls /dev/vd*</span></code></b><br><br>'''NOTE:''' If nothing displays, issue the command: '''4 GBls /dev/sd*''' and click use that device pathname '''/dev/sda'Ok''instead.<br><br> <li>Issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">fdisk /dev/vda</span></code></b><br>(or ''fdisk /dev/sda'' if the previous command didn't work)</li> <li>At the fdisk prompt issue the command: '''p'''. What does this do?</olli> <li>Create a Now issue the commands '''n'''(new 3G LVpartition), '''p''' (primary partition), '''3''' (LV Propertiesi.e. next available partition number). When prompted for initial block, '''press enter to accept the default beginning block size''', and '''type: linear+2G''' at ending block (create 2GB for partition) containing an ext4 filesystem named lv_archive and mount it at '''press enter'''. </archiveli> <li>At the fdisk prompt, issue the command '''p''' to review the partition information, then type '''w'''to save partition table and exit (ignore WARNING message).</li> <li>Backup You <codeu>'''/etcmust'''</u> restart your centos2 VM to allow changes to take effect</li> <li>Open a terminal as root, and format your newly-created partition by issuing the command: <b><code> into <span style="color:#3366CC;font-size:1.2em;">mkfs -t ext4 /dev/vda3</span></code></b><br>(or '''mkfs -t ext4 /dev/archivesda3'''</code>)</li>
</ol>
{| width="40%" align="right" cellpadding="10"|- valign="top"|[[Image::* Copy the files in lvm3.png|thumb|right|500px|What '''system-config-lvm''' display should appear after using '''fdisk''' to create new partition (/etc into the filesystem mounted at <code>dev/archive</code><br />(use the graphical tools or the command line. If using cpsda3), '''formatting''' partition, '''adding partition to LVM''', remember and '''allocating partition''' to use the -R option)our default volume group.]]|[[Image:lvm4.png|thumb|right|200px|Creating a new logical volume from our newly created physical volume]]|}
<ol>
<li value="621">Shrink '''Restart the system-config-lvm utility'''. Do you see a new /dev/sda3 partition under Physical Volumes?</li> <li>To add the newly created partition, you need to add it into LVM to be used. '''Exit the system-config-lvm utility''' and '''issue the following command to add the partition into LVM:'''<br><b><code><span style="color:#3366CC;font-size of :1.2em;">pvcreate /dev/vda3</span></code>lv_archive</codeb> (or ''pvcreate /dev/sda3'' ) (enter '''y''' to proceed - ignore warning)</li> <li>'''Restart system-config-lvm'''. You should notice a section at the bottom indicating <u>Unallocated</u> Physical Volumes. Click on the <u>unallocated</u> partition /dev/vda3 and then click '''Add to Existing Volume Group'''1 GB(click on other button in next screen to continue). The screen should now show the partition ''/dev/vda3''contained in our default Volume Group (refer to diagram on right-side for reference).</li> <li>Try shrinking Click on Logical View (i.e. above home, root, swap), and then click on '''Create New Logical Volume''' button and fill out the home details for this new logical volume including: size: '''1GB''', LV Properties: '''linear''', file system: '''ext4''' file-systemname: '''archive''', select '''mount''' and mount it at: '''/archive'''. Have the system create the directory ''/archive'' if it does not exist (Refer to diagram on right for reference).</li> <li>Confirm that this new Logical Volume now exists by changing to the directory /archive. What happens? WhyDid you need to restart your centos2 VM to confirm that the '''/archive''' directory is now on your '''centos2''' VM?</li> <li>Use system-config-lvm to resize (i.e. edit) the '''archive''' logical volume to '''1.5 GB''' and verify your results.</li>
</ol>
'''Answer the Investigation 5 observations / questions in your lab log book.'''
= Storage Setup (prior to starting Lab 4) ='''Answer Part 1 observations / questions in your lab log book.'''
At this point, having completed ===Part 2: Managing LVM Via Command Line & Adding Virtual Hard Drives===[[OPS235 Lab 3 - CentOS6Image:add_virtual_disk.png|thumb|400px|right|Lab 3]] you should have <u>You can add virtual hard disks for a VM by changing to the '''roughlyDetails'''</u> section for the following disk storage setup:<br />VM (as opposed to ''console''), click '''Note:Add Hardware''' These results are output from , fill information in the '''vgsAdd New Virtual Hardware'''dialog box and clicking ', ''Finish'lvs''.]]Let', and s say that you have run out of disk space on your '''pvscentos3''' commands within each virtual machineVM, and you need more space on the root file-system in order to host more web-pages, or to support a larger database. You will be using these commands in What are your options? Getting a replacement hard-drive would probably require re-installation of the following lab investigations)<br operating system and/><br />or backing up and restoring data on the old hard disk.
* Because we're using LVM we can avoid this problem. We can ''centos1'add a new <u>virtual</u> 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. Creating virtual hard drives is not only inexpensive, but a great way for students to learn now to simulate growing the size of the file system.
This VM has a GUI and no free space in '''Perform the following operations to increase the VG. VG #PV #LV #SN Attr VSize VFree vg_centos1 1 2 0 wz--n- 9.80G 0 LV VG Attr LSize size of lv_root vg_centos1 -wi-ao 8.83G lv_swap vg_centos1 -wi-ao 992.00M PV VG Fmt Attr PSize PFree /dev/vda2 vg_centos1 lvm2 a- 9.80G 0in centos3:'''
* '''centos2'''
This # Perform this Part in your '''centos3''' VM has a GUI .# Run the following commands and free space in make note of the VGoutput:::<b><code><span style="color:#3366CC;font-size:1.2em;">ls /dev/vd*</span></code></b> VG ::<b><code><span style="color:#PV #LV #SN Attr VSize VFree vg_centos2 3366CC;font-size:1 4 0 wz--n- 19.51g 4.73g2em;">pvs</span></code></b> LV VG Attr LSize lv_archive vg_centos2 -wi-ao---::<b><code><span style="color:#3366CC;font- size:1.00g 2em;">vgs</span></code></b> lv_home vg_centos2 ::<b><code><span style="color:#3366CC;font-wi-ao---- 4size:1.00g 2em;">lvs</span></code></b> lv_root vg_centos2 ::<b><code><span style="color:#3366CC;font-wisize:1.2em;">df -ao---- 7h</span></code></b><ol> <li value="3">Record the size of the volume group and the amount of free space</li> <li>At the top of your VM window (make certain <u>not</u> full screen mode) click the '''view''' menu and change view from '''Console''' to <u>Details</u>''' .81g </li> lv_swap vg_centos2 <li>At the bottom left-wihand corner, click '''Add Hardware''' and add a new storage device of '''2GBs''', make sure the '''Bus type''' is selected as: '''VirtIO disk'''.<br><br>'''NOTE: Make certain to click "select managed or other existing storage", and fill in the pathname circled in red as shown in the diagram on the right-aohand---- 1side.97g <br><br>'''</li> <li>Go back to the '''console''' view</li> PV VG Fmt Attr PSize PFree<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>Use '''fdisk''' (''refer to how to use in Part 1'') to create a new single primary partition for '''/dev/vda2 vdb''' that fills the entire disk, save partition table (accepting defaults prompts would work), restart your '''centos3''' VM and then '''format''' that partition for file type: '''ext4'''.</li> vg_centos2 lvm2 <li>Now we'll make the new device a'''physical volume''', add it to the '''volume group''', and extend '''lv_root''':</li></ol>:: <b><code><span style="color:#3366CC;font-size:1.2em;">pvcreate /dev/vdb1</span></code></b> (enter '''y''' to proceed - 19.51g 4.73gignore warning)
* :: <b><code><span style="color:#3366CC;font-size:1.2em;">vgs</span></code></b> (to determine: '''centos3'name_of_volumegroup'')
This VM has no GUI installed. VG :: <b><code><span style="color:#PV #LV #SN Attr VSize VFree vg_centos3 2 3 0 wz3366CC;font--n- 16.50g 0 LV VG Attr LSize lv_home vg_centos3 -wi-ao---- size:1.00g lv_root vg_centos3 -wi-ao---- 10.00g lv_swap vg_centos3 -wi-ao---- 992.00m PV VG Fmt Attr PSize PFree2em;">vgextend ''name_of_volumegroup'' /dev/vda3 vg_centos3 lvm2 a-- 14.51g 2.54g vdb1</span></devcode></vdb vg_centos3 lvm2 a-- 2.00g 2.00gb>
* '''c6host (i.e:: <b><code><span style="color:#3366CC;font-size:1. 2em;"disk pack")>lvextend -L +2G -r ''name_of_volumegroup''/lv_root</span></code></b>
/dev{| width="40%" align="right" cellpadding="10"|- valign="top"|{{Admon/sdc3 20G 3note|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.7G 15G 20% This usually required to separate operations:<ul><li>Reducing the file-system to make room (''resize2fs'')</ li><li>Reduce the logical volume by using the '''lvreduce''' command</devli></sdc2 29G 4ul>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.<br>The newer LVM commands have "safeguards" (eg.7G 23G 18% option '''-r''' to prevent destroying the file-system (thus making the ''resize2fs'' command <u>obsolete</homeu>). '''|}} /dev/sdc1 97G 48G 45G 52% /var/lib/libvirt/images|}
<ol> <li value= Logical Volume "13">Now rerun the '''ls /dev/vd*''' , '''pvs''' , '''vgs''' , '''lvs''' and '''df -h''' commands.</li> <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 since you used fdisk to create a partition!</li> <li>Reduce the size of the '''lv_root''' partition by '''1GB''' by issuing the following command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">lvreduce ''name_of_volumegroup''/lv_root --size -1G</span></code></b></li>Confirm that the file system has been reduced.</li><li>Increase the size of the '''lv_root''' partition by another '''1GB''' by issuing the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">lvextend ''name_of_volumegroup''/lv_root --size +1G</span></code></b></li>Confirm that the file system can been increased.</li><li>Record the LVM Management (Continued) =commands in your lab log-book.</li></ol>
{{Admon/note|Recovering VMs|'''Most of these investigations will take place in you 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 3, and you can '''restore them if something goes wrong'''.}}
== Resources =='''Answer Part 2 observations / questions in your lab log book.'''
Please read this page to get an overview of LVM:
[http://zenit.senecac.on.ca/wiki/index.php/Logical_Volume_Management Logical Volume Management]
It is recommended to open another window(eg. '''right= INVESTIGATION 2: ADDITIONAL FILE-click''', '''open in new tab or window''') to make reference to view LVM commands as you perform investigations 1 to 3.SYSTEM OPERATIONS =
== Investigation 1: How are LVMs are managed using CommandWe take for granted that a file-Line Tools ==# You are going to repeat the same LVM management operations system must be mounted (as your did with for example the ''centos2'' VM root partition) in order for a Linux system to be usable upon system start-up. This was create automatically for the '''lab3/archive'''), but you will using commandmount point automatically when we used the system-config-line tools lvm utility in the '''centos3''' VMprevious investigation. Since the centos3 VM only operates in command-line mode, you will We need to refer learn now to do this manually by editing or adding an entry in the ''/etc/fstab'"Logical Volume Management"' file. The ''' link above.# Write down the exact commands used at each step, and record appropriate command output::: a. Determine the current LVM configuration using the <code>pvs</code>, <code>vgs</code>, and <code>lvs</code> commands.:: b.Grow the home filesystem to 2G using the command <code>lvextend</code> and <code>resize2fs</code>.:: c.Create a new 2G LV containing an ext4 filesystem and mount it at /archive (use <code>mkdir</code>, <code>lvcreate</code>, <code>mkfs</code>, <code>mount</code>, edit the file <code>/etc/fstab</code> ''' (read the resource: [https://wiki.archlinux.org/index.php/fstab https://wiki.archlinux.org/index.php/fstab] file system table), and then reboot contains entries to confirm automatic mount).:: d.Copy various file systems automatically upon start-up of the contents of <code>/etc</code> into <code>/archive</code>Linux system.:: e.Shrink <code>lv_archive</code> to 1G (use <code>umount</code>, <code>resize2fs</code>, <code>lvreduce</code>, and <code>mount</code>)
== Investigation 2: How can a PV be added The Linux system administrator also has the ability to an existing VG using Command-Line Tools? ==# Add an additional 2 GB virtual disk to your manually '''mount'<u>centos1</u>'' 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 <code>/dev/vda</code> (connect) and <code>/dev/vdb</code>.# Record the size of the volume group and the amount of free space '''un-mount''' (Hint: use a command that you learned disconnect) partitions 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.# Use fdisk to partition /dev/vdb with a Linux single partition that fills the whole disk.# Check the messages printed when <code>fdisk</code> exits -- you may need order to reboot perform maintenance on the file system in order (for example un-mounting the new partition table to take effect.# Mark ''vdb1'/home''' as a physical volume usable by LVM.# Add the new physical volume partition to the existing volume group.# Verify install software and prevent users from logging in during that the volume group is larger and has more free spaceprocess).
{{Admon/note|Think!|The next part of this investigation requires some research, thought, and creativity.}}
'''Using that additional space, create a separate filesystem for <code>/home</code>:'''
# Create the logical volume <code>lv_home</code> (1G ext4)
# Find a way to move the contents of <code>/home</code> onto it.
# Change your system configuration so that the new filesystem is mounted on <code>/home</code> from now on.
{{Admon/tip== Part 1: Mounting and Un-mounting Partitions ==[[Image:mount.png|thumb|700px|right|SELinux relabelling 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.]]# Perform this part in your '''centos2''' VM.# As you may recall in Part 1 of Investigation 1, we created another logical volume called '''archive''' using the graphical application '''system-config-lvm'''. This logical volume should be required|Your mounted (connected) to our existing file-system may report (2GB).# Issue the following command: <b><code><span style="color:#3366CC;font-size:1.2em;">mount</span></code></b># What is the purposed of issuing this command without arguments? Can you see the '''/archive''' mount point?# Confirm that the files directory named '''/archive''' is mounted.# You can use the '''umount''' command to unmount a file-system (eg. for maintenance purposes). Note the the name of the command is umount, <u>not</u> unmount.# Make certain you are not present located in the new /home filesystem when they are clearly therearchive directory, and issue the following command to unmount the /archive directory:<br><b><code><span style="color:#3366CC;font-size:1. This is due 2em;">umount /archive</span></code></b># Issue the '''mount''' command (without arguments) to confirm it has been unmounted.# View the contents of the file-system table /etc/fstab by issuing the Securityfollowing command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">cat /etc/fstab</span></code></b># Note the line that automatically mounts a file-Enhanced Linux system (SELinux''/dev/sda3'', type ''ext4'') preventing access to '''/archive'''. This was automatically performed for you via the '''system-config-lvm''' utility.# View and record the filesfields for the '''/archive''' mount in your lab logbook, because and then issue the files were tampered with (moved) and following command to reconnect or mount '''/archive''':<br><b><code><span style="color:#3366CC;font-size:1.2em;">mount &nbsp; -t ext4 &nbsp; /dev/centos_centos2/archive &nbsp; /archive</span></code></b><br><br>'''NOTE:''' If you are no longer recognized as home directory contenthaving problem mounting, use the /dev pathname listing in your /etc/fstab file.<br><br># Confirm that this file-system has been properly mounted. Note: You can fix this problem by restoring could have also issued the command: '''mount -a''' to <u>automatically</u> mount the file-systems contained in the '''/etc/fstab''' file context labels so that SELinux accepts .<br><br>Tip: If you had to do manually configure /etc/fstab (eg. only in text-based mode - centos3), you could have issued the files command (as valid home directory contentroot): <br> <b><code>restorecon <span style="color:#3366CC;font-r size:1.2em;">echo "/dev/centos_centos2/archive /homearchive ext4 defaults 1 2" >> /etc/fstab</span></code>}}</b><br>(although we don't need to do this, since it was already done).<br><br># '''A curious question''': If root needs to unmount the '''/home''' directory for maintenance but we had to first login in graphically as a regular user, then su to "root", isn't our regular user still logged in so we can't un-mount the /home directory?!? How can we as a Linux System Administrator get around the problem (hint: you already learned it somewhere in lab3!!! Wow, using what we already taught can pay-off in the future ... lol!).
== Investigation 3: How can I use fdisk to manage storage on my disk pack? ==
'''On your <u>c6host</u> (i.e. "disk pack"), using your choice of the GUI and/or command-line tools:'''
# Create a new partition or logical drive ('''NOT a logical volume!''') - minimum 5G, leaving at least 10G free space in the extended partition.
# Format that partition (i.e. put a filesystem on it).
# Make sure it's mounted automatically on a mountpoint of your choosing (easiest is to create a new directory for a mountpoint).
= Updated backup instructions =
If you completed this '''Answer the Part 1 observations / questions in your lab correctly - please make sure you are still making full backups of your virtual machineslog book.'''
Remember adding a new harddrive to centos3? You will need to back up that drive as well. If you don't - you will only have half of your machine backed up, which is of no use for a recovery.
== Part 2: Monitoring Disk Space ==
[[Image:disk_usage.png|thumb|500px|right|The '''df''' and '''du''' commands are useful tools for Linux system administrators to flag disk space issues and investigate their causes.]]
Another essential duty of a Linux system administrator is to anticipate problems and take preventative measures to avoid computer system problems <u>before</u> that occur.
Monitoring disk space activity helps provide Linux system administrators information to help take corrective action before problems can occur.
# Remain in your '''centos2''' VM for this section.
# Issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">df -h</span></code></b>
# Note the disk space usage for '''/''', '''/home''', and '''/archive''' partitions.
# If a partition is running out of available space, the Linux System Administrator can reallocate space among partitions or add another disk and grow the file system (like you did in a previous investigation). The administrator also can investigate the cause of low disk space. Two examples immediately come to mind: excessive use of space from users, and potential penetration from hackers.
# To investigate excessive disk usage by regular users, you can obtain a total amount of disk usage for that user by issuing the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">du -hs /home/regularuserid</span></code></b>
# To provided a more detailed list of usage (file-by-file), issue the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">du -h /home/regularuserid | more</span></code></b>
# If there is a recurring space usage problem with regular users, the Linux system administrator can impose quotas (caps on disk usage). This method is not taught in this course.
# The methods to monitor potential penetration to a Linux system are too numerous, and are taught in other coures (for example: SEC520). On method of monitoring potential penetration is to look for abnormally large files. Issue the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">find -P / -size +100000k</span></code></b>
# Did you see any files that are that size?
# The next section will apply some of these tools we have discussed into a shell script and crontab entry to periodically monitor and contact the system administrator of potential disk space issues (before they become a serious problem).
==Resources on the web==
Additional links to tutorials and HOWTOs:
* [http://www.centos.org/docs/2/rhl-gsg-en-7.2/s1-zip-tar.html archiving with tar, gzip, gunzip]
* [[init vs systemd]]
* [https://wiki.debian.org/Debate/initsystem/upstart init vs systemd vs upstart]
* [https://www.centos.org/docs/5/html/5.2/Installation_Guide/s2-init-boot-shutdown-rl.html Runlevels]
'''Answer the Part 2 observations / questions in your lab log book.'''
==Managing Run-Levels and System Services==
===Investigation 4INVESTIGATION 3: How do we Manage Runlevels?==LOOKING AHEAD =
==Automating Routine Tasks (Scheduling The Running of Shell Script Via Crontab)=={|width="40%" align="right" cellpadding="10"|- valign="top"|{{Admon/notetip|Use centos2 and centos3Bash Shell Scripting Tips:|Perform these steps <br><ul><li>'''Using awk to Manipulate Text:'''<br><br>Legend has it that the '''awk''' command was invented by three C programmers that wanted to create a utility in both of these virtual machinesUnix that had programming syntax more like C programming. People started to use the command and found it very useful for report generation and file repair or manipulation.<br><br>The command mimics a C program, with braces '''{ }''' that surround the action to perform based on records from a database file matching either test conditions, regular expressions, etc. Fields appear as numbers with $.<br><br>'''<u>Examples</u>:'''<br><br>''awk '{print}' data-file.txt''<br><br>''awk -F";" '{print $5,$3}' data-file.txt''<br><br>''awk -F"," '$4 &gt;&#61; 10000 {print $1, $2}' salary.txt''</li></ul>}}|}
The runlevel command is now deprecated in Fedora, and will likely be deprecated in RHEL/CentOS This emphasis on this section focuses on how to run useful shell scripts or shell script that we have created at some point as well, but for now this is what the industry is using. <ol> <li>Issue the following Linux command: <ul> <li><code>runlevel</code></li> </ul> <specific dates/li> <li>Note the difference in output between centos2 and centos3times.</li> <li>You can use the <code>init</code> command It would be silly to expect a system administrator to change the current runlevelstay up late (eg. See 2 a list of runlevels [https://www.centosm.org/docs/5/html/5.2/Installation_Guide/s2-init) to manually run a shell script to terminate processes or to re-boot-shutdown-rl.html here]Linux servers. Use the <code>man</code> command Database files (tables) are used to learn provide instructions on how frequent shell scripts or commands can be run. The '''cron''' daemon is used to use the <code></code>init command. Use this command refer to change the current runlevel in centos2 these files and to 3. What happened? What happens after your reboot?</li> <li>Change the default runlevel run them on centos2 to 3a pre-determined basis. What happens now after you reboot?</li> <li>Issue The term '''cron''' comes from the following Linux command: <ul> <li><code>startx</code></li> </ul> </li> <li>What happens?</li> <li>Logold word '''chronograph''' meaning a special type of watch (actually a ''stop-off your graphical system. You should return to your shell prompt.</li> <li>Change the default runlevel for centos2 back watch'') to 5 help monitor and reboot to make sure it worksschedule routine tasks.</li></ol>
'''Answer the Investigation 4 observations / questions in your lab log book.'''
=== Investigation 5: How do we Manage System Services? ===
{{Admon/note|Remain #Perform this section in your centos2 VM|Perform these steps '''c7host''' machine#Make certain you are logged in as '''root'''.#Download, study, and run the following shell script. Issue the command:<br><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">wget https://scs.senecac.on.ca/~murray.saul/monitor-disk-space.bash</span></code></b>#Try to understand what this Bash Shell script does (refer to man pages for the '''centos2awk''' virtual machinecommand), and then run the script as root.}}
We have seen that maintaining unneeded '''packages can be a security risk''' due to the unnecessary increase in the complexity of your system. Similarly, it is also unnecessarily hazardous, and even more so, to leave unneeded services running. In this investigation, we will learn how to '''control services, and turn off those services that we think are not necessary to help reduce security risks'''.}}
In order to automatically run the above-mentioned script periodically, you use the scheduler in Linux called '''crontab'''. The term crontab stands for '''Chronograph Tables''', where a chronograph is the old term for a timepiece (the forerunner of the modern watch). You can run the crontab command to schedule commands and shell script to be run in a number of different ways.
<br><br>
<ol>
<li value="5">Quickly view the tutorial about the <b>[http://code.tutsplus.com/tutorials/scheduling-tasks-with-cron-jobs--net-8800 Using crontab]</b> file to understand the purpose of this file and how to basically set up a schedule to run a shell script.</li> <li>Issue the following Linux commandto setup a crontab entry for root: <ulbr> <lib><code>service <span style=" pointer-events:none;cursor:default;color:#3366CC;font-statussize:1.2em;">crontab -alle</codespan></licode> </ulb> </li> <li>Note Enter the following line in order to run at 6:00 on the services that are currently runningfirst day of every month:<br><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">0 6 1 * * /root/monitor-disk-space.bash #Runs first day of each month (6:00 am)</lispan> <li/code>Use the <code/b>service</codeli><li> command to stop the service named '''iptablesSave'''the crontab entry.</li> <li>Issue Confirm that the entry was properly saved by issuing the following command:<codebr>service</codeb> command to verify that this service has stopped.</licode> <lispan style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">If you reboot now crontab - the iptables service will be turned back on. We don't want it on though, it causes students headaches. To turn it off permanently we need to use the chkconfig command: l<code/span>chkconfig iptables off</code></lib> </li>Reboot and confirm that it's no longer running.</liol><'''Answer Investigation 3 observations /ol>questions in your lab log book.'''
= LAB 5 SIGN-OFF (SHOW INSTRUCTOR) ={{Admon/important|Time for a new backup, INCLUDING YOUR VIRTUAL HARD DRIVE!|If you have successfully completed this lab, make a new backup of your virtual machines. <br><br>'''Answer the Investigation 5 observations / questions Virtual hard-drives created in your this lab log book.are image files, and now need to be backed up as well!'''.}}
==Completing '''Arrange proof of the Lab==following on the screen:'''
Arrange evidence for each <ol><li><span style="color:green;font-size:1.5em;">&#x2713;</span> '''centos2''' VM:<blockquote><ul><li>'''Logical Volume''', '''Physical Volume''', and '''Volume Group''' information </li><li>Contents of '''/etc/fstab''' file</li><li>Proof that '''/archive''' has been mounted</li></ul></blockquote><li><span style="color:green;font-size:1.5em;">&#x2713;</span> '''centos3''' VM:<blockquote><ul><li>Proof of these items on your screenvirtual hard disk creation</li><li>'''Logical Volume''', then ask your instructor to check each item'''Physical Volume''', and '''Volume Group''' information </li></ul></blockquote></li><li><span style="color:green;font-size:1.5em;">&#x2713;</span> '''c7host''' Machine:<blockquote><ul><li>Proof of creation of the shell script: '''monitor-disk-space.bash'''</li><li>Crontab entry for '''root''' account</li></ul></blockquote><li><span style="color:green;font-size:1.5em;">&#x2713;</span> '''Lab5''' log-book filled out.</li></ol>
# Compressed files: <code>/tmp/archive1.tar.gz</code> and <code>/tmp/archive2.tgz</code>
#<code>nled</code> application is installed
#Lab5 notes how to use service/chkconfig commands
#VMs backed-up
==Preparing for Practice For Quizzes, Tests, Midterm &amp; Final Exam ==
#What is the advantage of disabling services such as bluetootha VG?#What is the difference between a .tgz file and a .tar.gz filePV? What do these stand forLV?#What is the purpose total size of a repository?#What is source codethe "main" VG on your system?#How do you build software from source codecreate an LV?#Which is preferred: installing from How do resize an RPM file, or installing from source code? WhyLV?#How do would you use <code>serviceadd the disk partition '''/initdev/chkconfig</code> sdb7''' to:your volume group "main"?#*show/set current runlevelHow would you increase the size of the root filesystem by 50 MB?#*list servicesHow can you determine if a partition has been mounted onto a system?#*stop How can you unmount an existing partition from the file-system?# How can you temporarily mount a servicepartition on a file-system?#*start How can you permanently mount a servicepartition on a file-system upon boot-up?#*Why is it important to learn how to manage servicesWhat are the separate elements (fields) of the '''/etc/fstab''' file?#*Why is it important Describe the tools that a Linux system administrator have to stop certain services?monitor disk space usage.
{{Admon/important | Backup your work |Backup your disk images for centos2 and centos3 Virtual Machines.}}[[Category:OPS235]][[Category:OPS235 Labs]]

Navigation menu