Konfigurasi Data Nusantara

LinuxUbuntu

Create, Add, Remove LVM disk

Hi…

Kali ini kita akan coba create, add dan remove LVM disk di Ubuntu.

Pertama, kita pastikan dulu disk sudah terpasang dengan benar pada server

root@konfigurasi:/home/ubuntu# fdisk -l

Disk /dev/vda: 17.2 GB, 17179869184 bytes
4 heads, 32 sectors/track, 262144 cylinders, total 33554432 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 identifier: 0x0007eb44

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 33554431 16776192 83 Linux

Disk /dev/vdb: 5368 MB, 5368709120 bytes
16 heads, 63 sectors/track, 10402 cylinders, total 10485760 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 identifier: 0x00000000

Disk /dev/vdb doesn't contain a valid partition table
Disk /dev/vdc: 12.9 GB, 12884901888 bytes
16 heads, 63 sectors/track, 24966 cylinders, total 25165824 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 identifier: 0x00000000

Disk /dev/vdc doesn't contain a valid partition table

Terlihat bahwa pada server ada 3 disk, yaitu vda yang berisi file-file system, kemudian vdb dan vdc yang baru saja kita tambahkan disknya. Selanjutnya, kita install dulu LVM

root@konfigurasi:/home/ubuntu# apt-get install lvm2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libdevmapper-event1.02.1 libreadline5 watershed
Suggested packages:
thin-provisioning-tools
The following NEW packages will be installed:
libdevmapper-event1.02.1 libreadline5 lvm2 watershed
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 622 kB of archives.
After this operation, 1,797 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://nova.clouds.archive.ubuntu.com/ubuntu/ trusty/main libdevmapper-event1.02.1 amd64 2:1.02.77-6ubuntu2 [10.8 kB]
Get:2 http://nova.clouds.archive.ubuntu.com/ubuntu/ trusty/main libreadline5 amd64 5.2+dfsg-2 [130 kB]
Get:3 http://nova.clouds.archive.ubuntu.com/ubuntu/ trusty/main watershed amd64 7 [11.4 kB]
Get:4 http://nova.clouds.archive.ubuntu.com/ubuntu/ trusty/main lvm2 amd64 2.02.98-6ubuntu2 [470 kB]
Fetched 622 kB in 2s (209 kB/s)
Selecting previously unselected package libdevmapper-event1.02.1:amd64.
(Reading database ... 51163 files and directories currently installed.)
Preparing to unpack .../libdevmapper-event1.02.1_2%3a1.02.77-6ubuntu2_amd64.deb ...
Unpacking libdevmapper-event1.02.1:amd64 (2:1.02.77-6ubuntu2) ...
Selecting previously unselected package libreadline5:amd64.
Preparing to unpack .../libreadline5_5.2+dfsg-2_amd64.deb ...
Unpacking libreadline5:amd64 (5.2+dfsg-2) ...
Selecting previously unselected package watershed.
Preparing to unpack .../archives/watershed_7_amd64.deb ...
Unpacking watershed (7) ...
Selecting previously unselected package lvm2.
Preparing to unpack .../lvm2_2.02.98-6ubuntu2_amd64.deb ...
Unpacking lvm2 (2.02.98-6ubuntu2) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up libdevmapper-event1.02.1:amd64 (2:1.02.77-6ubuntu2) ...
Setting up libreadline5:amd64 (5.2+dfsg-2) ...
Setting up watershed (7) ...
update-initramfs: deferring update (trigger activated)
Setting up lvm2 (2.02.98-6ubuntu2) ...
update-initramfs: deferring update (trigger activated)
Processing triggers for libc-bin (2.19-0ubuntu6.7) ...
Processing triggers for initramfs-tools (0.103ubuntu4.2) ...
update-initramfs: Generating /boot/initrd.img-3.13.0-83-generic

CREATE LVM
Kita create Physical Volume dan Volume Groupnya

root@konfigurasi:/home/ubuntu# pvcreate /dev/vdb
Physical volume "/dev/vdb" successfully created
root@konfigurasi:/home/ubuntu# vgcreate vgkonfigurasi /dev/vdb
Volume group "vgkonfigurasi" successfully created

