mirror of
https://codeberg.org/hyperreal/techne
synced 2024-11-01 14:23:06 +01:00
62 lines
1.6 KiB
Org Mode
62 lines
1.6 KiB
Org Mode
|
#+title: QCOW2
|
||
|
#+setupfile: ../org-templates/page.org
|
||
|
|
||
|
** Mount qcow2 image
|
||
|
Enable NBD on the host:
|
||
|
#+begin_src shell
|
||
|
sudo modprobe nbd max_part=8
|
||
|
#+end_src
|
||
|
|
||
|
Connect qcow2 image as a network block device:
|
||
|
#+begin_src shell
|
||
|
sudo qemu-nbd --connect=/dev/nbd0 /path/to/image.qcow2
|
||
|
#+end_src
|
||
|
|
||
|
Find the VM's partitions:
|
||
|
#+begin_src shell
|
||
|
sudo fdisk /dev/nbd0 -l
|
||
|
#+end_src
|
||
|
|
||
|
Mount the partition from the VM:
|
||
|
#+begin_src shell
|
||
|
sudo mount /dev/nbd0p3 /mnt/point
|
||
|
#+end_src
|
||
|
|
||
|
To unmount:
|
||
|
#+begin_src shell
|
||
|
sudo umount /mnt/point
|
||
|
sudo qemu-nbd --disconnect /dev/nbd0
|
||
|
sudo rmmod nbd
|
||
|
#+end_src
|
||
|
|
||
|
** Resize qcow2 image
|
||
|
Install guestfs-tools (required for virt-resize command):
|
||
|
#+begin_src shell
|
||
|
sudo dnf install -y guestfs-tools
|
||
|
sudo apt install -y guestfs-tools libguestfs-tools
|
||
|
#+end_src
|
||
|
|
||
|
To resize qcow2 images, you'll have to create a new qcow2 image with the size you want, then use ~virt-resize~ on the old qcow2 image to the new one.
|
||
|
|
||
|
You'll need to know the root partition within the old qcow2 image.
|
||
|
|
||
|
Create a new qcow2 image with the size you want:
|
||
|
#+begin_src shell
|
||
|
qemu-img create -f qcow2 -o preallocation=metadata newdisk.qcow2 100G
|
||
|
#+end_src
|
||
|
|
||
|
Now resize the old one to the new one:
|
||
|
#+begin_src shell
|
||
|
virt-resize --expand /dev/vda3 olddisk.qcow2 newdisk.qcow2
|
||
|
#+end_src
|
||
|
|
||
|
Once you boot into the new qcow2 image, you'll probably have to adjust the size of the logical volume if it has LVM:
|
||
|
#+begin_src shell
|
||
|
sudo lvresize -l +100%FREE /dev/mapper/sysvg-root
|
||
|
#+end_src
|
||
|
|
||
|
Then resize the XFS root partition within the logical volume:
|
||
|
#+begin_src shell
|
||
|
sudo xfs_grow /dev/mapper/sysvg-root
|
||
|
#+end_src
|