1
00:00:03,150 --> 00:00:08,140
During this course you're going to write several shell scripts and learn a lot along the way.

2
00:00:08,280 --> 00:00:12,840
It's really important that you learn the concepts so that you can apply your knowledge on any Linux

3
00:00:12,840 --> 00:00:16,490
distribution or any Unix like or Linux like system.

4
00:00:16,500 --> 00:00:20,830
However when you're learning a new concept I don't want anything to get in your way.

5
00:00:20,850 --> 00:00:26,260
I don't want you to get hung up on little gotchas or get sidetracked by some unimportant detail.

6
00:00:26,400 --> 00:00:32,190
That's the main reason why you're going to use a specific Linux installation that was created for this

7
00:00:32,190 --> 00:00:33,300
course.

8
00:00:33,300 --> 00:00:38,130
Another reason you're going to use the Linux image design for this course is so that you can get help

9
00:00:38,460 --> 00:00:43,590
if everyone in the class were to use a slightly different Linux installation it would be almost impossible

10
00:00:43,590 --> 00:00:49,110
to manage the class if I or the teaching assistants know exactly what system you're using.

11
00:00:49,140 --> 00:00:54,570
We can help you in a very specific way we can even take your script and run it on a system that is the

12
00:00:54,570 --> 00:00:56,900
same as the one you're working on.

13
00:00:57,030 --> 00:00:59,730
This helps us help you.

14
00:00:59,730 --> 00:01:04,890
A third reason to use the Linux installation method I'm about to describe is that it will allow you

15
00:01:04,890 --> 00:01:11,130
to quickly create an entire mini network of Linux systems in the real world you'll end up writing shell

16
00:01:11,130 --> 00:01:14,670
scripts that perform a given task on multiple systems.

17
00:01:14,670 --> 00:01:18,900
This setup allows you to practice those skills and we're going to do that in this class.

18
00:01:19,050 --> 00:01:19,330
OK.

19
00:01:19,350 --> 00:01:23,910
So what does this installation method and lab setup that I've been alluding to for the last couple of

20
00:01:23,910 --> 00:01:27,010
minutes here and what this environment look like.

21
00:01:27,210 --> 00:01:33,570
First it consists of virtualization software that will allow you to run Linux inside a virtual machine

22
00:01:33,810 --> 00:01:36,400
on your local desktop or laptop.

23
00:01:36,420 --> 00:01:42,120
My favorite virtualization software for this purpose is virtual box available for download and Virtual

24
00:01:42,120 --> 00:01:43,560
Box dot org.

25
00:01:43,560 --> 00:01:47,520
First off it's free to download and it's really easy to install.

26
00:01:47,520 --> 00:01:50,900
Secondly it runs on Windows Mac and Linux.

27
00:01:50,910 --> 00:01:55,830
This is a big plus for a course like this as you're going to have the exact same experience no matter

28
00:01:55,830 --> 00:02:01,430
if you're working on a Windows system a Mac system or if you use Linux on your desktop every day.

29
00:02:01,710 --> 00:02:06,720
A little side note here if you're looking for a virtualization solution for running virtual machines

30
00:02:06,720 --> 00:02:11,850
in production for example I'd be looking at something like VM where KTM or overt.

31
00:02:11,940 --> 00:02:17,550
But for our purposes for creating test systems on our local machine and working together in this class

32
00:02:17,730 --> 00:02:19,570
virtual box is the way to go.

33
00:02:19,770 --> 00:02:26,790
Let's get clear on what virtual box does and what virtual machines are virtual box is a full virtualization

34
00:02:26,790 --> 00:02:27,300
product.

35
00:02:27,420 --> 00:02:33,240
Meaning that it allows you to run an unmodified operating system with all of its installed software

36
00:02:33,240 --> 00:02:34,480
in a special environment.

37
00:02:34,500 --> 00:02:40,260
On top of your existing operating system this special environment called a virtual machine is created

38
00:02:40,260 --> 00:02:46,230
by the virtualization software by intercepting access to certain hardware components and certain features

39
00:02:46,530 --> 00:02:51,220
the physical computer is called the host while the virtual machine is called a guest.

40
00:02:51,240 --> 00:02:56,730
Most of the guest code runs unmodified directly on the host computer and the guest operating system

