Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Increase the size kvm vm with lvm?

  1. #1
    Join Date
    Oct 2004
    Beans
    359
    Distro
    Ubuntu 18.04 Bionic Beaver

    Increase the size kvm vm with lvm?

    Hi all,

    Running ubuntu18 with kvm. currently running 2 vms. each vm is ubuntu 18. Both are sitting in the /dev/lvg/vmstorage on the host server. one vm is 99G and the other is 45G.

    Code:
    root@serv:/home/admin# ls -l /var/vmstorage/
    total 105637884
    -rw------- 1 libvirt-qemu kvm  48325984256 Nov 21 22:22 mailserv
    -rw------- 1 libvirt-qemu kvm 106316892016 Nov 21 22:22 webserv
    I would like to increase the storage space in one of the VM's using LVM.

    I have already increased the size of the vm image using:
    Code:
    root@serv:/home/admin# qemu-img resize /var/vmstorage/webserv +20G
    Image resized.
    
    root@serv:/home/admin# lsblk
    NAME               MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda                  8:0    0  1.7T  0 disk 
    ├─sda1               8:1    0  1.9G  0 part /boot
    ├─sda2               8:2    0    1K  0 part 
    └─sda5               8:5    0  1.6T  0 part 
      ├─LVG-root       253:0    0    4G  0 lvm  /
      ├─LVG-usr        253:1    0    6G  0 lvm  /usr
      ├─LVG-var        253:2    0    4G  0 lvm  /var
      ├─LVG-tmp        253:3    0  3.5G  0 lvm  /tmp
      ├─LVG-bak        253:4    0  7.5G  0 lvm  /bak
      ├─LVG-srv        253:5    0  3.8G  0 lvm  /srv
      ├─LVG-opt        253:6    0   52G  0 lvm  /opt
      ├─LVG-home       253:7    0  1.8G  0 lvm  /home
      ├─LVG-isostorage 253:8    0    5G  0 lvm  /var/isostorage
      └─LVG-vmstorage  253:9    0  170G  0 lvm  /var/vmstorage
    sr0                 11:0    1 1024M  0 rom  
    sr1                 11:1    1 1024M  0 rom
    on the host server, and it increased from 150G to 170G.

    The current size of the vm is 99G, would like to add +20G

    But I can seem to increase the size on the vm guest side:

    I tried:
    Code:
    root@webserv:/home/admin# lvextend -l 100%FREE -r /dev/webserv-vg/root
      New size of 0 not permitted.
    
    root@webserv:/home/admin# lsblk
    NAME                   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sr0                     11:0    1 1024M  0 rom  
    vda                    252:0    0  119G  0 disk 
    └─vda1                 252:1    0   99G  0 part 
      ├─webserv--vg-root   253:0    0   98G  0 lvm  /
      └─webserv--vg-swap_1 253:1    0  980M  0 lvm  [SWAP]
    
    root@webserv:/home/admin# lvextend -L+20G -r /dev/webserv-vg/root
      Insufficient free space: 5120 extents needed, but only 0 available
    
    root@webserv:/home/admin#
    But it is not letting me

    What do I need to do?
    Last edited by Heeter; 2 Weeks Ago at 06:22 PM.

  2. #2
    Join Date
    Jun 2007
    Location
    Arizona U.S.A.
    Beans
    4,343

    Re: Increase the size kvm vm with lvm?

    The current size of the vm is 99G, would like to add +20G
    You need to resize the virtual disk. I have used the directions given here:
    https://fatmin.com/2016/12/20/how-to...h-virt-resize/

  3. #3
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Increase the size kvm vm with lvm?

    So you are using LVM on the hostOS which provides a file-based VM storage area
    and
    you are using LVM inside the guest OS.

    In this storage setup, the storage changes on the host doesn't directly impact the guest. When you resized using the qemu-img tool, that was like making a larger physical disk, but inside the VM, until you force it to see the new size, you are stuck.

    I would run sudo -H gparted inside the guest to have it see the new storage. Then reboot the guest so the OS really sees it.
    Next you should post the output from these commands run from inside the guest:
    Code:
    sudo parted -l
    lsblk -o name,size,type,fstype,mountpoint
    df -hT -x squashfs -x tmpfs -x devtmpfs
    I suspect the easiest answer will be to add a new 20G partition, create a PV in that partition, add that PV to the existing VG, then use sudo lvresize -r -L+20G /path/to/the/lv.....
    That will resize the file system at the same time the LV is increased in size. 1-step, like was mentioned in another thread.

    Do you really want to have all that storage inside the root LV? I'd rethink that, but it is your machine. I keep the OS in a 25G LV and put everything else into other LVs. It makes sense for backups and OS upgrades and OS patching to keep them separate, IMHO.
    Plus you might want to leave 5G free in the VG to support snapshots for backup needs.

    lvextend/lvresize/lvreduce are all really the same program with resize accepting bigger and smaller sizes. Good on you for specifically choosing lvextend. I need to use that for making LVs bigger for safety reasons. Thanks.

  4. #4
    Join Date
    Oct 2004
    Beans
    359
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Increase the size kvm vm with lvm?

    Hey Guys for the replies

    I am trying to use the tutorial. I am stuck trying to figure the command for my particular situation, though.

    This is what I have now:
    Code:
    root@serv:/var/vmstorage# qemu-img info webserv
    image: webserv
    file format: qcow2
    virtual size: 119G (127775277056 bytes)
    disk size: 94G
    cluster_size: 65536
    Format specific information:
        compat: 1.1
        lazy refcounts: true
        refcount bits: 16
        corrupt: false
    root@serv:/var/vmstorage#
    The virtual size is now where I want it. (120G)

    Then I type this in:
    Code:
    root@serv:/var/vmstorage# virt-resize -expand webserv webserv
    virt-resize: error: usage is: virt-resize [--options] indisk outdisk
    
    If reporting bugs, run virt-resize with debugging enabled and include the 
    complete output:
    
      virt-resize -v -x [...]
    /var/vmstorage/ is where the "webserv" vm image is located

    I am pretty sure that I am not correctly reading the tutorial.

    Regards
    Last edited by Heeter; 2 Weeks Ago at 11:47 PM.

  5. #5
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Increase the size kvm vm with lvm?

    I've never used this tool.

    Take a look at the manpage.
    Code:
    SYNOPSIS
            virt-resize [--resize /dev/sdaN=[+/-]<size>[%]]
              [--expand /dev/sdaN] [--shrink /dev/sdaN]
              [--ignore /dev/sdaN] [--delete /dev/sdaN] [...] indisk outdisk
    
    DESCRIPTION
           Virt-resize is a tool which can resize a virtual machine disk, making
           it larger or smaller overall, and resizing or deleting any partitions
           contained within.
    
           Virt-resize cannot resize disk images in-place.  Virt-resize should not
           be used on live virtual machines - for consistent results, shut the
           virtual machine down before resizing it.
    If you had the correct options, it still won't do what you want.
    two dashes are required for options, not one.
    The infile and outfile cannot be the same. If you do that, expect corruption. The tool might allow it, still, expect corruption.
    Also looks like you are missing the device inside the guest as an option to --expand. My guests use virtio, so that would be /dev/vda[?]. If you use SATA/SCSI drivers, then /dev/sda[?]


    Looks like the virtio driver doesn't matter to virt-resize:
    Code:
    $ sudo virt-filesystems --long --parts --blkdevs -h -a /dev/mapper/hadar--vg-lv--blog44--1604 
    Name       Type       MBR  Size  Parent
    /dev/sda1  partition  83   487M  /dev/sda
    /dev/sda2  partition  05   1.0K  /dev/sda
    /dev/sda5  partition  8e   15G   /dev/sda
    /dev/sda   device     -    16G   -
    inside the VM, the storage looks like this:
    Code:
    $ df -hT -x squashfs -x tmpfs -x devtmpfs
    Filesystem                Type  Size  Used Avail Use% Mounted on
    /dev/mapper/blog--vg-root ext4   14G  4.8G  7.8G  38% /
    /dev/vda1                 ext2  472M  160M  289M  36% /boot
    
    $ sudo parted -l
    
    Model: Virtio Block Device (virtblk)
    Disk /dev/vda: 17.4GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags: 
    
    Number  Start   End     Size    Type      File system  Flags
     1      1049kB  512MB   511MB   primary   ext2         boot
     2      513MB   16.1GB  15.6GB  extended
     5      513MB   16.1GB  15.6GB  logical                lvm
    Last edited by TheFu; 2 Weeks Ago at 12:24 AM.

  6. #6
    Join Date
    Jun 2007
    Location
    Arizona U.S.A.
    Beans
    4,343

    Re: Increase the size kvm vm with lvm?

    This step where you expand the filesystem isn't correct:
    Code:
    root@serv:/var/vmstorage# virt-resize -expand webserv webserv
    First, -expand should be --expand.
    Second, the two arguments following --expand are first the qcow2 copy and second the qcow2 original. They can't be the same.

    I kept a record of actual commands used when resizing manjaro-xfce.qcow2 by +5 GB. I am omitting all the related output here. Note: manjaro-xfce-orig.qcow2 is the copy of the original (see second command below). sda2 was the root partition that I needed to expand in this case.
    Code:
    sudo qemu-img resize manjaro-xfce.qcow2 +5G
    sudo cp manjaro-xfce.qcow2 manjaro-xfce-orig.qcow2
    sudo virt-resize --expand /dev/sda2 manjaro-xfce-orig.qcow2 manjaro-xfce.qcow2
    Last edited by Dennis N; 2 Weeks Ago at 01:59 AM.

  7. #7
    Join Date
    Oct 2004
    Beans
    359
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Increase the size kvm vm with lvm?

    Thank you again for your responses


    So if I understand correctly, there has to be enough room on the server for a second image to be created? So if it is in my case, I need room for the webserv-orig file and a new webserv+20G?

    Can I put the original image into another partition and create the new image+20G into the original image's location? and use the filepath in the command?

    Regards
    Last edited by Heeter; 2 Weeks Ago at 06:26 PM.

  8. #8
    Join Date
    Jun 2007
    Location
    Arizona U.S.A.
    Beans
    4,343

    Re: Increase the size kvm vm with lvm?

    Can I put the original image into another partition and create the new image+20G into the original image's location? and use the filepath in the command?
    Yes, the copy you make of the original in the 2nd step could be saved anyplace accessible using a path. The original gets enlarged where it is. Then the contents are copied back to the enlarged disk from the copy you made in step 2. The virt-resize command shown in 3rd step handles all the details of this. After you are sure the resized disk is working, you can delete the copy made in step 2.

    (No risk here because you have the copy of the original made in step #2 in case something fails - but, I've done this 4 times without any problems.)
    Last edited by Dennis N; 2 Weeks Ago at 03:37 AM.

  9. #9
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Increase the size kvm vm with lvm?

    The manpage is explicit about the order for the input and output VM files.
    Code:
    indisk outdisk
    The original is the 2nd from last argument and the new disk file is the last.

    So, please double check that the version on your system, as the local manpage documents, show the order you expect.

  10. #10
    Join Date
    Oct 2004
    Beans
    359
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: Increase the size kvm vm with lvm?

    Hi Guys, Can't thank you enough for your assistance.

    Okay, the first 2 steps went okay. The original working vm file is in the "/var/vmstorage/webserv" and the copy/backup is in the "/var/vmbackup/webserv"

    I type in the third step:
    Code:
    root@serv:/var/vmstorage# virt-resize --expand /dev/sda1 webserv /var/vmstorage/webserv
    Sorry, I still am having trouble with this.

    I got the /dev/sda1 from this:
    Code:
    root@serv:/var/vmstorage# virt-filesystems -l -h --all -a webserv
    Name                   Type       VFS  Label MBR Size Parent
    /dev/webserv-vg/root   filesystem ext4 -     -   98G  -
    /dev/webserv-vg/swap_1 filesystem swap -     -   980M -
    /dev/webserv-vg/root   lv         -    -     -   98G  /dev/webserv-vg
    /dev/webserv-vg/swap_1 lv         -    -     -   980M /dev/webserv-vg
    /dev/webserv-vg        vg         -    -     -   99G  /dev/sda1
    /dev/sda1              pv         -    -     -   99G  -
    /dev/sda1              partition  -    -     8e  99G  /dev/sda
    /dev/sda               device     -    -     -   119G -
    Regards

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •