Changes

Jump to: navigation, search

OPS235 Lab 5 - CentOS7

1,756 bytes added, 12:15, 27 November 2019
no edit summary
{{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]]
==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.]]
 The purpose of this lab is to discuss demonstrate how a Linux system administrator can monitor hard disk space availability, and to manage file system size via the Logical Volume Manager (LVM) application. This lab will also demonstrate how to manually mount (i.e. connect) and unmount (disconnect) partitions to file system directories, and demonstrate how to have partitions including adjusting the size of their automatically mounted to directories upon Linux systems if space is requiredsystem startup.
<u>Main Objectives</u>
*[http://www.cyberciti.biz/faq/howto-format-create-linux-filesystem/ mkfs]
*[http://man7.org/linux/man-pages/man5/fstab.5.html /etc/fstab]
*[http://v1code.corenominaltutsplus.orgcom/howtotutorials/scheduling-setuptasks-awith-crontabcron-file/ jobs--net-8800 Using crontab]
|}
</ol>
</li>
<li>Click on '''Logical View''' (i.e. above home, root, swap) and then click '''Create New Logical Volume''' button. What happens? Why do you think this happened?<br><br>We will now create another partition ('''/dev/vda3''') using the '''fdisk''' utility, format this newly-created partition so we can create another logical volume called '''archive'''.<br><br> </li>
<li>Quit the '''system-config-lvm''' application.</li>
<li>In the terminal as root, issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">fdisk ls /dev/vdavd*</span></code></b><br><br>Remember that we are using a Virtual Machine'''NOTE:''' If nothing displays, so issue the hard disk appears as command: '''ls /dev/vdasd*''' and use that device pathname ''' instead of /dev/sda''' 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?</li>
<li>Now issue the commands '''n''' (new partition), '''p''' (primary partition), '''3''' (i.e. next available partition number). When prompted for initial block, '''press enter to accept the default beginning block size''', and '''type: +2G''' at ending block (create 2GB for partition) and '''press enter'''. </li>
<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>You <u>'''must'''</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><span style="color:#3366CC;font-size:1.2em;">mkfs -t ext4 /dev/vda3</span></code></b><br>(or ''mkfs -t ext4 /dev/sda3'')</li>
</ol>
{| width="40%" align="right" cellpadding="10"
|}
<ol>
<li value="2021">'''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:1.2em;">pvcreate /dev/vda3</span></code></b> (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''' (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>Click on Logical View (i.e. above home, root, swap), and then click on '''Create New Logical Volume''' button and fill out the details for this new logical volume including: size: '''1GB''', LV Properties: '''linear''', file system: '''ext4''' file system name: '''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>
'''Answer Part 1 observations / questions in your lab log book.'''
 
===Part 2: Managing LVM Via Command Line & Adding Virtual Hard Drives===
[[Image:add_virtual_disk.png|thumb|400px|right|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, and you need more space on the root file-system, perhaps in order to host more webpages web-pages, or to support 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 or backing up and restoring data on the dataold hard disk.
Because we're using LVM we can avoid this problem. We can '''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.
'''Perform the following operations to increase the size of lv_root in centos3:'''
<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>''' .</li> <li>At the bottom left-hand 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-hand-side.<br><br>'''</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>Use '''fdisk''' (''refer to how to use in Part 1'') to create a new single primary partition for '''/dev/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>
<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;">vgs</span></code></b> (to determine: ''name_of_volumegroup'')
:: <b><code><span style="color:#3366CC;font-size:1.2em;">vgextend ''name_of_volumegroup'' /dev/vdb1</span></code></b>
:: <b><code><span style="color:#3366CC;font-size:1.2em;">lvextend -L +2G -r ''name_of_volumegroup''/lv_root</span></code></b>
<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''/root 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''/root lv_root --size +1G</span></code></b></li>Confirm that the file system can been increased.</li><li>Record the LVM Management commands in your lab log-book.</li>
</ol>
= 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. This was create automatically for the '''/archive''' mount point automatically when we used the system-config-lvm utility in the previous investigation. We need to learn now to do this manually by editing or adding an entry in the ''/etc/fstab'' file. 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 system administrator 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 ==
[[Image:mount.png|thumb|700px|right|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 part in your '''centos2''' VM.# As you may recall in Part 1 of Investigation 1, we created another logical volume called lv_archive '''archive''' using the graphical application '''system-config-lvm'''. This logical volume should be mounted (connected) to our existing file-system (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 lv_archive partition'''/archive''' mount point?
# Confirm that the 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.
# View the contents of the file-system table /etc/fstab by issuing the following 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-system (''/dev/sda3'', type ''ext4'') to '''/archive'''. This was automatically performed for you via the '''system-config-lvm''' utility.
# View and record the fields for the '''/archive''' mount in your lab logbook, and then issue the following command to reconnect or mount '''/archive''':<br><b><code><span style="color:#3366CC;font-size:1.2em;">mount &nbsp; -t ext4 &nbsp; /dev/''name_of_volumegroup'centos_centos2/archive &nbsp; /archive</span></code></b><br><br>'''NOTE:''' If you are having 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 could have also issue issued the command: '''mount -a''' to <u>automatically</u> mount the file-systems contained in the '''/etc/fstab''' file.<br><br>Tip: If you had to do manually configure /etc/fstab (eg. only in text-based mode - centos3), you could have issued the command(as root):<br> <b><code><span style="color:#3366CC;font-size:1.2em;">echo "/dev/centos_centos2/archive /archive ext4 defaults 1 12" >> /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 (i.e. prevent regular users from logging in), but were forced we had to first login in graphically as a regular user, then open a terminal and su into '''to "root", isn''', then t our regular user still logged in so we wouldncan't be able to unmount un-mount the /home, since we are still logged indirectory?! ? 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!).
# 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 +10000k100000k</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).
<br><br>
<ol>
<li value="5">Quickly view the tutorial about the <b>[http://v1code.corenominaltutsplus.orgcom/howtotutorials/scheduling-setuptasks-awith-crontabcron-file/ 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 command to setup a crontab entry for root:<br><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">crontab -e</span></code></b></li><li>Enter the following line in order to run at 6:00 on the first 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)</span></code></b></li><li>'''Save''' the crontab entry.</li><li>Confirm that the entry was properly saved by issuing the following command:<br><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">crontab -l</span></code></b></li></ol>
'''Arrange proof of the following on the screen:'''
<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 virtual hard disk creation</li><li>'''Logical Volume''', '''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>
= Preparing for the = Practice For Quizzes , Tests, Midterm &amp; Final Exam ==
# What is a VG? PV? LV?
# What is the total size of the "main" VG on your system?
# How do you create a an LV?# How do you delete resize 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?

Navigation menu