In this video, you'll learn about a little bit more
advanced operation, reducing a volume group.
So if a volume group consists of multiple PVs,
a PV can be removed from the VG if the remaining
PVs have sufficient free space to allocate its extents.
And this procedure will not work if the remaining
PVs are fully used already.
So you must see P3 greater than 0 in PVs output.
Otherwise, you won't have any success.
For this procedure, first, you will
have to use PV move to move used extents from the volume
you want to remove to the remaining volumes.
And then you use VG reduce to complete the removal.
Now, why would you want to do that?
Well, if you foresee a hard disk problem, for instance,
and you want to remove a failing disk,
this can be a useful procedure.
Let me demonstrate how this works.
On this slide, we have step one of the demo.
It's a two-slide demo.
And I will guide you through it.
So the demo starts with the requirement
to use FDIS to create two partitions with a size
of 2 gigs each and set the type to LVM.
Well, I don't think we have to create two partitions
because we already have these partitions.
But we do need to analyze.
I have two free partitions.
Here we have NVMe 0 and 1P4 with a size of 2 gigs.
And we have NVMe 0 and 2P7, also with a size of 2 gigs.
That's what I'm going to use.
Now, first, I'm using VG create once again.
VG demo is going to be the name of the volume group.
And I'm putting it on dev NVMe 0 and 1P4.
Then I'm going to use LV create minus L1G.
I specifically don't want to use all of the available disk space
minus NLV demo.
And I do that in the volume group VG demo.
Next, when we use VGS, then we see that in VG demo,
we have about 1 gig available.
And when we use PVS, we can see that in the N1P4 PV,
we have about 1 gig available.
Good.
Next, I'm going to use VG extend of VG demo.
And I'm adding slash dev slash NVMe 0 and 2P7.
And then when we use PVS again, then what do we see?
We see that VG demo is now on P7.
And we have 2 gigs available.
That is because the volume group is bigger now.
But we don't do anything with it.
And that's what you can see in the output of VGS,
where VG demo has a total size of 4 gigs.
And there is only 1 gig that is used.
So 3 gigs available.
And all the used disk space is in the PV dev NVMe 0 and 1P4.
Next, I'm going to use LV extend minus uppercase L plus 500M.
Dev VG demo LV demo.
But now I'm adding dev NVMe 0 and 2P7.
And why is that?
Well, that is because I want to make sure
that the extends are used on the second partition
that I just added.
And that's why I've used this device name.
And we can now see that the logical volume
has successfully been resized.
So when I use PVS again, I can see that on N2P7,
the P size is bigger than the P3,
which means that we have used extends on this device.
Good.
Now I can use MKFS.ext4 on dev VG demo LV demo
to create an ext4 file system.
Before continuing, let me see the remainder of the procedure
on the next slide.
And I'm going to mount it.
Temporary mount on MNT is good enough.
So let me do that.
And I'm using DF minus H. And in the last line,
we can see that the file system is 1 and 1 half gig.
And we have 1.4 gigs available.
All right.
Now I'm going to create a file using DD.
DD IFS dev 0, using dev 0 as the input file
to create a big file and measure specifically how many blocks
are written to the big file.
OF is slash MNT slash big file.
BS is 1M.
And count is 1,100.
I'm using 1,100 because I want to make sure
that data is used on both PVs.
You remember the first PV at 1 gig, the second PV at 500 meg.
And by using 1,100 meg in my output file,
I'm making sure that both PVs are being used.
And now I can do my magical command, which is PV move.
Now what is PV move going to do?
Well, I am going to use minus V. And then I'm
moving dev NVMe 0 N2 P7.
And I'm moving that to slash dev slash NVMe 0 N1 P4.
Now this is going to move all the extents from the N2 P7
partition to the N1 P4 partition.
And we can do that for the simple reason
that we had unused extents in the first partition.
And there we can see that the move is happening.
Minus V is for verbose.
And that shows progress.
It shouldn't take too much time, might be a minute or so.
So we can see polling finished successfully.
And now if I'm using PVs, then what do we see?
We see the N2 P7 is completely free now.
And we see that the N1 P4 has grown in size.
And that means that all the extents
have been moved away from N2 P7.
And that means that at this point,
you can use VGREDUCE VGDEMO slash dev slash NVMe 0 N2 P7
to completely remove it from the setup.
And now when I use VGS again, we can
see that VGDEMO is using one PV only.
So that was quite advanced, wasn't it?
But it's a convenient procedure if for any reason
you need to remove a storage device from a volume group.