LoginSignup
0
0

More than 5 years have passed since last update.

How to create larger resouce (disk, mem, cpu) of CentOS7/LVM VM by vagrant-libvirt

Last updated at Posted at 2019-04-12

How to create larger resouce (disk, mem, cpu) of CentOS7/LVM VM by vagrant-libvirt

 This diagram gives a overview of the main elements in an LVM system:

+-- Volume Group --------------------------------+
|                                                |
|    +----------------------------------------+  |
| PV | PE |  PE | PE | PE | PE | PE | PE | PE |  |
|    +----------------------------------------+  |
|      .          .          .        .          |
|      .          .          .        .          |
|    +----------------------------------------+  |
| LV | LE |  LE | LE | LE | LE | LE | LE | LE |  |
|    +----------------------------------------+  |
|            .          .        .         .     |
|            .          .        .         .     |
|    +----------------------------------------+  |
| PV | PE |  PE | PE | PE | PE | PE | PE | PE |  |
|    +----------------------------------------+  |
|                                                |
+------------------------------------------------+

System

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"
$ vagrant --version
Vagrant 1.8.1
$ vagrant plugin list
fog-libvirt (0.0.3)
  - Version Constraint: 0.0.3
vagrant-libvirt (0.0.35)

Configure Vagrantfile

resouce size
cpu 4
memory 8GB (8192MB)
disk 200GB
Vagrant.configure(2) do |config|
  config.vm.define :vm1 do |vm1|
    vm1.vm.box = "centos/7"
    vm1.vm.provider :libvirt do |domain|
      domain.memory = 8192
      domain.cpus = 4
      domain.machine_virtual_size = 200
    end
  end
end

After "vagrant up", check each numbers.

  • memory
[vagrant@localhost ~]$ free
              total        used        free      shared  buff/cache   available
Mem:        8010412      135600     7732552        8792      142260     7649876
Swap:       1572860           0     1572860
  • cpu
[vagrant@localhost ~]$ cat /proc/cpuinfo | grep ^processor
processor       : 0
processor       : 1
processor       : 2
processor       : 3
  • disk
[vagrant@localhost ~]$ df -h
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00   38G  918M   37G   3% /
devtmpfs                         3.9G     0  3.9G   0% /dev
tmpfs                            3.9G     0  3.9G   0% /dev/shm
tmpfs                            3.9G  8.4M  3.9G   1% /run
tmpfs                            3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda2                       1014M   65M  950M   7% /boot
tmpfs                            783M     0  783M   0% /run/user/1000

[vagrant@localhost ~]$ sudo fdisk -l | grep vda
Disk /dev/vda: 214.7 GB, 214748364800 bytes, 419430400 sectors
/dev/vda1            2048        4095        1024   83  Linux
/dev/vda2   *        4096     2101247     1048576   83  Linux
/dev/vda3         2101248    83886079    40892416   8e  Linux LVM

[vagrant@localhost ~]$ mount | grep /dev/mapper/VolGroup00-LogVol00
/dev/mapper/VolGroup00-LogVol00 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

After "vagrant up", extend fs by LVM command

Check current LVM status before extend

PV (physical volume) (collection of PE(physical extent))

[vagrant@localhost ~]$ sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda3
  VG Name               VolGroup00
  PV Size               39.00 GiB / not usable 30.00 MiB
  Allocatable           yes (but full)
  PE Size               32.00 MiB
  Total PE              1247
  Free PE               0
  Allocated PE          1247
  PV UUID               2GoPIF-shSp-sPzx-dk2v-erat-eFRD-h7mApJ

VG (volume group) (set of PV, LV)

[vagrant@localhost ~]$ sudo vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               38.97 GiB
  PE Size               32.00 MiB
  Total PE              1247
  Alloc PE / Size       1247 / 38.97 GiB
  Free  PE / Size       0 / 0
  VG UUID               0xuC6p-2WS9-nJV3-bzFL-JdPV-S8JV-jGHAK2

LV (logical volume) (collection of LE(logical extent))

[vagrant@localhost ~]$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/VolGroup00/LogVol00
  LV Name                LogVol00
  VG Name                VolGroup00
  LV UUID                Xo5DtX-P3er-b14c-QYxt-a7Ow-aPzX-0qDe2m
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-06-20 21:24:21 +0000
  LV Status              available
  # open                 1
  LV Size                37.47 GiB
  Current LE             1199
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/VolGroup00/LogVol01
  LV Name                LogVol01
  VG Name                VolGroup00
  LV UUID                Xb0aOa-9CNv-3DCQ-VCfi-10nQ-TeE7-o0SnsP
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-06-20 21:24:22 +0000
  LV Status              available
  # open                 2
  LV Size                1.50 GiB
  Current LE             48
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

Confirmation & Procedures

  1. Create /dev/vda3 by fdisk
  2. Extend PV with adding /dev/vda3() as PE
  3. Extend VG VolGroup00 with PV extended by 2.
  4. Extend LV(logical volume) with extended VG
  5. Resize XFS file system

1. Create /dev/vda3 by fdisk

  • Add logical partition because the probability for future extending /dev/vda ...
  • If you add new /dev/vdb, you can choose primary partition.
[vagrant@localhost ~]$ sudo fdisk /dev/vda
(snip)
Command (m for help): p

Disk /dev/vda: 214.7 GB, 214748364800 bytes, 419430400 sectors

