# Extend Root Filesystem Using LVM on Linux
Periksa langkah-langkah di bawah ini untuk memperluas sistem file root menggunakan LVM di Linux.
Anda dapat melewati beberapa langkah yang tidak perlu digunakan.
*Source:*
https://computingforgeeks.com/extending-root-filesystem-using-lvm-linux/
## Langkah 1: Konfirmasi Partisi Disk Dalam Distribusi
1. Konfirmasi *disk layout / partitioning scheme* sebelum melakukan ekstensi
```
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 30G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 29G 0 part
├─rhel-root 253:0 0 26.9G 0 lvm /
└─rhel-swap 253:1 0 2.1G 0 lvm [SWAP]
```
Seperti disebutkan, kita memiliki *root filesystem* di *physical volume* `/dev/vda2`.
```
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 rhel lvm2 a-- <29.00g 0
```
## Langkah 2: Tingkatkan Kapasitas OS *Root Disk* Anda
1. Seperti yang terlihat pada langkah 1, *root filesystem* yang digunakan adalah 30GB dan akan ditingkatkan menjadi 40GB dengan memperluas *virtual disk (VM Disk Device)*
Teknologi virtualisasi yang digunakan pada tutorial ini adalah *KVM Virtualization Technology*
```
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 40G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 29G 0 part
├─rhel-root 253:0 0 26.9G 0 lvm /
└─rhel-swap 253:1 0 2.1G 0 lvm [SWAP]
```
2. Install Cloud Utils
Ini adalah baris perintah Linux yang digunakan untuk memperluas partisi dalam tabel partisi untuk mengisi ruang yang tersedia.
Untuk Menjalankan Pada Ubuntu/Debian System:
```
sudo apt -y install cloud-guest-utils
```
Untuk Menjalankan Pada CentOS server:
```
sudo yum -y install cloud-utils-growpart
```
Halaman bantuan dapat dilihat dengan menggunakan argumen `-h`
```
# growpart -h
growpart disk partition
rewrite partition table so that partition takes up all the space it can
options:
-h | --help print Usage and exit
--fudge F if part could be resized, but change would be
less than 'F' bytes, do not resize (default: 1048576)
-N | --dry-run only report what would be done, show new 'sfdisk -d'
-v | --verbose increase verbosity / debug
-u | --update R update the the kernel partition table info after growing
this requires kernel support and 'partx --update'
R is one of:
- 'auto' : [default] update partition if possible
- 'force' : try despite sanity checks (fail on failure)
- 'off' : do not attempt
- 'on' : fail if sanity checks indicate no support
Example:
- growpart /dev/sda 1
Resize partition 1 on /dev/sd
```
Selanjutnya gunakan *growpart* untuk meningkatkan partisi
```
$ sudo growpart /dev/vda 2
CHANGED: partition=2 start=2099200 old: size=18872320 end=20971520 new: size=60815327,end=62914527
```
Ini akan mengubah ukuran partisi 2 di `/dev/vda`
Kemudian validasi perubahannya
```
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 252:0 0 40G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 39G 0 part
├─rhel-root 253:0 0 26.9G 0 lvm /
└─rhel-swap 253:1 0 2.1G 0 lvm [SWAP]
```
## Langkah 3: Ubah Ukuran *root logical volume* untuk mengisi seluruh ruang
1. Ubah ukuran *physical volume*
```
$ sudo pvresize /dev/vda2
Physical volume "/dev/vda2" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 rhel lvm2 a-- <39.00g 10.00g
```
2. Periksa ukuran grup volume yang dikonfigurasi
```
$ sudo vgs
```
Hasil:
```
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz - n- <39.00g 10.00g
```
3. Kemudian ubah ukuran *root logical volume* dengan menggunakan ukuran grup volume yang sudah diubah
```
sudo lvextend -l +100%FREE /dev/name-of-volume-group/root
```
4. Dalam tutorial ini akan menjadi seperti berikut:
```
$ df -hT | grep mapper
/dev/mapper/rhel-root xfs 27G 1.9G 26G 8% /
$ sudo lvextend -l +100%FREE /dev/mapper/rhel-root
Size of logical volume rhel/root changed from <26.93 GiB (6893 extents) to <36.93 GiB (9453 extents).
Logical volume rhel/root successfully resized.
```
Anda dapat mengubah perintah `100%FREE` dengan pilihan MB yang sesuai dengan kebutuhan, misalnya untuk menambahkan 256MB, maka ganti dengan `+256M`
## Langkah 4: Perbarui Perubahan Pada Filesystem
1. *Root Filesystem* Anda akan tetap menampilkan ukuran lama
```
$ df -hT | grep mapper
/dev/mapper/rhel-root xfs 27G 1.9G 26G 8% /
```
2. Untuk membuat filesystem melaporkan ukurannya termasuk ukuran yang sudah ditingkatkan, dengan cara:
Untuk *ext4 filesystem:*
```
sudo resize2fs /dev/name-of-volume-group/root
```
Untuk *xsf filesystem:*
```
$ sudo xfs_growfs /
meta-data =/dev/mapper/rhel-root isize=512 agcount=4, agsize=1764608 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=7058432, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=3446, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 7058432 to 9679872