41
00:02:56,730 --> 00:02:59,150
thinks it's running on a real machine.

42
00:02:59,160 --> 00:03:01,380
That last point is important.

43
00:03:01,380 --> 00:03:06,600
The guest operating system thinks it's running on real hardware and it really doesn't know that it's

44
00:03:06,600 --> 00:03:08,130
inside a virtual machine.

45
00:03:08,340 --> 00:03:12,720
If you're doing something inside a virtual machine in the operating system of them virtual machine says

46
00:03:12,720 --> 00:03:17,490
something like performing this action will erase all the data on all your disks.

47
00:03:17,490 --> 00:03:23,280
It's really only referring to the virtual disks that it has access to not your physical device on your

48
00:03:23,280 --> 00:03:25,200
real physical host computer.

49
00:03:25,200 --> 00:03:30,060
You can perform destructive actions inside the virtual machine and those actions are contained inside

50
00:03:30,060 --> 00:03:34,000
of that virtual machine and won't interfere with your actual physical computer.

51
00:03:34,170 --> 00:03:38,550
Virtual Box provides software that can be installed on the guest operating system.

52
00:03:38,550 --> 00:03:41,510
This software is called Virtual Box guest additions.

53
00:03:41,520 --> 00:03:46,650
This software allows the guest operating system to access shared folders on the host system share the

54
00:03:46,650 --> 00:03:49,260
clipboard and some other similar actions.

55
00:03:49,260 --> 00:03:52,010
This is not required but it can be very useful.

56
00:03:52,020 --> 00:03:56,250
The virtual machine you'll be deploying in this course will already have the guest addition software

57
00:03:56,250 --> 00:03:57,380
installed in them.

58
00:03:57,390 --> 00:04:02,190
I just wanted to mention the guest edition so that you're aware of them and know what they do manually

59
00:04:02,190 --> 00:04:06,510
creating virtual machines with virtual boxes fairly easy and straightforward.

60
00:04:06,630 --> 00:04:10,410
By the way we are not going to be manually creating machines in this course.

61
00:04:10,410 --> 00:04:15,750
I just want to show you the process so that you can do this on your own later or so that you know exactly

62
00:04:15,750 --> 00:04:19,020
what is happening behind the scenes when we automate this.

63
00:04:19,020 --> 00:04:25,170
So first you start the virtual box application and next you click on new to create a new virtual machine.

64
00:04:25,170 --> 00:04:29,910
From there you would give it a name virtual box a bit about the operating system that you'll be installing

65
00:04:29,910 --> 00:04:35,310
inside of the virtual machine and allocate some resources such as memory and disk space to the virtual

66
00:04:35,310 --> 00:04:35,900
machine.

67
00:04:36,000 --> 00:04:41,520
When you create a virtual desk for the virtual machine you can make it dynamically allocated a virtual

68
00:04:41,520 --> 00:04:43,990
disk is simply a file on the host system.

69
00:04:44,100 --> 00:04:49,920
When you choose to dynamically allocate that disk it will only use space on your physical disk as that

70
00:04:49,920 --> 00:04:55,890
space is used inside the virtual machine I guess this means that the disk file will grow as needed.

71
00:04:55,890 --> 00:05:01,130
The upside is that the virtual machine thinks it's getting a large disk such as 100 gigabyte or 200

72
00:05:01,140 --> 00:05:01,770
gigabyte.

73
00:05:01,860 --> 00:05:08,330
But if it only uses one gigabyte then only one gigabyte of space is used on your physical hard drive

74
00:05:08,780 --> 00:05:13,420
the price you pay for this dynamic allocation is performance inside the virtual machine.

75
00:05:13,460 --> 00:05:16,420
But for our purposes this is totally acceptable.

76
00:05:16,580 --> 00:05:20,150
Once you've allocated resources to the virtual machine it's ready to be used.

77
00:05:20,210 --> 00:05:24,200
And the first time you started up it will ask you to attach a disk to boot from.

78
00:05:24,200 --> 00:05:29,060
Typically what you'll do is download a Linux ISO from your favorite distribution's Web site and then

79
00:05:29,060 --> 00:05:32,290
tell virtual box to use that ISO to boot the system with.