Selanjutnya create Logical Volume nya

root@konfigurasi:/home/ubuntu# lvcreate -L 4.9G -n lvkonfigurasi vgkonfigurasi
Rounding up size to full physical extent 4.90 GiB
Logical volume "lvkonfigurasi" created

Selanjutnya, kita buat filesystemnya

root@konfigurasi:/home/ubuntu# mkfs -t ext3 /dev/vgkonfigurasi/lvkonfigurasi

mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
321280 inodes, 1285120 blocks
64256 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1317011456
40 block groups
32768 blocks per group, 32768 fragments per group
8032 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Setelah itu, bikin directory dan mount lvkonfigurasi ke directory tersebut

root@konfigurasi:/home/ubuntu# mkdir /konfigurasi

root@konfigurasi:/home/ubuntu# mount -t ext3 /dev/vgkonfigurasi/lvkonfigurasi /konfigurasi/

Cek lagi disknya

root@konfigurasi:/home/ubuntu# df -h
Filesystem Size Used Avail Use% Mounted on
udev 493M 12K 493M 1% /dev
tmpfs 100M 356K 100M 1% /run
/dev/disk/by-label/cloudimg-rootfs 16G 787M 15G 6% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 497M 0 497M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/mapper/vgkonfigurasi-lvkonfigurasi 4.8G 10M 4.5G 1% /konfigurasi

ADD DISK

Sekarang kita coba tambahkan disk lain (vdc) ke LVM yang telah kita buat sebelumnya. Berikut command command nya

Create Physical Volume

root@konfigurasi:/home/ubuntu# pvcreate /dev/vdc
Physical volume "/dev/vdc" successfully created

Cek LVM disk

root@konfigurasi:/home/ubuntu# lvmdiskscan -l
WARNING: only considering LVM devices
/dev/vdb [ 5.00 GiB] LVM physical volume
/dev/vdc [ 12.00 GiB] LVM physical volume
2 LVM physical volume whole disks
0 LVM physical volumes

Tambahkan vdc ke Volume Group yang sudah dibuat, yaitu vgkonfigurasi

root@konfigurasi:/home/ubuntu# vgextend vgkonfigurasi /dev/vdc
Volume group "vgkonfigurasi" successfully extended

Extend atau tambahkan size disk yang baru ke LVM

root@konfigurasi:/home/ubuntu# lvm lvextend -l +100%FREE /dev/vgkonfigurasi/lvkonfigurasi
Extending logical volume lvkonfigurasi to 16.99 GiB
Logical volume lvkonfigurasi successfully resized

Cek dulu, apakah disk sizenya sudah nambah? Ternyata belum, satu langkah lagi

root@konfigurasi:/home/ubuntu# df -h
Filesystem Size Used Avail Use% Mounted on
udev 493M 12K 493M 1% /dev
tmpfs 100M 356K 100M 1% /run
/dev/disk/by-label/cloudimg-rootfs 16G 787M 15G 6% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 497M 0 497M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/mapper/vgkonfigurasi-lvkonfigurasi 4.8G 10M 4.5G 1% /konfigurasi

Resize vgkonfigurasi-lvkonfigurasi

root@konfigurasi:/home/ubuntu# resize2fs -p /dev/mapper/vgkonfigurasi-lvkonfigurasi
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/mapper/vgkonfigurasi-lvkonfigurasi is mounted on /konfigurasi; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/mapper/vgkonfigurasi-lvkonfigurasi is now 4454400 blocks long.

Cek lagi, apakah sudah nambah kapasitas disknya?

root@konfigurasi:/home/ubuntu# df -h
Filesystem Size Used Avail Use% Mounted on
udev 493M 12K 493M 1% /dev
tmpfs 100M 356K 100M 1% /run
/dev/disk/by-label/cloudimg-rootfs 16G 787M 15G 6% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 497M 0 497M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/mapper/vgkonfigurasi-lvkonfigurasi 17G 14M 16G 1% /konfigurasi

REMOVE DISK FROM LVM

