Skip to content

Instantly share code, notes, and snippets.

@devsigner
Last active January 20, 2020 21:43
Show Gist options
  • Save devsigner/7d5a33adb36772891fa2755037524f19 to your computer and use it in GitHub Desktop.
Save devsigner/7d5a33adb36772891fa2755037524f19 to your computer and use it in GitHub Desktop.

How to resize VM

first Shut down the virtual machine

virsh shudown image.qcow2

then Resize the image with

qemu-img resize image.qcow2 +SIZE

then Start the virtaul machine

virsh start image.qcow2

open vm console and log in

virsh console image.qcow2

Collect some details again about our current partitioning

  • df -h
  • fdisk -l

Unmont the part

  • umount /dev/sda1
  • fdisk /dev/sda
  • fsck -n /dev/vda2

Type m to get a list of all commands:

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

print the partition table p

Now we delete partition d follow by part number

Next we create a new one n It was a primary partition before, so we choose p, and again it is our partition.

If the original part had the bootable flag, so we must add it to our new a

Now let's write our new partition table and exit fdisk w

and reboot

then

  • e2fsck -f /dev/vda2
  • resize2fs /dev/vda2
  • fsck -n /dev/vda2
  • tune2fs -j /dev/vda2
  • reboot

and voila

  • df -h
  • fdisk -l
  • fdisk -s /dev/vda1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment