My Wiki!

LVM

1. Resize logical volume

The steps are as follows:

  1. Create new disk partition with fdisk (after extending virtual disk of the VM or physical disk of the computer). Restart.
  2. Check things with pvdisplay, vgdisplay, lvdisplay
  3. Create the LVM Physical Volume: pvcreate /dev/sdaX
  4. Extend the LVM Volume Group: vgextend ubuntu-vg /dev/sda3
  5. Extend the LVM Logical Volume, use all space and resizefs (-r): lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
  6. Validate: df -h

1.1 Resize root lv

Resize2fs already done with -r key above. Otherwise:

  resize2fs /dev/ubuntu-vg/ubuntu-lv
  
  df -h
  lsblk

2. Mount Resize QCOW2

modprobe nbd max_part=63
qemu-nbd -c /dev/nbd0 Fedora-x86_64-20-20141008-sda-compute.qcow2
mount /dev/nbd0p2 /mnt/cf
error mounting lvm2_member
fdisk -l 
show nothing
    
    lvmdiskscan
      /dev/fedora_dai142/lv_root   [      78.12 GiB] 
  /dev/sda1                    [     200.00 MiB] 
  /dev/nbd0p1                  [     500.00 MiB] 
  /dev/fedora_dai142/lv_swap00 [       9.77 GiB] 
  /dev/sda2                    [     500.00 MiB] 
  /dev/nbd0p2                  [       9.51 GiB] LVM physical volume
  /dev/fedora_dai142/lv_home   [     117.19 GiB] 
  /dev/sda3                    [     205.08 GiB] LVM physical volume
  /dev/sdb1                    [     300.00 GiB] 
  /dev/sdb2                    [      10.00 GiB] 
  /dev/sdb3                    [     246.12 GiB] 
  /dev/sdb4                    [     375.39 GiB] LVM physical volume
  2 disks
  7 partitions
  0 LVM physical volume whole disks
  3 LVM physical volumes

3. Dont know how to resize

4. Clean up

  qemu-nbd -d /dev/nbd0
  vgchange -an VolGroupName
  killall qemu-nbd

Virt-resize

Basically: Copy old-image to new-image +resize

Create new image

  
  qemu-img create -f qcow2 newdisk.qcow2 15G

1. Find out which sdx to expand and which logical volume

Mount qcow2 image with guestfish

Mount the image in read-write mode as root, as follows:

# guestfish --rw -a Fedora-x86_64-20-20141008-sda-compute.qcow2
    

We must first use the run command at the guestfish prompt before we can do anything else. This will launch a virtual machine, which will be used to perform all of the file manipulations.

><fs> run
><fs> list-devices
/dev/sda1
/dev/sda2
><fs> list-filesystems
/dev/fedora/root: ext4   <-- here it is
/dev/fedora/swap: swap

We're done, so we can exit using the exit command:

><fs> exit

2. Expand image

  virt-resize --expand /dev/sda2 --LV-expand /dev/fedora/root \
    olddisk newdisk
virt-resize --expand /dev/sda2 --LV-expand /dev/fedora/root \
> Fedora-x86_64-20-20141008-sda-controller.qcow2 Fedora-x86_64-20-20141008-sda-controller2.qcow2
Examining Fedora-x86_64-20-20141008-sda-controller.qcow2 ...
◓ 25% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒══════════════════════════════════════════════════════⟧ --:--
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
**********

Summary of changes:

/dev/sda1: This partition will be left alone.
    
    /dev/sda2: This partition will be resized from 9.5G to 39.5G.  The LVM 
    PV on /dev/sda2 will be expanded using the 'pvresize' method.
    
    /dev/fedora/root: This logical volume will be expanded to maximum size. 
     The filesystem ext4 on /dev/fedora/root will be expanded using the 
    'resize2fs' method.
    
    **********
Setting up initial partition table on Fedora-x86_64-20-20141008-sda-controller2.qcow2 ...
Copying /dev/sda1 ...

3. Tuning lvm


Navigation