(snip)

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1            2048        4095        1024   83  Linux
/dev/vda2   *        4096     2101247     1048576   83  Linux
/dev/vda3         2101248    83886079    40892416   8e  Linux LVM

Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e
Selected partition 4
First sector (83886080-419430399, default 83886080):
Using default value 83886080
Last sector, +sectors or +size{K,M,G} (83886080-419430399, default 419430399):
Using default value 419430399
Partition 4 of type Extended and of size 160 GiB is set

Command (m for help): p

Disk /dev/vda: 214.7 GB, 214748364800 bytes, 419430400 sectors

(snip)

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1            2048        4095        1024   83  Linux
/dev/vda2   *        4096     2101247     1048576   83  Linux
/dev/vda3         2101248    83886079    40892416   8e  Linux LVM
/dev/vda4        83886080   419430399   167772160    5  Extended

Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (83888128-419430399, default 83888128):
Using default value 83888128
Last sector, +sectors or +size{K,M,G} (83888128-419430399, default 419430399):
Using default value 419430399
Partition 5 of type Linux and of size 160 GiB is set

Command (m for help): p

Disk /dev/vda: 214.7 GB, 214748364800 bytes, 419430400 sectors

(snip)

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1            2048        4095        1024   83  Linux
/dev/vda2   *        4096     2101247     1048576   83  Linux
/dev/vda3         2101248    83886079    40892416   8e  Linux LVM
/dev/vda4        83886080   419430399   167772160    5  Extended
/dev/vda5        83888128   419430399   167771136   83  Linux

Command (m for help): t
Partition number (1-5, default 5): 5
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/vda: 214.7 GB, 214748364800 bytes, 419430400 sectors

(snip)

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1            2048        4095        1024   83  Linux
/dev/vda2   *        4096     2101247     1048576   83  Linux
/dev/vda3         2101248    83886079    40892416   8e  Linux LVM
/dev/vda4        83886080   419430399   167772160    5  Extended
/dev/vda5        83888128   419430399   167771136   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

[vagrant@localhost ~]$ sudo partprobe

2. Extend PV with adding /dev/vda3() as PE

[vagrant@localhost ~]$ sudo pvcreate /dev/vda5
  Physical volume "/dev/vda5" successfully created.
[vagrant@localhost ~]$ sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda3
  VG Name               VolGroup00
  PV Size               39.00 GiB / not usable 30.00 MiB
  Allocatable           yes (but full)
  PE Size               32.00 MiB
  Total PE              1247
  Free PE               0
  Allocated PE          1247
  PV UUID               2GoPIF-shSp-sPzx-dk2v-erat-eFRD-h7mApJ

  "/dev/vda5" is a new physical volume of "160.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/vda5
  VG Name
  PV Size               160.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               IxnFr7-OUs2-g1z0-U1rY-vfhJ-sLYr-ZOB7Hc

3. Extend VG VolGroup00 with PV extended by 2.

[vagrant@localhost ~]$ sudo vgextend VolGroup00 /dev/vda5
  Volume group "VolGroup00" successfully extended
[vagrant@localhost ~]$ sudo vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               198.94 GiB
  PE Size               32.00 MiB
  Total PE              6366
  Alloc PE / Size       1247 / 38.97 GiB
  Free  PE / Size       5119 / 159.97 GiB
  VG UUID               0xuC6p-2WS9-nJV3-bzFL-JdPV-S8JV-jGHAK2

4. Extend LV(logical volume) with extended VG

[vagrant@localhost ~]$ sudo lvextend -l +100%FREE /dev/VolGroup00/LogVol00
  Size of logical volume VolGroup00/LogVol00 changed from 37.47 GiB (1199 extents) to 197.44 GiB (6318 extents).
  Logical volume VolGroup00/LogVol00 successfully resized.
[vagrant@localhost ~]$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/VolGroup00/LogVol00
  LV Name                LogVol00
  VG Name                VolGroup00
  LV UUID                Xo5DtX-P3er-b14c-QYxt-a7Ow-aPzX-0qDe2m
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-06-20 21:24:21 +0000
  LV Status              available
  # open                 1
  LV Size                197.44 GiB
  Current LE             6318
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/VolGroup00/LogVol01
  LV Name                LogVol01
  VG Name                VolGroup00
  LV UUID                Xb0aOa-9CNv-3DCQ-VCfi-10nQ-TeE7-o0SnsP
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2017-06-20 21:24:22 +0000
  LV Status              available
  # open                 2
  LV Size                1.50 GiB
  Current LE             48
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

5. Resize XFS file system

[vagrant@localhost ~]$ sudo xfs_growfs /dev/mapper/VolGroup00-LogVol00
meta-data=/dev/mapper/VolGroup00-LogVol00 isize=512    agcount=4, agsize=2455552 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=9822208, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4796, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 9822208 to 51757056

[vagrant@localhost ~]$ df -h
Filesystem                       Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00  198G  918M  197G   1% /
devtmpfs                         3.9G     0  3.9G   0% /dev
tmpfs                            3.9G     0  3.9G   0% /dev/shm
tmpfs                            3.9G  8.4M  3.9G   1% /run
tmpfs                            3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/vda2                       1014M   65M  950M   7% /boot
tmpfs                            783M     0  783M   0% /run/user/1000
tmpfs                            783M     0  783M   0% /run/user/0
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0