Instructor: This lesson is about adding
and extending disk using logical volume management.
Now why do we need to extend a disk?
So if we have a disk already in our system,
in our Linux system,
and let's say if that disk becomes full, it's 100%.
So you have this disk that is mounted on /oracle,
and the disk space of that Oracle is one gigabyte.
And now after, let's say, six months or a year,
the database administrator comes back to you and says,
hey, I need more disk space for /oracle
because we've been doing a lot of work.
The productivity has been increasing every day.
The data is increasing every day.
So of course eventually
the databases gets bigger and bigger,
so /oracle gets bigger.
So what options do you have?
Well, you can look at a few options.
Number one would be like delete
some of the older files to free up this space, right?
That's what the basic thing is.
So if you have your room that is fully cluttered
and you don't have a room to walk around, what do you do?
You take out the older stuff and throw it away, right?
I hope so, right?
Okay, so the other options
that we have is add a new physical disk
and mount it to /oracle2.
Meaning that if you have a physical system,
then you could add a new disk in this physical system
if and only if you have the slot.
An extra slot to add an extra disk to that physical system.
If you have it, perfect.
You could partition it.
You could configure it at your rate level
and then you can mount it on /oracle2.
Or if you have a virtual environment,
which is the perfect scenario
and that's why I love virtual environment
because you don't really have to actually,
pull your server out, open the top, and add a new disk.
So if you have a virtual disk,
all you have to do is go to your VM and add a new disk.
And it takes literally a few seconds to do that.
And then once you add that,
you do the same thing /oracle2.
Now I wanted to extend my /oracle.
I don't want to create another partition
or other another mount point like oracle2.
Then what do I do?
Well, you will be out of luck
if you had not used LVM initially.
If you have, then my friend, you are in luck.
Then you would extend your /oracle
through logical volume manager.
So no matter how many disks you attach,
external disk or internal disk, doesn't really matter.
All you have to do is create a partition of that disk
and then attach that disk
within the same group that you created
for /oracle mount point.
Now how does it work?
Let's get into our Linux machine and we'll find out.
Now before we get into a Linux machine,
let's assume that we don't have this space
and we want to add a new disk to our virtual machine.
So let's go to our machine powered off.
Of course, make sure it's powered off
every time you have to add a new disk
or add resources.
Go to Setting, go to Storage,
and then you'll see you have three disks.
The first one you have is about
your own Linux operating system disks
that you created initially.
I think it's like 10 gig.
The second one you have is about the datadisk.
And the third one we added dataoracle,
which is one gig.
So let's click here and you will notice right here
the virtual disk size is one gig,
but of course it is running out of space.
We could extend it.
Now remember one thing,
other virtual environment like enterprise level VMware
or even Oracle or Red Hat virtual environment,
you will be able to extend this disk space right here
by clicking and clicking on extend disk.
But I believe since this is a PC version,
personal version of virtual environment,
so you cannot extend that.
So what do you have to do?
You click on your controller, add a new disk,
add hard disk, create new disk, VDI,
Next, dynamically allocated, Next.
And the name,
you could just name the same way as the other one,
dataoracle and put one here,
because of course, sorry,
you cannot name the exact same
because it will be a conflict.
So now this is the second disk.
You know what?
It's better you put two.
So this way it's easier to differentiate
the first one and the second one.
So this is the two
and I want to give it another extra one gig.
So get one gig and click Create.
So it has created two disks.
So basically what we are doing here
is we are combining Oracle data,
sorry, dataoracle or dataoracle2.
So that is done and now click OK.
Go ahead and hit power on or Start.
Okay, so we have logged into our Linux machine.
Go ahead and become root.
Now let's run the df -h command
and the disk space or the partition
that we are trying to extend is this right here.
So if you look at it right now,
this partition is mounted on /oracle
and that this size is 997,
which is like a one gig,
used is 33 meg and available is 965.
Now we are assuming that right now the usage
is instead of four, it's 100%.
So once we are gonna add additional disk space to it,
instead of 997 megabyte, it'll become two gig.
So let's go to our command fdisk -l,
let's pipe it to more.
And let's see what other disk we have available.
/dev/sda which is the root disk
where we did installation;
sdb is where we created our data disk;
then we have sdc, which is the Oracle disk that we used.
So now we should also have the new one
which we just created with the label sdd.
So let's see, hit Enter.
See right here?
You just have to be very careful
'cause sometimes it throws
so much information on the screen,
you can't really see where your disk is.
Anyway, so that's the disk sdd.
This is our new disk with one gig.
So now we're gonna do,
we are gonna partition that disk
the same way we partition any other disk
whenever we create a new one.
So to partition that disk, you run fdisk /dev/sdd
and this is going to be your new disk,
hit n for new, p for primary disk,
hit Enter for default or just hit one, whatever you like.
Hit 2048 or just hit Enter to default.
Hit Enter again for default value.
p for petition.
You'll see right here it says empty.
As soon as I assign 8e to it,
it will see Linux LVM.
So hit t again and l again.
And you'll see this is a list of all the available
file types that we could assign to it.
So we will just pick 8e again for Linux LVM.
Hit Enter again, and now you'll see Linux LVM.
Now this is the system that's using its type of file.
It's gonna be assigning it to.
Now you hit w to create that partition.
So that partition is created.
The partition is sdd1.
You could do fdisk again, hit l and do pipe it to more.
And you'll see sdd1.
So right here, sdd1.
It is created, perfect.
All right, so now you could just reboot the system
real quick so it is updated to in the system again.
Okay, once you have your system back online,
you could log back in and become root.
Do fdisk -l again.
And this time just type /dev/sdd1,
just to make sure it's there.
Yep, it's there.
Now it's time to extend the file system,
/dev/mapper/oracle_vg-oracle_lv.
We are extending this one.
So the file system gets bigger.
So first we do pvdisplay.
This will show us which group is associated with which disk.
So our concern is right here, this one, sdc1
and it is associated with group oracle slash vg.
You could also run pvs.
It will also give you pretty much the same information.
This disk is associated with this group.
So we want to add a new disk within this group.
And once we add that new disk that we created, sdd,
then we'll extend the group
and we'll extend the logical volume as well.
So let's do vgdisplay.
And let's do on our oracle_vg.
This is our group.
So you'll see it also tells you
the volume group size is, what?
1020 megabyte, which again, of course is one gig.
So now let's create physical volume.
So pvcreate /dev/sdd1,
because we always have to create physical volume.
So it is successfully created.
Now we do vgextend.
We are extending the group,
which is a group name, oracle_vg.
And we are associating that to s, /s, sorry, /dev/sdd1.
Okay, so now it is extended with that disk partition.
Because if you just say vgextend oracle_vg,
it will say, hey, I will extend it.
That's fine, but which disk I should leverage on
or step on or include that disk within me to extend.
So you have to define that the disk is /dev/sdd1.
Okay, so now that is done.
Now let's do logical volume extend.
So logical volume extend is right here.
So you have to specify the size,
which is the command is -l and plus the size,
so 1024 which is one gig.
So just put meg here and then you specify /dev/mapper,
which is right here.
What I would do is I'll just move that, go up
to our fdisk command and I'll just copy this entire thing
so I won't make a mistake,
'cause this is the logical volume
that eventually we want to extend.
And now we come down and paste it right here.
Okay, so now we have extended
and it says logical volume oracle_vg/oracle_lv
successfully resized.
Awesome, let's extend the file system.
And the command to extend the file system is xfs_growfs.
And then you hit paste, hit Enter.
And that should grow your file system, df -h.
And now you will see /dev/mapper _vg, two gig, 33 oracle
is now two gig.
Remember we had it one gig, now it's two gig.
That's how you extend a file system.
Once you extend it, you go back to your Oracle guy,
tell him you have added a new storage
to your existing mount point.
You did not have to create /oracle2.