Skip to content

Instantly share code, notes, and snippets.

@JayaByu
Last active August 14, 2023 08:11
Show Gist options
  • Save JayaByu/b36d3fb335d85bd45a86eb353528e603 to your computer and use it in GitHub Desktop.
Save JayaByu/b36d3fb335d85bd45a86eb353528e603 to your computer and use it in GitHub Desktop.

LVM Uses

Install Requires

In Case i use Debian based

~: sudo apt-get install lvm2 -y

if use lvm package

~: sudo dpkg -i /path/lvm2.deb

if you using Arch based

~: sudo pacman -S lvm2

if you using RHEL/Oracle/CentOS

~: sudo yum install lvm2

After installing requirement u can use lvm on ur lab

check are u already insert ur disk? wth iscsi of something else

~: sudo fdisk -l

then select your disk, who want to be ur LVM disk it's (sd?)

create disk partition in case i use (sda) disk

~: sudo fdisk /dev/sda

inside fdisk /dev/sda

: m (to help)
: n (to create new partition)
: p (to create as primary disk)
: i press enter at this section (Partition number), (First Sector), (Last Sector)
: t (to change Linux type to LVM)
: Hex code type (8) for LVM 
: w (to write your new partition)

LVM Structure

remember in my case i use /dev/sda then i create partition so the partition must be /dev/sda1

PV [Pysical Volume] root@artemis : /dev/sda1

VG [Virtual Group] root@artemis : datavg

LV [Logical Volume] root@artemis : /dev/datavg/datalv

File System root@artemis : /mnt/dataLVM

Create PV

:~ pvcreate /dev/sda1

Display PV

:~ pvdisplay

  --- Physical volume ---
  PV Name               /dev/sda1
  VG Name               olympus
  PV Size               1.33 TiB / not usable 7.00 TiB
  Allocatable           yes
  PE Size               7.00 TiB
  Total PE              428130
  Free PE               1
  Allocated PE          428129
  PV UUID               d7fX0h-Eko9-XH64-fqRX-0mjd-g7pp-j1bk08
  

or

:~ pvs -v

PV         VG       Fmt   Attr  PSize     PFree   DevSize  PV UUID
/dev/sda1  olympus  lvm2  a--   1.33t     7.00m   1.33t    d7fX0h-Eko9-XH64-fqRX-0mjd-g7pp-j1bk08

Create VG

:~ vgcreate olympus /dev/sda1

Display VG

:~ vgdisplay

  --- Volume group ---
  VG Name               olympus
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  8
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               1.33 TiB
  PE Size               7.00 MiB
  Total PE              728130
  Alloc PE / Size       728129 / 1.33 TiB
  Free  PE / Size       1 / 7.00 MiB
  VG UUID               UT9UjE-PVPy-JXeU-RfM4-e7mh-1Wl4-JnMe8e

or

:~ vgs -v 

VG      Attr   Ext   #PV #LV #SN VSize  VFree   VG UUID                                VProfile
olympus wz--n- 7.00m   1   3   0 1.63t  7.00m   UT9UjE-PVPy-JXeU-RfM4-e7mh-1Wl4-JnMe8e

Create LV

:~ lvcreate -L450G olympus[vg] -n artemis[lv]

Format the new LVM

:~ mkfs.ext4 /dev/olympus/artemis

Then

Mount to another filesystem

sudo mount -t ext4 /dev/olympus/artemis /path/path

Reload systemd

:~ systemctl daemon-reload

Check if already created or not

:~ lsblk 

sda                 8:16   0  500G  0 disk
└─sda1              8:17   0  500G  0 part
  └─olympus-artemis 253:3  0  450G  0 lvm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment