Extend New Disk to LVM Root Partition

Gabungkan disk baru ke dalam partisi lvm root pada linux, ex: centos7

  • Cek partisi disk dan free space disk pada linux, total size disk SDA sebesar 100GB dan untuk partisi lvm root sebesar 80GB. Ada disk SDB sebesar 100GB yang akan di gabungkan kedalam partisi lvm root. Sehingga nantinya partisi lvm root akan menjadi 180GB.
[root@localhost admin]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  100G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part
  ├─centos-root 253:0    0   80G  0 lvm  /
  ├─centos-swap 253:1    0    4G  0 lvm  [SWAP]
  └─centos-var  253:2    0   15G  0 lvm  /var
sdb               8:16   0  100G  0 disk
sdc               8:32   0   50G  0 disk
sr0              11:0    1 1024M  0 rom
[root@localhost admin]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  232M     0  232M   0% /dev
tmpfs                   tmpfs     244M     0  244M   0% /dev/shm
tmpfs                   tmpfs     244M  4.6M  239M   2% /run
tmpfs                   tmpfs     244M     0  244M   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        80G  1.2G   79G   2% /
/dev/mapper/centos-var  xfs        15G  200M   15G   2% /var
/dev/sda1               xfs      1014M  137M  877M  14% /boot
tmpfs                   tmpfs      49M     0   49M   0% /run/user/1000
[root@localhost admin]#
  • Buat partisi /dev/sdb menjadi physical volume (pvcreate /dev/sdb), Gabungkan partisi /dev/sdb kedalam volume group centos (vgextend centos /dev/sdb), Gabungkan semua free yang ada pada logical volume kedalam partisi lvm root (lvextend -l +100%FREE /dev/centos/root), simpan perubahan table partisi (xfs_growfs /dev/centos/root) jika menggunakan file system ext4 gunakan perintah resize2fs.
  • Cek kembali partisi disk sdb, maka sudah menjadi type lvm dan untuk partisi lvm root sudah menjadi 180GB (gabungan lvm dari sda2 dan sdb)
[root@localhost admin]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.
[root@localhost admin]#
[root@localhost admin]# vgextend centos /dev/sdb
  Volume group "centos" successfully extended
[root@localhost admin]#
[root@localhost admin]# lvextend -l +100%FREE /dev/centos/root
  Size of logical volume centos/root changed from <80.00 GiB (20479 extents) to <180.00 GiB (46079 extents).
  Logical volume centos/root successfully resized.
[root@localhost admin]#
[root@localhost admin]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512    agcount=11, agsize=1966080 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=20971520, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=3840, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 20971520 to 47184896
[root@localhost admin]#
[root@localhost admin]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  100G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part
  ├─centos-root 253:0    0  180G  0 lvm  /
  ├─centos-swap 253:1    0    4G  0 lvm  [SWAP]
  └─centos-var  253:2    0   15G  0 lvm  /var
sdb               8:16   0  100G  0 disk
└─centos-root   253:0    0  180G  0 lvm  /
sdc               8:32   0   50G  0 disk
sr0              11:0    1 1024M  0 rom
[root@localhost admin]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  232M     0  232M   0% /dev
tmpfs                   tmpfs     244M     0  244M   0% /dev/shm
tmpfs                   tmpfs     244M  4.6M  239M   2% /run
tmpfs                   tmpfs     244M     0  244M   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs       180G  1.2G  179G   1% /
/dev/mapper/centos-var  xfs        15G  200M   15G   2% /var
/dev/sda1               xfs      1014M  137M  877M  14% /boot
tmpfs                   tmpfs      49M     0   49M   0% /run/user/1000
[root@localhost admin]#

herdiana3389

A system administrator with skills in system administration, virtualization, linux, windows, networking, cloud computing, container, etc.