80
00:05:32,510 --> 00:05:37,970
Alternatively you can actually put a physical CD or DVD in your computer and tell virtual box to use

81
00:05:37,970 --> 00:05:39,980
that physical drive for the install.

82
00:05:39,980 --> 00:05:45,350
Now you install the OS in the virtual machine just like you would as if you were installing that OS

83
00:05:45,350 --> 00:05:47,270
on real physical hardware.

84
00:05:47,270 --> 00:05:52,550
This process is all well and good but as you can probably guess it can be a bit time consuming.

85
00:05:52,550 --> 00:05:58,340
Going through the virtual machine creation process and manually performing the operating system installation

86
00:05:58,610 --> 00:06:03,920
each time you want to create a new virtual machine we're looking to automate this process and save us

87
00:06:03,920 --> 00:06:09,770
a lot of time doing that tedious work to do that we'll use a command line tool called vagrant which

88
00:06:09,770 --> 00:06:13,650
is available to download for free from vagrant up Tom.

89
00:06:13,940 --> 00:06:19,670
This command line tool works on Mac Windows and Linux so no matter what OS you're using for this course

90
00:06:19,670 --> 00:06:20,630
you'll be covered.

91
00:06:20,630 --> 00:06:27,130
Vagrant provides easy to configure reproduceable and portable work environments by default vagrant previsions

92
00:06:27,150 --> 00:06:29,400
virtual machines using Virtual Box.

93
00:06:29,480 --> 00:06:35,340
It can be configured to deploy virtual machines to VM where eight of us Rackspace and other providers.

94
00:06:35,510 --> 00:06:40,490
But for this course we're sticking to creating virtual machines inside a virtual box running on our

95
00:06:40,490 --> 00:06:41,580
local systems.

96
00:06:41,630 --> 00:06:46,250
You're going to use vagrant to quickly and easily spin up virtual machines running Linux.

97
00:06:46,250 --> 00:06:50,930
Let's talk about what you should know and understand about vagrant before you start using it.

98
00:06:50,990 --> 00:06:54,240
A box invigorates speak is an operating system image.

99
00:06:54,350 --> 00:06:58,990
The vagrant box ad command will download and store that box on your local system.

100
00:06:59,000 --> 00:07:02,600
You only need to download a box once as this image will be cloned.

101
00:07:02,660 --> 00:07:08,120
When you create a new virtual machine with vagrant using the boxes name the typical format of this command

102
00:07:08,120 --> 00:07:09,350
is vagrant box.

103
00:07:09,360 --> 00:07:12,320
Add user Ford slash box.

104
00:07:12,320 --> 00:07:18,860
I have a user account on vagrants public box catalog system my user name is Jason C..

105
00:07:18,980 --> 00:07:22,840
I created a box specifically for this course named Sentosa 7.

106
00:07:22,880 --> 00:07:26,780
It's really just a minimal Sentosa install so to demo that box you had run.

107
00:07:26,810 --> 00:07:32,430
Vagrant box and Jason see Ford slash Sentosa 7.

108
00:07:32,450 --> 00:07:37,200
There are several boxes that are publicly available on vagrants public box catalog system.

109
00:07:37,330 --> 00:07:41,720
I have a link in the exercise instructions where you can download other boxes if you'd like to experiment

110
00:07:41,720 --> 00:07:43,600
with them on your own time.

111
00:07:43,670 --> 00:07:49,880
In addition to boxes vagrant uses the concept of projects a vagrant project must consist of a folder

112
00:07:50,150 --> 00:07:53,480
and a vagrant configuration file called a vagrant file.

113
00:07:53,630 --> 00:07:56,650
So to create a new vagrant project first create a folder.

114
00:07:56,660 --> 00:08:02,000
For example I would open up a command prompt on Windows or a terminal on Linux or Mac and then type

115
00:08:02,000 --> 00:08:05,890
the command make DJR space VM one.

116
00:08:05,960 --> 00:08:09,350
From there you would change into that directory with CVM one.

117
00:08:09,350 --> 00:08:15,140
Now you need to initialize your vagrant project which means creating a vagrant configuration file his

118
00:08:15,170 --> 00:08:20,930
configuration file is named vagrant file and it contains the box name to use for the project and any

