Tuesday, September 28, 2021

thumbnail

How to extend an LVM partition in Linux

 How to extend LVM based filesystem



To increase the space for LVM partition follow the steps given below:

1. Verify availability of the new space.

# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  500G  0 disk 
\u251c\u2500sda1            8:1    0  512M  0 part /boot
\u251c\u2500sda2            8:2    0 29.5G  0 part 
\u2502 \u251c\u2500centos-root 253:0    0  799G  0 lvm  /
\u2502 \u2514\u2500centos-swap 253:1    0  512M  0 lvm  [SWAP]
\u251c\u2500sda3            8:3    0  220G  0 part 
\u2502 \u2514\u2500centos-root 253:0    0  799G  0 lvm  /
\u2514\u2500sda4            8:4    0  250G  0 part 
  \u2514\u2500centos-root 253:0    0  799G  0 lvm  /
sdb               8:16   0  100G  0 disk 
\u2514\u2500sdb1            8:17   0  100G  0 part 
  \u2514\u2500centos-root 253:0    0  799G  0 lvm  /
sdc               8:32   0  200G  0 disk 
\u2514\u2500sdc1            8:33   0  200G  0 part 
  \u2514\u2500centos-root 253:0    0  799G  0 lvm  /
sdd               8:48   0  200G  0 disk 
sr0              11:0    1 1024M  0 rom 

2. Create additional partition for the new swap partition.

# fdisk /dev/sdd
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x165e0fac.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-419430399, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399): 
Using default value 419430399
Partition 1 of type Linux and of size 200 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdd: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x165e0fac

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1            2048   419430399   209714176   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

3. Activate the new partition.

# partprobe

4. Verify the new partition is available.

# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  500G  0 disk 
\u251c\u2500sda1            8:1    0  512M  0 part /boot
\u251c\u2500sda2            8:2    0 29.5G  0 part 
\u2502 \u251c\u2500centos-root 253:0    0  799G  0 lvm  /
\u2502 \u2514\u2500centos-swap 253:1    0  512M  0 lvm  [SWAP]
\u251c\u2500sda3            8:3    0  220G  0 part 
\u2502 \u2514\u2500centos-root 253:0    0  799G  0 lvm  /
\u2514\u2500sda4            8:4    0  250G  0 part 
  \u2514\u2500centos-root 253:0    0  799G  0 lvm  /
sdb               8:16   0  100G  0 disk 
\u2514\u2500sdb1            8:17   0  100G  0 part 
  \u2514\u2500centos-root 253:0    0  799G  0 lvm  /
sdc               8:32   0  200G  0 disk 
\u2514\u2500sdc1            8:33   0  200G  0 part 
  \u2514\u2500centos-root 253:0    0  799G  0 lvm  /
sdd               8:48   0  200G  0 disk 
\u2514\u2500sdd1            8:49   0  200G  0 part 
sr0              11:0    1 1024M  0 rom 

Note: a reboot may be needed if the change does not show at this point.

5. Create a new physical volume on the LUN.

# pvcreate /dev/sdd1

6. Add the new volume to the volume group for the swap volume. Our examples use centos and /dev/sdd1; replace with the volume names and devices as appropriate to your deployment.

# vgextend centos /dev/sdd1

7. Using vgdisplay command we can find out available Free PE(Physical Extents)/ Size

# vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        6
  Metadata Sequence No  12
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                6
  Act PV                6
  VG Size               <999.48 GiB
  PE Size               4.00 MiB
  Total PE              255866
  Alloc PE / Size       204667 / 799.48 GiB
  Free  PE / Size       51199 / <200.00 GiB
  VG UUID               s9r38a-nQQX-eDR7-l9AW-PiTV-xW6i-o6H4rg

8. Resize the logical volume to the desired size.

# lvextend -l +51199 /dev/centos/root
  Size of logical volume centos/root changed from 798.98 GiB (204539 extents) to <998.98 GiB (255738 extents).
  Logical volume centos/root successfully resized.

9. Format the extended volume for xfs file system. use "resize2fs /dev/centos/root"

# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512    agcount=111, agsize=1900288 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=209447936, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=3711, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 209447936 to 261875712

10. Enable the logical volume.

# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  500G  0 disk 
\u251c\u2500sda1            8:1    0  512M  0 part /boot
\u251c\u2500sda2            8:2    0 29.5G  0 part 
\u2502 \u251c\u2500centos-root 253:0    0  999G  0 lvm  /
\u2502 \u2514\u2500centos-swap 253:1    0  512M  0 lvm  [SWAP]
\u251c\u2500sda3            8:3    0  220G  0 part 
\u2502 \u2514\u2500centos-root 253:0    0  999G  0 lvm  /
\u2514\u2500sda4            8:4    0  250G  0 part 
  \u2514\u2500centos-root 253:0    0  999G  0 lvm  /
sdb               8:16   0  100G  0 disk 
\u2514\u2500sdb1            8:17   0  100G  0 part 
  \u2514\u2500centos-root 253:0    0  999G  0 lvm  /
sdc               8:32   0  200G  0 disk 
\u2514\u2500sdc1            8:33   0  200G  0 part 
  \u2514\u2500centos-root 253:0    0  999G  0 lvm  /
sdd               8:48   0  200G  0 disk 
\u2514\u2500sdd1            8:49   0  200G  0 part 
  \u2514\u2500centos-root 253:0    0  999G  0 lvm  /
sr0              11:0    1 1024M  0 rom  

11. View the new size.

# df -h /
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  999G  755G  245G  76% /

Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments

Powered by Blogger.