During this course you're going to write several shell scripts and learn a lot along the way.
It's really important that you learn the concepts so that you can apply your knowledge on any Linux
distribution or any Unix like or Linux like system.
However when you're learning a new concept I don't want anything to get in your way.
I don't want you to get hung up on little gotchas or get sidetracked by some unimportant detail.
That's the main reason why you're going to use a specific Linux installation that was created for this
course.
Another reason you're going to use the Linux image design for this course is so that you can get help
if everyone in the class were to use a slightly different Linux installation it would be almost impossible
to manage the class if I or the teaching assistants know exactly what system you're using.
We can help you in a very specific way we can even take your script and run it on a system that is the
same as the one you're working on.
This helps us help you.
A third reason to use the Linux installation method I'm about to describe is that it will allow you
to quickly create an entire mini network of Linux systems in the real world you'll end up writing shell
scripts that perform a given task on multiple systems.
This setup allows you to practice those skills and we're going to do that in this class.
OK.
So what does this installation method and lab setup that I've been alluding to for the last couple of
minutes here and what this environment look like.
First it consists of virtualization software that will allow you to run Linux inside a virtual machine
on your local desktop or laptop.
My favorite virtualization software for this purpose is virtual box available for download and Virtual
Box dot org.
First off it's free to download and it's really easy to install.
Secondly it runs on Windows Mac and Linux.
This is a big plus for a course like this as you're going to have the exact same experience no matter
if you're working on a Windows system a Mac system or if you use Linux on your desktop every day.
A little side note here if you're looking for a virtualization solution for running virtual machines
in production for example I'd be looking at something like VM where KTM or overt.
But for our purposes for creating test systems on our local machine and working together in this class
virtual box is the way to go.
Let's get clear on what virtual box does and what virtual machines are virtual box is a full virtualization
product.
Meaning that it allows you to run an unmodified operating system with all of its installed software
in a special environment.
On top of your existing operating system this special environment called a virtual machine is created
by the virtualization software by intercepting access to certain hardware components and certain features
the physical computer is called the host while the virtual machine is called a guest.
Most of the guest code runs unmodified directly on the host computer and the guest operating system
thinks it's running on a real machine.
That last point is important.
The guest operating system thinks it's running on real hardware and it really doesn't know that it's
inside a virtual machine.
If you're doing something inside a virtual machine in the operating system of them virtual machine says
something like performing this action will erase all the data on all your disks.
It's really only referring to the virtual disks that it has access to not your physical device on your
real physical host computer.
You can perform destructive actions inside the virtual machine and those actions are contained inside
of that virtual machine and won't interfere with your actual physical computer.
Virtual Box provides software that can be installed on the guest operating system.
This software is called Virtual Box guest additions.
This software allows the guest operating system to access shared folders on the host system share the
clipboard and some other similar actions.
This is not required but it can be very useful.
The virtual machine you'll be deploying in this course will already have the guest addition software
installed in them.
I just wanted to mention the guest edition so that you're aware of them and know what they do manually
creating virtual machines with virtual boxes fairly easy and straightforward.
By the way we are not going to be manually creating machines in this course.
I just want to show you the process so that you can do this on your own later or so that you know exactly
what is happening behind the scenes when we automate this.
So first you start the virtual box application and next you click on new to create a new virtual machine.
From there you would give it a name virtual box a bit about the operating system that you'll be installing
inside of the virtual machine and allocate some resources such as memory and disk space to the virtual
machine.
When you create a virtual desk for the virtual machine you can make it dynamically allocated a virtual
disk is simply a file on the host system.
When you choose to dynamically allocate that disk it will only use space on your physical disk as that
space is used inside the virtual machine I guess this means that the disk file will grow as needed.
The upside is that the virtual machine thinks it's getting a large disk such as 100 gigabyte or 200
gigabyte.
But if it only uses one gigabyte then only one gigabyte of space is used on your physical hard drive
the price you pay for this dynamic allocation is performance inside the virtual machine.
But for our purposes this is totally acceptable.
Once you've allocated resources to the virtual machine it's ready to be used.
And the first time you started up it will ask you to attach a disk to boot from.
Typically what you'll do is download a Linux ISO from your favorite distribution's Web site and then
tell virtual box to use that ISO to boot the system with.
Alternatively you can actually put a physical CD or DVD in your computer and tell virtual box to use
that physical drive for the install.
Now you install the OS in the virtual machine just like you would as if you were installing that OS
on real physical hardware.
This process is all well and good but as you can probably guess it can be a bit time consuming.
Going through the virtual machine creation process and manually performing the operating system installation
each time you want to create a new virtual machine we're looking to automate this process and save us
a lot of time doing that tedious work to do that we'll use a command line tool called vagrant which
is available to download for free from vagrant up Tom.
This command line tool works on Mac Windows and Linux so no matter what OS you're using for this course
you'll be covered.
Vagrant provides easy to configure reproduceable and portable work environments by default vagrant previsions
virtual machines using Virtual Box.
It can be configured to deploy virtual machines to VM where eight of us Rackspace and other providers.
But for this course we're sticking to creating virtual machines inside a virtual box running on our
local systems.
You're going to use vagrant to quickly and easily spin up virtual machines running Linux.
Let's talk about what you should know and understand about vagrant before you start using it.
A box invigorates speak is an operating system image.
The vagrant box ad command will download and store that box on your local system.
You only need to download a box once as this image will be cloned.
When you create a new virtual machine with vagrant using the boxes name the typical format of this command
is vagrant box.
Add user Ford slash box.
I have a user account on vagrants public box catalog system my user name is Jason C..
I created a box specifically for this course named Sentosa 7.
It's really just a minimal Sentosa install so to demo that box you had run.
Vagrant box and Jason see Ford slash Sentosa 7.
There are several boxes that are publicly available on vagrants public box catalog system.
I have a link in the exercise instructions where you can download other boxes if you'd like to experiment
with them on your own time.
In addition to boxes vagrant uses the concept of projects a vagrant project must consist of a folder
and a vagrant configuration file called a vagrant file.
So to create a new vagrant project first create a folder.
For example I would open up a command prompt on Windows or a terminal on Linux or Mac and then type
the command make DJR space VM one.
From there you would change into that directory with CVM one.
Now you need to initialize your vagrant project which means creating a vagrant configuration file his
configuration file is named vagrant file and it contains the box name to use for the project and any
other configuration options for the virtual machine or virtual machines to create to create the vigor
and file run the vagrant init command.
So continuing with our previous example here you would run vagrant a net.
Jason C forward slash Cinto 7.
Now you can bring up an instance of that box by running vagrant.
Up the first time you run the vagrant up command vagrant will import or clone that vagrant box into
virtual box and then start it.
If vagrant detects that the virtual machine already exists in virtual box it will just simply start
it by default when the virtual machine is started.
It is started in headless mode meaning that there is no user interface for the machine visible on your
local host machine.
Since this class is focused on shell scripting will be working at the command line so we really don't
care about looking at the Linux desktop anyway.
Now if you look at the virtual box application you'll see that you'll have a new virtual machine that's
running it's name starts with the name of the vagrant project which is the name of the director you
created where the vagrant file lives.
As I mentioned earlier you are going to be creating multiple virtual machines you can actually specify
those additional virtual machines in the same vagrant file.
This is called a multi machine setup by vagrant by default when you run the vagrant up command it brings
up all the virtual machines defined in the vagrant file.
If you only want to operate on a single virtual machine you have to supply the virtual machines name.
For example if you defined a VM named M..
You can bring it up with a vagrant a master command.
Likewise if you had a VM defined with the name of server wan you would bring it up with vagrant up server
one and I want to repeat that if you just Rannveig went up it would bring up both of those that word
of find be caused by a fault.
It brings up every system that's defined in the vagrant file for that vagrant project.
SH secure shell is the network protocol used to connect to Linux systems vigor it provides a nice shortcut
to S-sh into the virtual machines.
If you only have one virtual machine defined in the bigger file you can simply run vagrant S-sh and
emet the VM name and you'll be automatically logged into that one VM Linux system that you've created
with vagrant.
If you have multiple machines defined you'll need to supply the specific VM name for example vagrant
S-sh master to log out of a Linux system simply type exit and hit enter.
A quick note for you Windows users Windows doesn't currently ship with an S-sh client so you'll need
to install one.
And what I recommend doing is installing.
Get that CGI tty from get dash SBM dot com which includes an S S H client.
When you work on the exercise I'll give you specific instructions on how to get this configured but
for you Mac and Linux users you can just skip this step as you already have an S-sh client built in
by default.
Ok back to vagrant vagrant can be used to control the virtual machines it creates.
For example the vagrant halt command shuts down all the virtual machines defined in the vagrant file.
If you have multiple victims to find and only want the whole one just specify the VM name when you run
this command you will not lose any work you've performed inside the virtual machine.
That's because the virtual machine will still exist in virtual box but it will just simply be halted
or stop to restart all the defined VM for the project run.
Vagrant up since the virtual machines already exist a vagrant Upal simply start them and it will skip
the import process because it's not needed.
By the way I'm pretty sure you see a pattern here with all these commands if you don't specify a VM
name the command will operate on all the VM defined in the vagrant file for the project.
If you want to limit that operation to a specific VM then you need to supply that name of the VM that
you want to operate on.
So going forward I'm just going to assume that you understand this concept and not point it out for
each and every command.
If you want to suspend the virtual machine run vagrant suspend to resume it run vagrant resume.
If you're done with a virtual machine or you want to start over with a fresh copy of the virtual machine
virtual machines run vagrant destroy.
This will terminate and remove the virtual machine or virtual machines from Virtual Box.
If you run this command then any work inside of the virtual machine will be lost.
If you need help or forget some of the commands you can just run the vagrant command itself without
any options.
Also keep in mind that the vagrant command will act on the virtual machine or virtual machines associated
with a vagrant project directory that you're in during this course she'll be creating multiple vagrant
projects so be sure that you're in the desired vagrant project directory before running any vagrant
command.
Before we wrap up talking about vagrant Let's take a quick look at the vagrant file.
All the vigor configuration occurs after the vagrant Dom configure line and before the end keyword the
two in parentheses.
Here is the configuration version.
Older style configurations are supported but will be used in version 2.
So this is what you'll see in the vagrant file you'll be working with.
The simplest of vagrant file just specifies the name of the box you'll use to create the default VM.
If you want vagrant to set the hostname inside the virtual machine you can use config dot VM dot hostname
to assign a static IP address to the virtual machine.
Use a config VM dot network line.
The example on your screen will assign the IP address of 1:50 3.4 to the virtual machine on a private
network that can only be accessed from the host machine or other vagrant VM.
On that same network you'll be using this vagrant feature to create an entire network of Linux systems
that can communicate with each other.
Each box ships with a set of defaults like whether or not to star in headless mode or how much memory
to allocate to the virtual machine and so on.
You can override these default settings by using a config that VM up provider block.
The example here on the screen will force the virtual machine to start with a gooey graphical user interface
and use 1024 megabytes which is of course one gigabyte of memory.
Vagrant has a provisioning system built in it.
Pre-vis winners and vagrant allow you to automatically install software alter configurations and more
on the machine as part of the vagrant process because we're focusing on shell scripting in this course.
We'll use the show provision.
You won't be using a provision or all the time but we will do this at some point during the course.
This is where you can write a post installation shell script to configure a new system for example.
Vigor will execute the shell script that you specify the first time vagrant upas executed.
The example here on your screen will upload the setup that sh shell script into the virtual machine
and then execute it from there.
This way you can automate and reproduce entire environments quickly if you want to make sure someone
else like a developer is working with the same configuration as you give them the vagrant file and the
set up that sh script and they're set let's look at how to configure a multi machine set and vagrant
if there is any common configuration to all the VM is just specify it at the top of the file.
In this example we're going to use the same box or image for all the VM so we list it first.
Next create a configuration block for the first VM.
The syntax is shown on your screen.
That's in Texas config that VM don't define and then you put a server name in quotation marks followed
by do.
And then in a set of pipes you also put the server.
Then you set the VM specific configuration using that server any.
This example sets the hostname an IP address for the VM.
You keep adding additional victims using the exact same syntax on your screen a second VM is defined
named server 2.
If you were to run vagrant up using this configuration you would end up with two virtual machines one
named server one with an IP address of 10.
Two of three to four.
And another one named server 2 with an IP address of 10 to 3.5.
We've talked about many of the awesome things vagrant can do and many of the vagrant features you'll
be using most often.
However there is more the vigor and it can and creates a default vagrant file which contains several
comments.
You can read through those comments to get an idea of what else is possible with vagrant.