Instructor: Okay, so now let's talk
about EBS volume and resizing.
So you can increase the size of your EBS volumes.
So you can increase the size or the IOPS if it's relevant,
and after resizing an EBS volume,
what you need to do is to repartition your drive.
That means that after you increase the size of your volume,
there's going to be more sizes available
but your EC2 instance will not know about it
until you read partition your drive to tell your instance
to use that new space.
So when you increase the size,
it's possible for the volume to go
into a long optimization phase.
This is to reorder the blocks.
But during that time, the volume is still usable
and working as expected.
You cannot decrease the size of your EBS volume.
If you wanted to do so, you need to create a smaller volume,
then copy the data from one form to another
and then attach it properly.
So if we have a look at what happens,
so let's say we have a 250 gigabyte volume,
and then we are modifying it to make one terabyte.
So it goes into the modifying phase,
then it goes into the optimizing phase,
and then you will be into the completed phase
with a one terabyte EBS volume.
But as I said, if from the perspective of your EC2 instance,
there will be 250 gigabytes of partition already being used
and being mounted properly,
but you need to repartition your EBS volume
to add on that extra missing 750 gigabytes for that
so that your EC2 instance will be able
to use that extra size.
So let's have a look in the hands-on
to see how we can do it.
So let me launch an instance and I'm going to go quickly,
but I'm going to create an Amazon Linux to T2 micro.
Next, and for the storage let's say we start with
a gigabyte of storage and then we'll add tags,
security group, and then I can choose a security group
that I already know, this one, perfect.
And then we'll key pair and we're good to go.
So my instance is now starting,
and then you wait for it to be done.
So I can connect to it using EC2 instance connect.
And then if I do LSBLK,
I can see that I have one device of XVA of type,
a gigabyte, so this is my main volume on my EC2 instance.
And if I do DF minus H, as we can see,
the size is a gigabyte.
1.5 gig is used and 6.6 is available.
So now what I'm going to do is I'm going to change the size
of that main EBS volume.
So for this I'm going to go into my volumes.
And in here, I'm going to take this volume,
right-click, and I'm going to modify it.
Now there's multiple ways I can modify the volume.
I can modify the type itself,
so from to GP2 to GP3,
to IO1 to IO2, to even magnetic.
And then within each category,
you can also change some attributes.
So say I want you to go from eight gigabytes
to 10 gigabytes, okay,
and then I will click on modify.
So it takes some time for the performance change
to take full effect.
And we need to extend the OS file system on the volume
to use any newly allocated space.
So this is what we're going to see right here.
And there are commands to do it on Linux and Windows.
So I click on yes.
Now the modified volume request is being done.
So I'm going to have to wait for it to be done.
So if we have a look at the status on the right-hand side,
it says In-use and then modifying, zero percent.
So as the volume is being modified, this is going to evolve.
And after the modifying phase is done,
it's going to go into an optimizing phase
that you can see right now.
So this was quick because I just added two gigabytes,
so that was pretty quick.
So now if we run the same commands right here,
so I'll do LSBLK.
As we can see now, X VDA is 10 gigs,
but X VDA1 is eight gigs.
That means that yes, as you can see,
the OS has not been extended
to use the full size of the disc.
And we can also see it by doing DF minus H.
And as we can see in here,
it says still eight gigabytes for this mounted disc.
So as you can see,
we're still not using the 10 gigabytes in here.
And so to do so we need to extend a Linux file system
after resizing a volume,
and there are commands on how to do that.
So as we can see,
we're running this command right now,
and we've run this command as well.
But there is a way for you to do it.
So you need to use the growpart command, okay?
And we need to change the name of the device.
So as we can see right here,
we need to do sudo growpart
and then the partition number, which is one,
so let's have a look and see if that works.
So we're going to do sudo growparts
and then Dev, Xvda1, 1.
Dev, Xvda1.
So here we go.
So sudo growparts Dev, Xvda1,
and it has changed my partition
and now there's an old and a new size.
And so now if I do DF minus H, as you can see,
or LSBLK,
as you can see now, my Xvda1 is using 10 gigabytes.
And so from my DF minus H,
to return 10 gigs I believe I have to reboot my instance.
So sudo reboot.
So I'm going to reboot it directly
from the EC2 instance page.
So let's go ahead and reboot that instance.
And then click on connect, using EC2 instance connect.
And as we can see now, if I do LSBLK,
it shows 10 gigs,
And if I do GF minus H,
it shows 10 gigs as well.
So I have extended my partition.
And I believe you could do it without a reboot.
So if you go into the documentation,
so once we're done with the sudo growparts,
you can extend the file system using the XFS growth
if you're using the XFS file system,
or if you're using the ex4 file system,
you can use the sudo resize2fs as well to resize it.
And then the DF should work as well.
So it was just an example,
but at least you can see how you can resize an EBS volume.
And that's it.
I hope you like it and I will see you in the next lecture.