Changes

Jump to: navigation, search

OPS235 Lab 3

1,024 bytes added, 02:50, 4 August 2020
m
no edit summary
[[Category:OPS235]][[Category:OPS235 Labs]]
 
= LAB PREPARATION =
{| width="40%" align="right" cellpadding="10"
|- valign="top"
|
[[Image:package.png|thumb|right|200px|Learning how to conserve disk space is essential for the efficient operation of a Linux computer system. You will learn how to manipulate the size of Linux file-system sizes (via '''LVM''') in Lab5Lab 5. ]]
|
[[Image:lbreakout2.png|thumb|right|200px|You will download and compile the game called '''lbreakout2''' which is only available as compressed source code. ]]
|}
=== Purpose / Objectives of Lab3Lab 3===
In this lab, you are going to identify potential problems such as running out of space to run a GUI, or forgetting your root password. You will also learn to conserve hard disk space by learning how to compress and decompress files that are stored on your computer server. In addition, you will learn alternative methods of how to install applications (i.e. programs).
<u>Main Objectives</u>
*Learn to boot your Centos CentOS VM into '''Single User mode''' for rescue purposes
*Create and extract '''archive''' files ('''tar''' and '''tar.gz''')
*Install applications using various methods:
|colspan="3" style="font-size:16px;font-weight:bold;border-bottom: thin solid black;border-spacing:0px;padding-left:20px;"|Linux Command Reference<br>
H
|- valign="top"
| style="padding-left:20px;"|Archiving / Compiling
[http://man7.org/linux/man-pages/man1/tar.1.html tar]<br>
[http://unixhelplinuxcommand.ed.ac.ukorg/CGIlc3_man_pages/man-cgi?gzip gzip1.html gzip, gunzip]<br>
[http://man7.org/linux/man-pages/man1/make.1.html make]<br><br>
Software Manangement<br>
[httphttps://wwwlinux.rpmdie.orgnet/man/max-rpm8/rpm.8.html rpm]<br>
[http://man7.org/linux/man-pages/man8/yum.8.html yum]
| style="padding-left:20px;"|Miscellaneous
[http://ss64.com/vi.html vi]
| style="padding-left:20px;"|Matrix On-line Tutorials:<ul><li>Shell Scripting Basics - Part 4 (The sed Utility):<br>'''/home/murray.saulops235/scripting-4'''</li></ul>
|}
 
= INVESTIGATION 1: TROUBLESHOOTING BOOTING &amp; FORGOTTEN ROOT PASSWORD =
#Issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">chroot /sysroot</span></code></b><br><br>
#Issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">passwd root</span></code></b> in order to change your root password (press '''ctrl-c''' if you wish to abort - i.e. not change password).
#To restart in graphical mode, simply enter the command <b><code><span style="color:#3366CC;font-size:1.2em;">exit</span></code></b>, then <b><code><span style="color:#3366CC;font-size:1.2em;">reboot</span></code></b>.
{{Admon/important | What To Do If Reboot Doesn't Work | In this mode, the reboot command may not work. If it doesn't, go to the top of the centos1 VM window, select Send Key -> Ctrl+Alt+Delete.}}
===Catastrophic Boot Problems===
'''Perform the following steps:'''
#Boot up your '''centos3''' VM.H
#Change your working directory to '''/usr/share/doc/sudo*'''
#Use the tar (tape archiver) command to create an archive file named "/tmp/archive1.tar" by issuing the following command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">tar cvf /tmp/archive1.tar .</span></code></b>
#Compare '''/tmp/extract1/README''' and '''/usr/share/doc/sudo*/README'''. Are they exactly the same? Why?
#Create the directory '''/tmp/extract2'''
#Move the file '''archive2.tgztar.gz''' to the '''/tmp/extract2''' directory.#Extract the files from the second archive by issuing the following command: <b><code><span style="color:#3366CC;font-size:1.2em;">tar xvzf /tmp/extract2/archive2.tar.gz</span></code></b>
#Note that this time a separate <b><code><span style="color:#3366CC;font-size:1.2em;">gunzip</span></code></b> command was not needed. Why?
#Repeat the previous command, leaving out the option '''z'''. Does it work? Why?
'''Answer Investigation 2 observations / questions in your lab log book.'''
 
=INVESTIGATION 3: MANAGING SOFTWARE PACKAGES=
'''Perform the following steps:'''
#Make certain that you are in your '''c7host''' VMmachine.
#Issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">yum install elinks</span></code></b>
#Now issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">yum info elinks</span></code></b>
# Verify that the elinks package has been removed. Also verify that the application called: '''xchat''' is not installed.
# Use the wget command to download the xchat rpm binary from the following URL:
::<b><code><span style="color:#3366CC;font-size:1.2em;">http://mirror.centos.org/centos/7/os/x86_64/Packages/xchat-2.8.8-2325.el7.x86_64.rpm</span></code></b><br>
::What do you think is the purpose of the numbers also contained in the filename?
<ol><li value="8">Issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">yum localinstall xchat-2.8.8-2325.el7.x86_64.rpm</span></code></b></li>
<li>Verify that the '''xchat''' command has been installed.</li>
<li>Run the xchat application. What does it say if you run this application as root?</li></ol>
<ol>
<li value="11">We will now look at how we can add different repositories to our '''c7host''' machine.</li><li>As root, issue the following command: <b><code><span style="color:#3366CC;font-size:1.3em;">yum repolist</span></code></b></li><li>Take a few moments to view the contents of the file. Do you see which repositories are used by the '''yum''' command? Write down the repositories in your lab logbook.</li><li>View the following link to see a general listing of repositories:<br>[ [http://wiki.centos.org/AdditionalResources/Repositories Available Repositories for Centos] ].</li><li>To add the epel repository, issue the command:<br><b><code><span style="color:#3366CC;font-size:1.3em;">sudo yum install epel-release</span></code></b></li><li>To verify that you have added the repository, you can issue the command: <b><code><span style="color:#3366CC;font-size:1.3em;">yum repolist</span></code></b></li><li>Unused and unneeded software can present a security risk and ties up disk space needlessly. Find '''at least 4 other packages''' to remove on your c7host machine(for example: '''sound & video''', '''games''', etc) that you're not using on your system. Be careful to ensure that removing those packages does not also remove other software that you do need.</li>
</ol>
===Part 2: Compiling Source Code from a Downloaded Archived File===
Sometimes, some software may <u>not</u> be available on repositories to install with the '''yum''' command. They may be available from web-pages to download, and compile. Now that you know how to create and decompress "zipped tarball archives", we will demonstrate how to install applications from websites containing these types of archives. Although this method is not as "user-friendly" as using the yum command, this method is useful if the application is NOT contained in regular software repositories...
In order to build software from source code, you must have the appropriate software development tools (such as make and gcc) and libraries (such as GTK) installed. The required tools will vary depending on the computer languages used in the software being built.
{| width="40%" align="right" cellpadding="10"
|- valign="top"
|}
===Part 2: Compiling Source Code from a Downloaded Archived File===
Sometimes, some software may <u>not</u> be available on repositories to install with the '''yum''' command. They may be available from web-pages to download, and compile. Now that you know how to create and decompress "zipped tarball archives", we will demonstrate how to install applications from websites containing these types of archives. Although this method is not as "user-friendly" as using the yum command, this method is useful if the application is NOT contained in regular software repositories...
 
In order to build software from source code, you must have the appropriate software development tools (such as make and gcc) and libraries (such as GTK) installed. The required tools will vary depending on the computer languages used in the software being built.
 
'''Perform the following steps:'''
# Remain in your '''c7host''' VM, but make certain that you are logged in as a regular user (i.e. NOT root!).
# Issue the command: <b><code><span style="color:#3366CC;font-size:1.2em;">which lbreakout2</span></code></b><br>Is there a program called '''lbreakout2''' on your system?
# Perform a Netsearch for the pattern: <b><code><span style="color:#3366CC;font-size:1.2em;">lbreakout2 tar.gz</span></code></b>
# Go to an appropriate webpage and download a "zipped tarball" (compressed source code) for the '''lbreakout2''' game (filename should be something like: '''lbreakout2.tar.gz''')
#Change to the directory where you downloaded that file (most likely ''~/Download''s).
# Use the '''tar''' command to compress decompress the "zipped tarball" called something like (not may be exactly): '''lbreakout2.tar.gz'''.
# Change to the directory that contains that ''lbreakout2'' source code.
{| width="40%" align="right" cellpadding="10"
|}
<ol>
<li value="78">Issue the following command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">./configure && make</span></code></b><br>Most likely, you will get an '''ERROR!''' What do you think the error is telling you?<br></li>
<li>Issue the following command to install the files for application development by issuing the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">yum groupinstall "Development Tools"</span></code></b></li>
<li>Issue the command in step 7. You should get another ERROR! What dependency is missing?</li>
<li>Issue the following command to install the library files for SQL by issuing the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">yum install SDL-devel</span></code></b> (possibly <b><code><span style="color:#3366CC;font-size:1.2em;">yum install libpng-devel</span></code></b> and <b><code><span style="color:#3366CC;font-size:1.2em;">yum install zlib-devel</span></code></b> )</li> <li>Reissue the <b><code><span style="color:#3366CC;font-size:1.2em;">./configure && make</span></code></b> command. Where Were you successful?</li> <li>Run the command <b><code><span style="color:#3366CC;font-size:1.2em;">lbreakout2</span></code></b>. Where Were you successful?</li> <li>You need to run a command to make this program available regardless of your current directory(as opposed to running command in the directory that contains the program). Login as root, change (be sure to be in the same directory '''lbreakout''' as the source code after logging in as root) and issue the command:<br><b><code><span style="color:#3366CC;font-size:1.2em;">make install</span></code></b></li> <li>Run the command: <b><code><span style="color:#3366CC;font-size:1.2em;">lbreakout2</span></code></b> . Did it work? Issue the command:<br> <b><code><span style="color:#3366CC;font-size:1.2em;">which lbreakout2</span></code></b>. What do you think that the '''make install''' command could you issue to confirm this game was installed without actually running this programdid?</li>
</ol>
{{Admon/tip|Bash Shell Scripting Tips:|<br>'''<u>The Here Document</u>'''<br><ul><li>A neat little trick involving a special type of redirection of stdin symbol: '''&lt;&lt;''' that allows input to be redirected to a command from within the command.<br><br> </li><li>Examples:<br><br>''cat &lt;&lt;+<br>This is a test message<br>This is the second line<br>+''<br><br>''mail -s "test message" youremailaddr &lt;&lt;+<br>This is a test message<br>I hope you like it.''<br>+<br><br>''tr [a-z] [A-Z] &lt;&lt;+<br>i like ops235<br>i love scripting.<br>+''<br><br></li></ul>'''<u>Using sed to Manipulate Text</u>'''<ul><li>The Linux command '''sed''' stands for <u>'''S'''</u>treaming <u>'''Ed'''</u>itor which is an effective way to manipulate a text file, output sent from a command, or from within a "here document". This command can manipulate matching text on a variety of criteria (such as '''line number(s)''', '''regular expression match''', etc). Commands can then be used for manipulation such as '''omitting''', '''printing''', '''substituting''', '''adding''', and '''inserting''' text.<br><br></li><li>The sed option '''-n''' suppresses display of text so the print ('''p''') command can be used; otherwise, the text will be displayed (with edits via the sed command instructions).<br><br></li><li>Results of text manipulation with sed can be stored in a variable using command substitution, or redirected to a file. '''NEVER redirect the stdout from a sed command to the same input file (or the input file will be destroyed)!''' <br><br></li><li>Examples<br><br>''sed 's/&#124;/ /g' &lt;&lt;+<br>I&#124;like&#124;weekends!<br>+''<br><br>''sed 's/$/\n/g' &lt;&lt;+<br>This text<br>should be<br>double-spaced!''<br>+<br><br></li></ul>}}
|}
 
===Part 3: Generating Sofware Package Information with Shell Scripts===
We will continue with using shell scripts to create a Software Information Report that manipulates output generated by the '''rpm''' command. The '''sed''' and '''awk''' commands are very useful tools in shell scripting to manipulate text. In this lab, we will be using ''sed'' to allow the user to select certain portions from the rpm command (options -qi).
# Use your '''c7host''' VM for this section.
# Open a Bash shell terminal and login as root.
# Use a text editor (such as <b><code><span style="color:#3366CC;font-size:1.2em;">vi</span></code></b> or <b><code><span style="color:#3366CC;font-size:1.2em;">nano</span></code></b>) to create a Bash Shell script called: <b><code><span style="color:#3366CC;font-size:1.2em;">packageInfo.bash</span></code></b> in the '''/root/bin'''s home directory.
# Enter the following text content into your text-editing session:
<code style="color:#3366CC;font-family:courier;font-size:.9em;margin-left:20px;font-weight:bold;">
&#35; Date: *** CURRENT DATE ***<br>
<br>
if [ $HOME PWD != "/root/bin" ] # only runs if logged in as /root/bin directory<br>
then<br>&nbsp;echo "You must be logged in as root." >&2<br>
&nbsp;exit 1<br>
<br>
&#35; Use sed with extended regular expressions to only print those matching report elements<br>
rpm -qi $1 | sed -r -n "/^($processedChoice)/ p" &gt;&gt; /root/package-info.txt<br>
<br>
cat &lt;&lt;+<br>
<ol>
<li value="8">Save, set permissions, and then run that shell script for the application '''gedit'''. Did it create that report? Try running the script without an argument - What did it do? <li>Use the <b><code>wget</code></b> command to download, study, and run the following shell scripts on-line:<blockquote><b><code><span style=" pointer-events:none;cursor:default;color:#3366CC;font-size:1.2em;">https://scsict.senecac.onsenecacollege.ca/~murray.saulops235/labs/packageInfoGraphical.bash</span></code></b></blockquote></li><li>Try to understand what this Bash Shell script does.</li><li>You have completed lab3. Proceed to Completing The Lab, and follow the instructions for "lab sign-off".</li></ol>
'''Answer the Investigation 3 observations / questions in your lab log book.'''
= LAB 3 SIGN-OFF (SHOW INSTRUCTOR) =
===Exclusively for Summer 2020 term, submissions are accepted only online!===
Follow the submission instructions for lab 3 on Blackboard.
{{Admon/important|Time for a new backup!|If you have successfully completed this lab, make a new backup of your virtual machines as well as your host machine.}}
# Switch to your <u>'''c7host'''</u> machine, open a shell terminal, and login as root.
# Change to the directory: '''/root/bin'''
# Issue the Linux command: <b><code><span style="color:#3366CC;font-size:1.2em;">wget httphttps://matrixict.senecac.onsenecacollege.ca/~murray.saulops235/ops235labs/lab3-check.bash</span></code></b>
# Give the '''lab3-check.bash''' file execute permissions (for the file owner).
# Run the shell script and if any warnings, make fixes and re-run shell script until you receive "congratulations" message.
#Arrange proof of the following on the screen:<br><span style="color:green;font-size:1.5em;">&#x2713;</span> '''centos3''' VM:<blockquote><ul><li> Archived files '''created'''</li><li>Archive files '''restored'''</ul></blockquote><span style="color:green;font-size:1.5em;">&#x2713;</span> '''c7host''' Machine:<blockquote><ul><li> '''One repository added''' for yum</li><li>Run the '''lab3-check.bash''' script in front of your instructor (must have all <b><code><span style="color:#66cc00;border:thin solid black;font-size:1.2em;">&nbsp;OK&nbsp;</span></code></b> messages)</li></ul></blockquote><span style="color:green;font-size:1.5em;">&#x2713;</span> '''Lab3''' log-book filled out.
 
= Practice For Quizzes, Tests, Midterm &amp; Final Exam =
[[Category:OPS235]][[Category:OPS235 Labs]][[Category:CentOS 7]][[Category:SSD2]][[Category:Digital Classroom]]

Navigation menu