Quantcast
Channel: Linux – IT Pings!
Viewing all articles
Browse latest Browse all 11

How to Add Physical Disk to Increase Size of /dev/mapper/centos-root

$
0
0

Dear Friends,

I ran into a problem where my openstack machine ran out of space. My Logical FS /dev/mapper/centos-root was only 50GB and most of the space was lost.

Solution:
LVM

I Added a new 500GB HDD (sdb), created partition with parted (sdb1) and gave the below commands:

[root@stack opt]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created

Next Check your Volumes with “vgdisplay” command

[root@stack opt]# vgdisplay 
 --- Volume group ---
 VG Name centos
 System ID 
 Format lvm2
 Metadata Areas 1
 Metadata Sequence No 4
 VG Access read/write
 VG Status resizable
 MAX LV 0
 Cur LV 3
 Open LV 3
 Max PV 0
 Cur PV 1
 Act PV 1
 VG Size 465.27 GiB
 PE Size 4.00 MiB
 Total PE 119109
 Alloc PE / Size 119109 / 465.27 GiB
 Free PE / Size 0 / 0 
 VG UUID TrvUI3-Xt7U-6vzF-5RtW-OfK0-OCOy-Tejrb6
 
 --- Volume group ---
 VG Name cinder-volumes
 System ID 
 Format lvm2
 Metadata Areas 1
 Metadata Sequence No 5
 VG Access read/write
 VG Status resizable
 MAX LV 0
 Cur LV 0
 Open LV 0
 Max PV 0
 Cur PV 1
 Act PV 1
 VG Size 20.60 GiB
 PE Size 4.00 MiB
 Total PE 5273
 Alloc PE / Size 0 / 0 
 Free PE / Size 5273 / 20.60 GiB
 VG UUID 9LDtLm-52Un-1QJA-yc3q-13vE-LqEc-hX0kiU

From above you can see that i have two volume groups: “centos” and “cinder-volumes”

Then i extended my centos volume by the below command:

[root@stack opt]# vgextend centos /dev/sdb1
 Volume group "centos" successfully extended

Then issue the pvscan command:

[root@stack opt]# pvscan 
 PV /dev/sda2 VG centos lvm2 [465.27 GiB / 0 free]
 PV /dev/sdb1 VG centos lvm2 [465.76 GiB / 465.76 GiB free]
 PV /dev/loop1 VG cinder-volumes lvm2 [20.60 GiB / 20.60 GiB free]
 Total: 3 [951.62 GiB] / in use: 3 [951.62 GiB] / in no VG: 0 [0 ]

Issue the lvdisplay command to list the logical volumes

[root@stack opt]# lvdisplay 
 --- Logical volume ---
 LV Path /dev/centos/swap
 LV Name swap
 VG Name centos
 LV UUID UOe0cx-ruLe-pD31-dLP0-bPEW-ePYb-Gc5da7
 LV Write Access read/write
 LV Creation host, time localhost, 2017-06-21 11:10:40 +0600
 LV Status available
 # open 2
 LV Size 11.76 GiB
 Current LE 3010
 Segments 1
 Allocation inherit
 Read ahead sectors auto
 - currently set to 8192
 Block device 253:0
 
 --- Logical volume ---
 LV Path /dev/centos/home
 LV Name home
 VG Name centos
 LV UUID TTSL4v-dBZ4-CAFd-2pxK-ev4B-38Zj-LVeX2s
 LV Write Access read/write
 LV Creation host, time localhost, 2017-06-21 11:10:41 +0600
 LV Status available
 # open 1
 LV Size 403.51 GiB
 Current LE 103299
 Segments 1
 Allocation inherit
 Read ahead sectors auto
 - currently set to 8192
 Block device 253:2
 
 --- Logical volume ---
 LV Path /dev/centos/root
 LV Name root
 VG Name centos
 LV UUID U63MqA-Sadu-zxFb-Nyy7-kkDO-N4uj-c3iodO
 LV Write Access read/write
 LV Creation host, time localhost, 2017-06-21 11:10:43 +0600
 LV Status available
 # open 1
 LV Size 50.00 GiB
 Current LE 12800
 Segments 1
 Allocation inherit
 Read ahead sectors auto
 - currently set to 8192
 Block device 253:1

For me the interesting LV was

— Logical volume —
LV Path /dev/centos/root

Then i issued the lvextend command on this Logical Volume

[root@stack opt]# lvextend /dev/centos/root /dev/sdb1
 Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 515.76 GiB (132034 extents).
 Logical volume centos/root successfully resized.

df command will not show the change at this moment

[root@stack opt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 50G 31G 20G 62% /
devtmpfs 12G 0 12G 0% /dev
tmpfs 12G 4.0K 12G 1% /dev/shm
tmpfs 12G 505M 12G 5% /run
tmpfs 12G 0 12G 0% /sys/fs/cgroup
/dev/loop0 1.9G 6.1M 1.7G 1% /srv/node/swiftloopback
/dev/sda1 494M 161M 334M 33% /boot
/dev/mapper/centos-home 404G 33M 404G 1% /home
tmpfs 2.4G 0 2.4G 0% /run/user/1000

Changes will take effect after you issue the resize command. Since i am using XFS therefore i will use the xfs_growfs command to resize the disk

[root@stack opt]# xfs_growfs /dev/centos/root 
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=3276800 blks
 = sectsz=4096 attr=2, projid32bit=1
 = crc=0 finobt=0 spinodes=0
data = bsize=4096 blocks=13107200, imaxpct=25
 = sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=6400, version=2
 = sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13107200 to 135202816

Now we will issue the df command to check if the drive space is increased.

[root@stack opt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 516G 31G 485G 6% /
devtmpfs 12G 0 12G 0% /dev
tmpfs 12G 4.0K 12G 1% /dev/shm
tmpfs 12G 505M 12G 5% /run
tmpfs 12G 0 12G 0% /sys/fs/cgroup
/dev/loop0 1.9G 6.1M 1.7G 1% /srv/node/swiftloopback
/dev/sda1 494M 161M 334M 33% /boot
/dev/mapper/centos-home 404G 33M 404G 1% /home
tmpfs 2.4G 0 2.4G 0% /run/user/1000
[root@stack opt]#

Great we can see that the size has been increased from 50GB to 516GB. Thanks to LVM.

Thanks & Best Regards,

Salman A. Francis
YouTube: LinuxKing
Facebook: LinuxKing, LZHProject, LinuxZeroToHero


Viewing all articles
Browse latest Browse all 11

Trending Articles