welcome back to back space Academy in this lecture we'll explore using EBS or 2
elastic block storage as a storage option for Amazon ec2 we'll create an 3
instance which will have an extra EBS volume attached to it and then we're 4
going to go into the Linux operating system and mount that volume will then 5
take a snapshot of that volume and use that snapshot to create a copy of that 6
EBS volume. Okay so from the ec2 management console we'll launch an 7
instance and I'm going to just select the Amazon Linux AMI. Now I'm just 8
going to slow down here and explain a few things so we can see here it's with 9
our t2 micro for instance storage it only has the option for EBS there's no 10
option for attaching an instance store to that so let me scroll down we can see 11
that most of them don't until we get to an m3 medium and we can see there an m3 12
medium can have instant store storage attached to it 13
you may want to consider using instant store storage if you've got a batch 14
operation and you just want to a device or storage device that is going 15
to be used for storage of batch data that is not going to need to be 16
persisted afterwards so it can be lost after you've finished with that 17
batch operation and so that's the kind of thing that you would use an instance 18
store for but it's normally with larger instances I'm not going to go into 19
instance store it's pretty well the same sort of process that you would do with an EBS 20
volume but I just don't want you to get a bill at the end of the month if you 21
forget to terminate all this stuff if you forget to terminate a t2 micro 22
instance it's not a major deal for you financially but if you get a bigger 23
instance it you might be a bit surprised when you get your bill at the end of the 24
month so I'm going to stick with a t2 micro and be responsible for you next 25
configure instance details we want to make sure that we have a public IP Auto 26
automatically assigned for that we'll leave everything else as it is 27
add storage so we can see that as as we normally have we have our root storage 28
there which is has a storage name of dev or device name of dev /xvda 29
and the snapshot which would come from our our Linux AMI 30
and we can see there that we've selected the general-purpose now we're going to 31
add a new volume additional to that and if we look at the selection there we've 32
only got the option of EBS but if this was a large instance then we would have 33
an option of EBS or instance store type storage the device name that has been 34
selected for us there is dev /sdb but we can change that if we want if we're going 35
to be attaching multiple volumes they will have different device names and we 36
would need to take note of the device names so that we can recognize and when 37
we go to mount them we also have the option of of creating this EBS volume 38
from an EBS snapshot and we could select that we don't have one so we're not 39
going to do that and we have our volume type so here it's automatically selected 40
as a general purpose type but we could do provisioned IOPS if we want and we can 41
put our IOPS that we would like to provision for this drive we could also 42
go down to magnetic if we wanted to save costs and if speed was not a major deal 43
for us I'm going to stick with a general purpose now I'd like you to take very 44
good note here is that by default delete on termination has been selected for the 45
route volume but by default manually added EBS volumes are not deleted on 46
termination you need to you need to remember that so that by default route 47
are deleted on termination but by default manually added EBS volumes are 48
not but of course you can change that here if you'd like the reason why 49
manually added EBS volumes are not normally deleted on termination is that 50
they normally contain data and you something goes wrong with your ec2 51
instance it is terminated you don't necessarily 52
want to lose that data you want that data to persist afterwards and use it maybe 53
later on with another instance but for this lab or for this hands-on exercise 54
I'm going to select delete on determination for both of them because I 55
want to make sure that when you terminate this instance everything is 56
cleaned up afterwards and you're not going to get a bill at the end of the 57
month so just click on review and launch and launch and I'll just select the key 58
pair that I've used before and launch that instance and after a certain amount 59
of time we're going to have our instance up and running if we look at the 60
description of our instance when we scroll down to block devices we can see 61
that we've got our route device of xvda and also our manually added EBS 62
volume which is at sdb so let's click on that it'll give us the details of 63
this so we can see that we've got an EBS volume ID there and it is attached and 64
it has delete on termination selected for true now although it has been 65
attached it's not necessarily available for us to use with that instance until 66
we mount it so we're going to go now into the command line interface and 67
we're going to connect into this instance and we're going to mount it 68
using the Linux operating system okay so I've just connected into that 69
ec2 instance now the first thing we want to do is just to list the block volumes 70
that are attached to this instance so just do a LS or list blk and that will 71
list our volumes in so we can see we have our route volume is xvda and 72
that is mounted as a route volume there it has a mount point there and we also 73
see that there is xvdb which is our manually added EBS volume and there is 74
no mount point for that some we need to create a mount point the first thing 75
we'll do is we'll have a look and see whether or not a filesystem is actually 76
on that disk so the command we use there is sudo 77
for root we'll need root access to do that sudo file -s and the name 78
of our our EBS volume device now all the details of this are in the AWS 79
documentation so you get lost just refer to that and it'll be pretty 80
straightforward for you and then we can see it's come back with data which means 81
that there is no file system that has been created on this volume so we need 82
to do that now the command that we use to create a file system is sudo mkfs and 83
then we have the - T option and the filesystem type and then we have the 84
device name after that and there you can see it's created that filesystem for us 85
now to check whether or not we've successfully created at filesystem we 86
can just check the file systems now so we can sudo file - s and then the name 87
of that volume and it will tell us whether there is a filesystem on there 88
so there is a filesystem there we've got the ID of that filesystem as well so now 89
I'm just going to make a directory that we can use as a mount point for this EBS 90
volume so we just make a directory called data and now we'll mount our EBS 91
volume to that mount point directory so now that we've mounted our volume we 92
need to make sure that is mounted when the instance reboots so to do that we 93
need to edit our fstab file now if you don't understand what all this means 94
don't worry too much because this is not a course on the Linux operating system 95
it's a course on AWS so you just need to know how to go through this process of 96
mounting a volume you don't need to be an expert in the Linux operating system 97
but it is a good thing if you're going to be using Linux in the future to learn 98
a bit more about it so what we're going to do now is just edit, but first of 99
all we'll make a back of our fstab file, so before I edit the 100
file I need to get the ID of the EBS volume I can use the device name but it 101
is more reliable to use the ID of the device so I'll just do that same command 102
that we used before to get the file system information and then I can see is 103
that the ID there so it's going to copy that 104
UUID equals it's going to copy that 105
and now I'm going to edit that file the fstab file in Nano so just sudo nano 106
and then these file and there we can get into the edited screen so you can see 107
there's a number of entries and we need to add another one for our our new 108
amount so we just scroll down to the bottom of the lift set and we're just 109
going to put another entry and it's going to paste it in so what we what 110
we're going to put in is we're going to put in the ID of that volume that we got 111
from that command previously then we're going to put in the mount point 112
directory which is data or forward slash data then the filesystem type and then 113
we're going to do defaults and then ,nofail and then we're 114
going to do 0 and 2 and once we've done it that will enable that the EDS volume 115
will be mounted upon reboot so just do control X and if you want to save that 116
we just click on yes we do want to save that and enter and so now we can just 117
check that it works so we do sudo mount -a and there's no errors 118
coming back so that's fine instead we're just going to CD into that data 119
mount point directory which is where our EBS volume is now mounted let me just 120
do a dir on that and we can see there's nothing in them and so now we'll just 121
create a test folder so just to sudo touch just create an empty file there of 122
test.txt and i'll just dir into that now 123
okay so we've successfully create an ec2 instance with an additional EBS volume 124
we've mounted that volume using a Linux operating system we've added a file to 125
that volume what I'd like to do now is to create a snapshot snapshot of that 126
volume and then use that snapshot to launch another ec2 instance with a EBS 127
volume that will be an exact replica of that EBS volume that we created a 128
snapshot from okay so back in the ec2 management console if I select the 129
description of that ec2 instance and we scroll down to the EBS volume that we've 130
attached there dev /sdb and if I click on that and if I click then on the EBS 131
ID I can get the details of that EDS volume which we've got there so what I 132
want to do now is to create a snapshot of this volume so I'll just go into 133
actions create snapshot I'll give it a name so I'll just give it a name 134
backspace - and in the details of the the volume just click on create now and 135
it has started and so we can view this snapshot now so just click on View now 136
after a certain amount of time it will be available for us to use so there is 137
our completed snapshot so we just go to actions and we can create a volume from 138
this snapshot so I'm just going to leave those the same as they are there and 139
we'll create a volume for this snapshot and we can do the volume there and 140
there's our volume ready to go so now jumping back into the ec2 management 141
console I'm going to launch another instance of the same type using the same 142
ami but I'm going to use the snapshot that we just created to attach a volume 143
from or an identical volume for the one that we just created a snapshot 144
of so just going to launch instance will select the same linux ami that we've 145
selected before will you select the same t2 micro that we had will again put a 146
public IP during the lead storage now so now we can add a new volume EBS and we 147
can put the same device name there and now we just got a search for our 148
snapshot we just type in because I know it started with backspace and 149
it will come up with that snapshot there so it's always a good idea to put a 150
description in so as you can find your snapshots a lot easier but I didn't put 151
a description in but I know that that was the snapshot it was any one that I 152
created and I just do delete on termination again so what we will be 153
doing is we'll be creating as before a Linux instance with an EBS volume 154
attached but this time it will already have a filel system created on it from a 155
snapshot so we just need to mount that volume afterwards and we'll have that 156
ready to use so just going to review and launch and launch using a key pair that 157
we've used before 158
okay so after a while our instance will be up and running and so we can have a 159
look at that now and we can see there that we have our extra block devices as 160
well so we've gone through with we've done the two ways we've created a EBS 161
volume from scratch on launch and we've mounted that and we've added files to it 162
and we've also gone the other way of doing it with a snapshot as well so it 163
got a pretty good understanding now of EBS volumes and I'll see you in the next lecture