119
00:08:20,930 --> 00:08:27,300
other configuration options for the virtual machine or virtual machines to create to create the vigor

120
00:08:27,300 --> 00:08:29,450
and file run the vagrant init command.

121
00:08:29,450 --> 00:08:33,950
So continuing with our previous example here you would run vagrant a net.

122
00:08:33,980 --> 00:08:37,110
Jason C forward slash Cinto 7.

123
00:08:37,130 --> 00:08:40,090
Now you can bring up an instance of that box by running vagrant.

124
00:08:40,090 --> 00:08:46,070
Up the first time you run the vagrant up command vagrant will import or clone that vagrant box into

125
00:08:46,070 --> 00:08:47,970
virtual box and then start it.

126
00:08:48,080 --> 00:08:52,820
If vagrant detects that the virtual machine already exists in virtual box it will just simply start

127
00:08:52,820 --> 00:08:55,400
it by default when the virtual machine is started.

128
00:08:55,400 --> 00:09:00,950
It is started in headless mode meaning that there is no user interface for the machine visible on your

129
00:09:00,950 --> 00:09:02,430
local host machine.

130
00:09:02,540 --> 00:09:07,370
Since this class is focused on shell scripting will be working at the command line so we really don't

131
00:09:07,370 --> 00:09:10,420
care about looking at the Linux desktop anyway.

132
00:09:10,430 --> 00:09:14,450
Now if you look at the virtual box application you'll see that you'll have a new virtual machine that's

133
00:09:14,450 --> 00:09:19,700
running it's name starts with the name of the vagrant project which is the name of the director you

134
00:09:19,700 --> 00:09:22,700
created where the vagrant file lives.

135
00:09:22,700 --> 00:09:28,250
As I mentioned earlier you are going to be creating multiple virtual machines you can actually specify

136
00:09:28,250 --> 00:09:31,540
those additional virtual machines in the same vagrant file.

137
00:09:31,550 --> 00:09:37,250
This is called a multi machine setup by vagrant by default when you run the vagrant up command it brings

138
00:09:37,250 --> 00:09:40,660
up all the virtual machines defined in the vagrant file.

139
00:09:40,700 --> 00:09:46,220
If you only want to operate on a single virtual machine you have to supply the virtual machines name.

140
00:09:46,460 --> 00:09:48,970
For example if you defined a VM named M..

141
00:09:49,010 --> 00:09:51,800
You can bring it up with a vagrant a master command.

142
00:09:51,800 --> 00:09:57,530
Likewise if you had a VM defined with the name of server wan you would bring it up with vagrant up server

143
00:09:57,530 --> 00:10:02,500
one and I want to repeat that if you just Rannveig went up it would bring up both of those that word

144
00:10:02,500 --> 00:10:04,470
of find be caused by a fault.

145
00:10:04,470 --> 00:10:09,720
It brings up every system that's defined in the vagrant file for that vagrant project.

146
00:10:09,920 --> 00:10:16,830
SH secure shell is the network protocol used to connect to Linux systems vigor it provides a nice shortcut

147
00:10:16,830 --> 00:10:19,070
to S-sh into the virtual machines.

148
00:10:19,260 --> 00:10:24,780
If you only have one virtual machine defined in the bigger file you can simply run vagrant S-sh and

149
00:10:24,780 --> 00:10:30,330
emet the VM name and you'll be automatically logged into that one VM Linux system that you've created

150
00:10:30,330 --> 00:10:31,440
with vagrant.

151
00:10:31,440 --> 00:10:37,140
If you have multiple machines defined you'll need to supply the specific VM name for example vagrant

152
00:10:37,200 --> 00:10:42,510
S-sh master to log out of a Linux system simply type exit and hit enter.

153
00:10:42,540 --> 00:10:47,700
A quick note for you Windows users Windows doesn't currently ship with an S-sh client so you'll need

154
00:10:47,700 --> 00:10:48,760
to install one.

155
00:10:48,840 --> 00:10:50,670
And what I recommend doing is installing.

156
00:10:50,680 --> 00:10:57,210
Get that CGI tty from get dash SBM dot com which includes an S S H client.

157
00:10:57,210 --> 00:11:02,190
When you work on the exercise I'll give you specific instructions on how to get this configured but

