Skip to main content
  1. Posts/

Cara membuat Logical Volume (LVM)

3 mins
lvm linux lvm
Table of Contents

LVM adalah sebuah manajemen penyimpan di sistem operasi GNU/Linux yang menyediakan fleksibilitas dalam membuat dan mengubah partisi dalam sebuah disk.

Buat partisi LVM
#

Sebelum memulai, pastikan anda sudah menyiapkan space kosong untuk membuat partisi LVM atau hdd baru untuk ditambahkan ke physical volume pada LVM

root@ubuntu:~# fdisk  /dev/vdb

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p
Disk /dev/vdb: 3 GiB, 3221225472 bytes, 6291456 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
Disklabel type: gpt
Disk identifier: A01CA716-11FF-42B7-B0F3-8A6E9FF8CE6F

Device     Start    End Sectors  Size Type
/dev/vdb14  2048  10239    8192    4M BIOS boot
/dev/vdb15 10240 227327  217088  106M EFI System

Buat partisinya

Command (m for help): n
Partition number (1-13,16-128, default 1):
First sector (34-6291422, default 227328):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (227328-6291422, default 6291422):

Created a new partition 1 of type 'Linux filesystem' and of size 2.9 GiB.

Setting type partisi ke Linux LVM

Command (m for help): t
Partition number (1,14,15, default 15): 1
Partition type or alias (type L to list all): L
...
 25 Linux root (ARM-64)            B921B045-1DF0-41C3-AF44-4C6F280D3FAE
 26 Linux root (IA-64)             993D8D3D-F80E-4225-855A-9DAF8ED7EA97
 27 Linux reserved                 8DA63339-0007-60C0-C436-083AC8230908
 28 Linux home                     933AC7E1-2EB4-4F13-B844-0E14E2AEF915
 29 Linux RAID                     A19D880F-05FC-4D3B-A006-743F0F84911E
 30 Linux LVM                      E6D6D379-F507-44C2-A23C-238F2A3DF928
 31 Linux variable data            4D21B016-B534-45C2-A9FB-5C16E091FD2D
 32 Linux temporary data           7EC6F557-3BC5-4ACA-B293-16EF5DF639D1
 33 Linux /usr (x86)               75250D76-8CC6-458E-BD66-BD47CC81A812
 34 Linux /usr (x86-64)            8484680C-9521-48C6-9C11-B0720656F69E
 35 Linux /usr (ARM)               7D0359A3-02B3-4F0A-865C-654403E70625
Partition type or alias (type L to list all): 30

Changed type of partition 'Linux filesystem' to 'Linux LVM'.

Cek partisi apakah berhasil terbuat dan Write agar partisi yang dibuat tersimpan

Command (m for help): p
Disk /dev/vdb: 3 GiB, 3221225472 bytes, 6291456 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
Disklabel type: gpt
Disk identifier: A01CA716-11FF-42B7-B0F3-8A6E9FF8CE6F

Device      Start     End Sectors  Size Type
/dev/vdb1  227328 6291422 6064095  2.9G Linux LVM
/dev/vdb14   2048   10239    8192    4M BIOS boot
/dev/vdb15  10240  227327  217088  106M EFI System

Partition table entries are not in disk order.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Buat physical volume [PV]
#

pvcreate /dev/vdb1
root@ubuntu:~# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created.

Buat volume group [VG]
#

vgcreate -Ay vg_root /dev/vdb1
root@ubuntu:~# vgcreate -Ay vg_root /dev/vdb1
  Volume group "vg_root" successfully created

Buat logical volume [LV]
#

Saya alokasikan semua free space partisi 2.9 GiB ke LV

lvcreate -Ay -l 100%FREE -n root vg_root
root@ubuntu:~# lvcreate -Ay -l 100%FREE -n root vg_root
  Logical volume "root" created.

Cek info PV, VG, dan LV
#

root@ubuntu:~# pvs
  PV         VG      Fmt  Attr PSize  PFree
  /dev/vdb1  vg_root lvm2 a--  <2.89g    0

root@ubuntu:~# vgs
  VG      #PV #LV #SN Attr   VSize  VFree
  vg_root   1   1   0 wz--n- <2.89g    0

root@ubuntu:~# lvs
  LV   VG      Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root vg_root -wi-a----- <2.89g

Format LV
#

Terakhir kalian bisa format sesuai tipe filesystem yang diinginkan

mkfs.xfs /dev/mapper/vg_root-root

Related

Meningkatkan Kinerja Disk dengan LVM Cache
3 mins
lvm linux lvm
Menambah Space Logical Volume pada LVM
3 mins
lvm lvm
Migrasi OS Ubuntu ke LVM
3 mins
ubuntu linux ubuntu lvm
How to Copy Text in Tmux to System Clipboard
3 mins
tmux linux tmux
Install GSocket di Linux
2 mins
gsocket linux gsocket
How to Configure cGroups v2 on Linux
2 mins
linux linux