HostOnNet Blog

Create Volume Group with vgcreate

vgcreate is used to create LVM volume group.

Before we can create a volume group, we need to create physical volume. To list available physical volume, run pvdisplay

If you don’t have a physical volume, create one with pvcreate.

root@server2:~# pvdisplay
  "/dev/md4" is a new physical volume of "1.80 TiB"
  --- NEW Physical volume ---
  PV Name               /dev/md4
  VG Name
  PV Size               1.80 TiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               h1kshf-do9O-y3jn-eVs3-Rl4V-WLeQ-aSYd9h

root@server2:~#

From the above command, we see found we have physical volume with name /dev/md4, lets create a volume group using it.

root@server2:~# vgcreate myVolumeGroup1 /dev/md4
  Volume group "myVolumeGroup1" successfully created
root@server2:~#

Verify volume group created properly with vgdisplay.

root@server2:~# vgdisplay
  --- Volume group ---
  VG Name               myVolumeGroup1
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               1.80 TiB
  PE Size               4.00 MiB
  Total PE              470906
  Alloc PE / Size       0 / 0
  Free  PE / Size       470906 / 1.80 TiB
  VG UUID               o16EQL-mDbw-7yPG-iDcX-lh6X-gWwN-X9TCnT

root@server2:~#

Before we can use LVM, we need to create a logical volume with lvcreate

root@server2:~# lvcreate -L 100G --name dataVolume myVolumeGroup1
WARNING: ext3 signature detected on /dev/myVolumeGroup1/dataVolume at offset 1080. Wipe it? [y/n]: y
  Wiping ext3 signature on /dev/myVolumeGroup1/dataVolume.
  Logical volume "dataVolume" created.
root@server2:~#

List all available logical volumes with

root@server2:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/myVolumeGroup1/dataVolume
  LV Name                dataVolume
  VG Name                myVolumeGroup1
  LV UUID                9oDlaW-gJFc-FmNI-TSYh-XGbu-F6R8-DmTAyK
  LV Write Access        read/write
  LV Creation host, time server2, 2015-12-13 00:14:35 -0500
  LV Status              available
  # open                 0
  LV Size                100.00 GiB
  Current LE             25600
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0

root@server2:~#

Create file system

root@server2:~# mkfs.xfs /dev/myVolumeGroup1/dataVolume
meta-data=/dev/myVolumeGroup1/dataVolume isize=256    agcount=4, agsize=6553600 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=26214400, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=12800, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
root@server2:~#

Here i used xfs file system, for ext4 use mkfs.ext4 command.

mkfs.ext4 /dev/myVolumeGroup1/dataVolume

Now we have LVM ready, mount it with command

root@server2:~# mount /dev/myVolumeGroup1/dataVolume /var/lib/vz/
root@server2:~# df -h
Filesystem                             Size  Used Avail Use% Mounted on
udev                                    10M     0   10M   0% /dev
tmpfs                                   13G  9.1M   13G   1% /run
/dev/md2                                20G  1.7G   17G   9% /
tmpfs                                   32G   25M   32G   1% /dev/shm
tmpfs                                  5.0M     0  5.0M   0% /run/lock
tmpfs                                   32G     0   32G   0% /sys/fs/cgroup
tmpfs                                  100K     0  100K   0% /run/lxcfs/controllers
cgmfs                                  100K     0  100K   0% /run/cgmanager/fs
/dev/fuse                               30M   12K   30M   1% /etc/pve
/dev/mapper/myVolumeGroup1-dataVolume  100G   33M  100G   1% /var/lib/vz
root@server2:~#

To auto mount, add following to /etc/fstab

/dev/mapper/myVolumeGroup1-dataVolume /var/lib/vz       xfs     defaults        1       2

See lvm


Posted in Linux