158
00:11:02,190 --> 00:11:07,170
for you Mac and Linux users you can just skip this step as you already have an S-sh client built in

159
00:11:07,170 --> 00:11:08,000
by default.

160
00:11:08,190 --> 00:11:12,800
Ok back to vagrant vagrant can be used to control the virtual machines it creates.

161
00:11:12,810 --> 00:11:18,340
For example the vagrant halt command shuts down all the virtual machines defined in the vagrant file.

162
00:11:18,510 --> 00:11:23,730
If you have multiple victims to find and only want the whole one just specify the VM name when you run

163
00:11:23,730 --> 00:11:28,080
this command you will not lose any work you've performed inside the virtual machine.

164
00:11:28,080 --> 00:11:32,550
That's because the virtual machine will still exist in virtual box but it will just simply be halted

165
00:11:32,550 --> 00:11:36,390
or stop to restart all the defined VM for the project run.

166
00:11:36,390 --> 00:11:41,340
Vagrant up since the virtual machines already exist a vagrant Upal simply start them and it will skip

167
00:11:41,340 --> 00:11:44,040
the import process because it's not needed.

168
00:11:44,100 --> 00:11:48,420
By the way I'm pretty sure you see a pattern here with all these commands if you don't specify a VM

169
00:11:48,420 --> 00:11:53,760
name the command will operate on all the VM defined in the vagrant file for the project.

170
00:11:53,760 --> 00:11:59,010
If you want to limit that operation to a specific VM then you need to supply that name of the VM that

171
00:11:59,010 --> 00:12:00,080
you want to operate on.

172
00:12:00,180 --> 00:12:04,800
So going forward I'm just going to assume that you understand this concept and not point it out for

173
00:12:04,800 --> 00:12:06,030
each and every command.

174
00:12:06,360 --> 00:12:11,640
If you want to suspend the virtual machine run vagrant suspend to resume it run vagrant resume.

175
00:12:11,910 --> 00:12:16,280
If you're done with a virtual machine or you want to start over with a fresh copy of the virtual machine

176
00:12:16,330 --> 00:12:19,190
virtual machines run vagrant destroy.

177
00:12:19,380 --> 00:12:23,870
This will terminate and remove the virtual machine or virtual machines from Virtual Box.

178
00:12:23,970 --> 00:12:27,960
If you run this command then any work inside of the virtual machine will be lost.

179
00:12:27,960 --> 00:12:32,220
If you need help or forget some of the commands you can just run the vagrant command itself without

180
00:12:32,250 --> 00:12:33,660
any options.

181
00:12:33,660 --> 00:12:39,120
Also keep in mind that the vagrant command will act on the virtual machine or virtual machines associated

182
00:12:39,120 --> 00:12:44,250
with a vagrant project directory that you're in during this course she'll be creating multiple vagrant

183
00:12:44,250 --> 00:12:49,860
projects so be sure that you're in the desired vagrant project directory before running any vagrant

184
00:12:49,860 --> 00:12:51,080
command.

185
00:12:51,090 --> 00:12:55,930
Before we wrap up talking about vagrant Let's take a quick look at the vagrant file.

186
00:12:56,090 --> 00:13:02,550
All the vigor configuration occurs after the vagrant Dom configure line and before the end keyword the

187
00:13:02,550 --> 00:13:03,420
two in parentheses.

188
00:13:03,420 --> 00:13:05,630
Here is the configuration version.

189
00:13:05,760 --> 00:13:09,150
Older style configurations are supported but will be used in version 2.

190
00:13:09,210 --> 00:13:12,660
So this is what you'll see in the vagrant file you'll be working with.

191
00:13:12,870 --> 00:13:18,460
The simplest of vagrant file just specifies the name of the box you'll use to create the default VM.

192
00:13:18,510 --> 00:13:24,510
If you want vagrant to set the hostname inside the virtual machine you can use config dot VM dot hostname

193
00:13:24,930 --> 00:13:27,670
to assign a static IP address to the virtual machine.

194
00:13:27,670 --> 00:13:30,730
Use a config VM dot network line.

195
00:13:30,830 --> 00:13:37,620
The example on your screen will assign the IP address of 1:50 3.4 to the virtual machine on a private