Sekarang kita lanjut ke remove disk yang tadi kita tambahkan

Cek Physical Volume

root@konfigurasi:/home/ubuntu# pvs -o+pv_used
PV VG Fmt Attr PSize PFree Used
/dev/vdb vgkonfigurasi lvm2 a-- 5.00g 0 5.00g
/dev/vdc vgkonfigurasi lvm2 a-- 12.00g 0 12.00g

Sebelum diremove, umount dulu directory /konfigurasi

root@konfigurasi:/home/ubuntu# umount /konfigurasi/

Check Volume Group dan LVM

root@konfigurasi:/home/ubuntu# e2fsck -f /dev/mapper/vgkonfigurasi-lvkonfigurasi
e2fsck 1.42.9 (4-Feb-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vgkonfigurasi-lvkonfigurasi: 11/1092352 files (0.0% non-contiguous), 104816/4454400 blocks

Resize LVM size

root@konfigurasi:/home/ubuntu# lvreduce -L 4.8G /dev/vgkonfigurasi/lvkonfigurasi
Rounding size to boundary between physical extents: 4.80 GiB
WARNING: Reducing active logical volume to 4.80 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lvkonfigurasi? [y/n]: y
Reducing logical volume lvkonfigurasi to 4.80 GiB
Logical volume lvkonfigurasi successfully resized

Lepas Disk pada Volume Group

root@konfigurasi:/home/ubuntu# vgreduce vgkonfigurasi /dev/vdc
Removed "/dev/vdc" from volume group "vgkonfigurasi"

root@konfigurasi:/home/ubuntu# pvremove /dev/vdc
Labels on physical volume "/dev/vdc" successfully wiped

Buat filesystemnya

root@konfigurasi:/home/ubuntu# mkfs -t ext3 /dev/vgkonfigurasi/lvkonfigurasi
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
315120 inodes, 1258496 blocks
62924 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1291845632
39 block groups
32768 blocks per group, 32768 fragments per group
8080 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Selanjutnya mount kembali di directory /konfigurasi

root@konfigurasi:/home/ubuntu# mount -t ext3 /dev/vgkonfigurasi/lvkonfigurasi /konfigurasi
root@konfigurasi:/home/ubuntu# df -h
Filesystem Size Used Avail Use% Mounted on
udev 493M 12K 493M 1% /dev
tmpfs 100M 356K 100M 1% /run
/dev/disk/by-label/cloudimg-rootfs 16G 787M 15G 6% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 497M 0 497M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/mapper/vgkonfigurasi-lvkonfigurasi 4.7G 9.8M 4.4G 1% /konfigurasi

Terakhir resize size disknya

root@konfigurasi:/home/ubuntu# lvm lvextend -l +100%FREE /dev/vgkonfigurasi/lvkonfigurasi
Extending logical volume lvkonfigurasi to 5.00 GiB
Logical volume lvkonfigurasi successfully resized

root@konfigurasi:/home/ubuntu# df -h
Filesystem Size Used Avail Use% Mounted on
udev 493M 12K 493M 1% /dev
tmpfs 100M 356K 100M 1% /run
/dev/disk/by-label/cloudimg-rootfs 16G 787M 15G 6% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 497M 0 497M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/mapper/vgkonfigurasi-lvkonfigurasi 4.7G 9.8M 4.4G 1% /konfigurasi

root@konfigurasi:/home/ubuntu# resize2fs -p /dev/mapper/vgkonfigurasi-lvkonfigurasi
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/mapper/vgkonfigurasi-lvkonfigurasi is mounted on /konfigurasi; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/vgkonfigurasi-lvkonfigurasi is now 1309696 blocks long.

root@konfigurasi:/home/ubuntu# df -h
Filesystem Size Used Avail Use% Mounted on
udev 493M 12K 493M 1% /dev
tmpfs 100M 356K 100M 1% /run
/dev/disk/by-label/cloudimg-rootfs 16G 787M 15G 6% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 497M 0 497M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/mapper/vgkonfigurasi-lvkonfigurasi 4.8G 9.8M 4.6G 1% /konfigurasi

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.