Partition the new disk
We now need to partition the new /dev/sdb disk so that it can be used, this is done by using fdisk.
# fdisk /dev/sdb
This should provide us with the below prompt, the inputs I have entered in are shown in bold.
‘p’ is then selected as we are making a primary partition.
Command action
e extended
p primary partition (1-4)
p
As this is a new disk, we do not yet have any partitions on it so we will use partition 1 here.
Partition number (1-4): 1
Next, we press the enter key twice, as by default the first and last cylinders of the unallocated space should be correct.
First cylinder (1-2610, default 1): "enter"
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): "enter"
Using default value 2610
‘t’ is selected to change to a partitions system ID, in this case, we change to ’1′ automatically as this is currently our only partition.
Command (m for help): t
Selected partition 1
The hex code ’8e’ was entered as this is the code for a Linux LVM which is what we want this partition to be, as we will be joining it with the original Linux LVM which is currently using /dev/sda5.
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
‘w’ is used to write the table to disk and exit, all changes that have
been done will be saved and then you will be the exit from fdisk.
been done will be saved and then you will be the exit from fdisk.
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
By using “fdisk -l” now you will be able to see that /dev/sdb1 is listed, this is the new partition created on our newly added /dev/sdb disk and it is currently using all 20gb of space.
Increasing the logical volume
Next, we will use the pvcreate command to create a physical volume for later use by the LVM. In this case, the physical volume will be our new /dev/sdb1 partition.
#pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
Now we need to confirm the name of the current volume group using the vgdisplay command. The name will vary depending on your setup, for me, it is the name of my test server. vgdisplay provides plenty of information on the volume group, I have only shown the name and the current size of it for this example.
# vgdisplay
--- Volume group ---
VG Name motadata
VG Size 13.97 GiB
Now using the vgextend command, we extend the ‘motadata’ volume group by adding in the physical volume of /dev/sdb1 which we created using the pvcreate command just before.
# vgextend motadata /dev/sdb1
Volume group "motadata" successfully extended
Using the pvscan command we scan all disks for physical volumes, this should confirm the original /dev/sda5 partition and the newly created physical volume /dev/sdb1
[root@centosdemo ~]# pvscan
PV /dev/sda5 VG centos lvm2 [9.31 GiB / 0 free]
PV /dev/sda2 VG motadata lvm2 [13.97 GiB / 0 free]
PV /dev/sdb1 VG motadata lvm2 [5.00 GiB / 5.00 GiB free]
Total: 3 [28.28 GiB] / in use: 3 [28.28 GiB] / in no VG: 0 [0 ]
Next, we need to increase the logical volume with the lvextend command (rather than the physical volume which we have already done). This means we will be taking our original logical volume and extending it over our new disk/partition/physical volume of /dev/sdb1.
Firstly confirm the name of the logical volume using lvdisplay. The name will vary depending on your setup.
[root@centosdemo ~]# lvdisplay
--- Logical volume ---
LV Path /dev/motadata/motadata
LV Name motadata
VG Name motadata
LV UUID NVvHXi-MvaQ-2zOB-vHVA-9poh-N6MD-PtD4gw
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-09-30 17:31:03 +0530
LV Status available
# open 1
LV Size 13.97 GiB
Current LE 3577
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID kQPUTY-RhUp-dxQV-NcDg-2R9x-MedH-wGdlPS
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-09-30 17:31:02 +0530
LV Status available
# open 1
LV Size 9.31 GiB
Current LE 2384
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
The logical volume is then extended using the lvextend command. We are extending the original logical volume of /dev/motadata/motadata over the newer /dev/sdb1
[root@centosdemo ~]# lvextend /dev/motadata/motadata /dev/sdb1
Size of logical volume motadata/motadata changed from 13.97 GiB (3577 extents) to 18.97 GiB (4856 extents).
Logical volume motadata successfully resized.
If you like you can then run vgdisplay and lvdisplay again to confirm the size of the volume group and logical volume respectively, I have done this and I now have the following.
However, if you run a “df” command to see available disk space it will not have changed yet as there is one final step, we need to resize the file system using the resize2fs command in order to make use of this space.
[root@centosdemo ~]# xfs_growfs /dev/motadata/motadata
meta-data=/dev/mapper/motadata-motadata isize=256 agcount=4, agsize=915712 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=3662848, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 3662848 to 4972544
Alternatively, if you’re facing any error running above command you can also use below command “resize2fs /dev/motadata/motadata”.
Rather than resizing the file system manually, you could instead use the -r option of the lvextend command which will automatically resize the file system to make use of the additional disk space.
The resize took a minute or so to complete (it will depend on the disk speed and size), running the “df” command now shows the correct disk space for /dev/mapper/motadata-motadata.
No comments:
Post a Comment