196
00:13:37,620 --> 00:13:42,420
network that can only be accessed from the host machine or other vagrant VM.

197
00:13:42,420 --> 00:13:47,940
On that same network you'll be using this vagrant feature to create an entire network of Linux systems

198
00:13:47,940 --> 00:13:49,820
that can communicate with each other.

199
00:13:49,860 --> 00:13:55,410
Each box ships with a set of defaults like whether or not to star in headless mode or how much memory

200
00:13:55,410 --> 00:13:57,640
to allocate to the virtual machine and so on.

201
00:13:57,840 --> 00:14:03,040
You can override these default settings by using a config that VM up provider block.

202
00:14:03,360 --> 00:14:08,130
The example here on the screen will force the virtual machine to start with a gooey graphical user interface

203
00:14:08,550 --> 00:14:13,500
and use 1024 megabytes which is of course one gigabyte of memory.

204
00:14:13,500 --> 00:14:16,440
Vagrant has a provisioning system built in it.

205
00:14:16,470 --> 00:14:22,080
Pre-vis winners and vagrant allow you to automatically install software alter configurations and more

206
00:14:22,230 --> 00:14:27,650
on the machine as part of the vagrant process because we're focusing on shell scripting in this course.

207
00:14:27,650 --> 00:14:29,260
We'll use the show provision.

208
00:14:29,400 --> 00:14:34,020
You won't be using a provision or all the time but we will do this at some point during the course.

209
00:14:34,020 --> 00:14:39,220
This is where you can write a post installation shell script to configure a new system for example.

210
00:14:39,230 --> 00:14:44,360
Vigor will execute the shell script that you specify the first time vagrant upas executed.

211
00:14:44,370 --> 00:14:49,320
The example here on your screen will upload the setup that sh shell script into the virtual machine

212
00:14:49,350 --> 00:14:51,360
and then execute it from there.

213
00:14:51,360 --> 00:14:56,580
This way you can automate and reproduce entire environments quickly if you want to make sure someone

214
00:14:56,580 --> 00:15:01,830
else like a developer is working with the same configuration as you give them the vagrant file and the

215
00:15:01,830 --> 00:15:07,910
set up that sh script and they're set let's look at how to configure a multi machine set and vagrant

216
00:15:08,420 --> 00:15:14,260
if there is any common configuration to all the VM is just specify it at the top of the file.

217
00:15:14,270 --> 00:15:19,970
In this example we're going to use the same box or image for all the VM so we list it first.

218
00:15:19,970 --> 00:15:24,070
Next create a configuration block for the first VM.

219
00:15:24,110 --> 00:15:26,420
The syntax is shown on your screen.

220
00:15:26,520 --> 00:15:31,900
That's in Texas config that VM don't define and then you put a server name in quotation marks followed

221
00:15:31,910 --> 00:15:32,830
by do.

222
00:15:32,990 --> 00:15:36,040
And then in a set of pipes you also put the server.

223
00:15:36,440 --> 00:15:40,560
Then you set the VM specific configuration using that server any.

224
00:15:40,720 --> 00:15:45,200
This example sets the hostname an IP address for the VM.

225
00:15:45,230 --> 00:15:50,960
You keep adding additional victims using the exact same syntax on your screen a second VM is defined

226
00:15:51,050 --> 00:15:52,700
named server 2.

227
00:15:52,820 --> 00:15:58,040
If you were to run vagrant up using this configuration you would end up with two virtual machines one

228
00:15:58,040 --> 00:16:00,810
named server one with an IP address of 10.

229
00:16:00,830 --> 00:16:02,420
Two of three to four.

230
00:16:02,540 --> 00:16:07,610
And another one named server 2 with an IP address of 10 to 3.5.

231
00:16:08,420 --> 00:16:13,220
We've talked about many of the awesome things vagrant can do and many of the vagrant features you'll

232
00:16:13,220 --> 00:16:14,630
be using most often.

233
00:16:14,780 --> 00:16:20,300
However there is more the vigor and it can and creates a default vagrant file which contains several

234
00:16:20,300 --> 00:16:21,130
comments.

235
00:16:21,170 --> 00:16:25,220
You can read through those comments to get an idea of what else is possible with vagrant.
