Partitioning /root in a VM

Hi folks!

I came across an ugly problem and here’s what I did:
As a host system, I use openSUSE 13.2, GNOME; On that, I have gnome-boxes as a virtualiser (in fact, it uses quemu). In this VM, besides other, I tried openSUSE tumbleweed, KDE (pretty nice btw). Now that KDE5 came out, I learned that it requires more space in the root-partition (I guess because it still has a lot of KDE4 in it, plus the new stuff); Anyway: The “/” in my VM is full. BTW: I stayed with the default settings for openSUSE, so I have a / in btrfs and /home as xfs; I already deleted all old btrfs-snapshots.

On a non-virtual machine, I would “simply” take a live-image, start GParted (or any alternative) and change the partitions’s sizes. But: I have no clue how to apply a live-image to a virtual box. And of course, I can’t use the partitioner from within the VM (it wont’ let me unmount “/” – surprise!!1!).
I am pretty sure there’s a solution to that. But I am a complete newbie to virtualisation… Can anyone give me a hint?

Thanks in advance!!
:\

On 2015-05-19 12:16, pbiel wrote:

> On a non-virtual machine, I would “simply” take a live-image, start
> GParted (or any alternative) and change the partitions’s sizes. But: I
> have no clue how to apply a live-image to a virtual box.

Why not?

You had to boot a live image in order to install anything in any virtual
environment. So boot it again, or any other image you want…

I can’t give precise instructions with quemu, though, I don’t use it.


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

Hi!

Install package “guestfs-tools”. This will install the tool “virt-resize” among others
that will help manage the virtual disk.

Power off the virtual machine.

Then find out where your virtual disk is located:
(they are located in “~/.local/share/gnome-boxes/images/” by default)

$ virsh dumpxml guestname | xpath /domain/devices/disk/source

(replace “guestname” with the name of your virtual machine)

Then list the partitions on the virtual disk:

$ virt-filesystems --long --parts --blkdevs -h -a ~/.local/share/gnome-boxes/images/nameofdisk

(replace “nameofdisk” with the name of your virtual disk)

Now that you know which one is your root partition and what size it is, create a file at least as big as your
virtual disk+the extra space you want to increase your root partition with (using 40G as an example):

$ truncate -s 40G ~/.local/share/gnome-boxes/images/outdisk

Now merge your virtual disk into the new space you just created and expand the partition (replace “/dev/sda2” with your root partition):

$ virt-resize --expand /dev/sda2 ~/.local/share/gnome-boxes/images/nameofdisk ~/.local/share/gnome-boxes/images/outdisk

Power on the virtual machine again. Did it work?

Source: http://libguestfs.org/virt-resize.1.html#detailed-usage

If you’re used to using Gparted,
You can also run it against a diskfile.

Simply mount/configure the gparted live iso in the Guest’s virtual cdrom and boot.
Everything works exactly the same as working with a physical disk.

TSU

Just an additional FYI -
The original post describes running out of space on the root (/) partition, but sometimes re-sizing partitions on a diskfile isn’t sufficient.
It should be noted that <depending on the type of diskfile> there often are ways to re-size the entire diskfile itself (both “growable” dynamic and fixed size formats.

So, just something to keep in mind which isn’t an option when working with real, physical disks.

TSU

@DanneStrat:

Thanks, that sound very nice, however, I have a newbie question…

I did:

virt-filesystems --long --parts --blkdevs -h -a ~/.local/share/gnome-boxes/images/boxes-unknown
Name       Type       MBR  Size  Parent
/dev/sda1  partition  82   2,0G  /dev/sda
/dev/sda2  partition  83   10G   /dev/sda
/dev/sda3  partition  83   8,0G  /dev/sda
/dev/sda   device     -    20G   -

And the partition I want to resize is the 10G [sic!] /dev/sda2. However, what did not work was:


virt-resize --expand /dev/sda2 ~/.local/share/gnome-boxes/images/boxes-unknown/dev/sda2 ~/.local/share/gnome-boxes/images/outdisk
Examining /home/philipp/.local/share/gnome-boxes/images/boxes-unknown/dev/sda2 ...
virt-resize: libguestfs error: /home/philipp/.local/share/gnome-boxes/images/boxes-unknown/dev/sda2: Not a directory

Yes, that was a wild guess of mine, but how would I correctly tell virt-resize, that it should resize this partition?

Thanks for your help so far!

The last command should be:

$ virt-resize --expand /dev/sda2 ~/.local/share/gnome-boxes/images/boxes-unknown ~/.local/share/gnome-boxes/images/outdisk

The option “–expand” tells virt-resize which partition you want to expand with the new free space and “boxes-unknown” is the name of the virtual disk.

Oh, thanks, that makes sense… Unfortulately, it tells me the following:

 virt-resize: libguestfs error: lvm_set_filter: aug_save: Lens not found: Can not find lens guestfs_lvm_conf.lns 

Do you understand what it means? What’s a “lens”? And somehow it sounds as if it wants to do something with lvm… How come – I have not (at least afaik) used any lvm?

On 2015-05-20 15:06, pbiel wrote:
> Do you understand what it means? What’s a “lens”? And somehow it sounds
> as if it wants to do something with lvm… How come – I have not (at
> least afaik) used any lvm?

Did you install the guest with full system encryption? That implies
using LVM.


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

Hi. Nope. Plain and simple, no LVM, no LUKS, no nothing^^.

Hope I’m not stating some obvious things…

  • If you value the contents of your diskfile, <never> perform major surgery on an only copy. Always copy the disk before applying disk operations against one of the copies.
  • Keep in mind myPost #4

It’s been a long time since I’ve attempted to modify partitions in a diskfile like what you seem to be doing with libvirt.
Your LVM issue may be related to some other LVM related posts I’ve seen in the Install/Boot forum… something about LVM installed and running even when not used(may be also totally unrelated). But, since I haven’t personally run into that yet, I haven’t dived into whatever that situation involved.

TSU

@pbiel

There seems to be a bug in the current package in the repositories.
Libguestfs spits out those errors when it can’t find some files that are
missing from the initramfs:
https://bugzilla.novell.com/show_bug.cgi?id=908632

The bug appears to be fixed, however just a short while ago there was
a new request submitted with regards to fixing this bug:
https://build.opensuse.org/request/show/308082
“- Package guestfs_lvm_conf.aug (bnc#908632)”

You could try to install the latest version of package “guestfs-data” according to
post #4 in the bug report above:

# zypper -p http://download.opensuse.org/repositories/Virtualization/openSUSE_13.2/ in guestfs-data-1.26.10-168.11.x86_64

(assuming you’re using 64-bit, else you should pick the 32-bit package)

Then repeat the last step that failed.

Just a small adjustment to my previous post:

# zypper -p http://download.opensuse.org/repositories/Virtualization/openSUSE_13.2/ in guestfs-data

should be enough. Zypper should pick the correct architecture.

Hi, and thanks so far!

@DanneStrat: Thanks, this solved the one issue. Now, virt-resize walk through like a charm:


Summary of changes:

/dev/sda1: This partition will be left alone.
    
    /dev/sda2: This partition will be resized from 10,0G to 15,0G.  The 
    filesystem btrfs on /dev/sda2 will be expanded using the 
    'btrfs-filesystem-resize' method.
    
    /dev/sda3: This partition will be left alone.
    
    **********
Setting up initial partition table on ~/.local/share/gnome-boxes/images/outdisk ...
Copying /dev/sda1 ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Copying /dev/sda2 ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Copying /dev/sda3 ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Expanding /dev/sda2 using the 'btrfs-filesystem-resize' method ...

Resize operation completed with no errors.  Before deleting the old 
disk, carefully check that the resized disk boots and works correctly.


Unfortunately, the virtual machine, after reboot, seems to be not impressed:


btrfs fi df -h /
Data, single: total=8.19GiB, used=8.17GiB
System, DUP: total=32.00MiB, used=16.00KiB
Metadata, DUP: total=896.00MiB, used=574.89MiB
GlobalReserve, single: total=192.00MiB, used=3.66MiB

Am I doing something wrong here?
Do I probably need to point the vm to the new disk? I mean, the old one still exists and the new (= large) might ignored… Should I do something such as


mv ~/.local/share/gnome-boxes/images/outdisk ~/.local/share/gnome-boxes/images/boxes-unknown

?
I’m not sure whether that’s a good idea… (sorry, newbie)

Thanks in advance

Yes, now you need to change the disk to the new one.
If you have enough disk space I would advise you to
first make a backup of the old disk before you overwrite it:

$ cp ~/.local/share/gnome-boxes/images/boxes-unknown ~/.local/share/gnome-boxes/images/boxes-unknown.old

Power off the virtual machine if you haven’t done so already and move to the new disk:

$ mv ~/.local/share/gnome-boxes/images/outdisk ~/.local/share/gnome-boxes/images/boxes-unknown

then boot the virtual machine and try it out. If something has failed you can just go back to the old one and try again:

$ mv ~/.local/share/gnome-boxes/images/boxes-unknown.old ~/.local/share/gnome-boxes/images/boxes-unknown

If everything works, then you can delete the backup:

$ rm ~/.local/share/gnome-boxes/images/boxes-unknown.old

If the VM fails to start after doing:

$ mv ~/.local/share/gnome-boxes/images/outdisk ~/.local/share/gnome-boxes/images/boxes-unknown

then there is a possibility the new disk type is “raw” while the old one was “qcow2” (the default format used by qemu).
To find out if this is the case do:

$ virsh dumpxml ~/.local/share/gnome-boxes/images/boxes-unknown | xpath /domain/devices

and look for something like:


<driver name=“qemu” type=“qcow2”

If it says type=“qcow2” then convert the disk to “qcow2”:

# zypper in qemu-tools
$ qemu-img convert -O qcow2 ~/.local/share/gnome-boxes/images/boxes-unknown ~/.local/share/gnome-boxes/images/boxes-unknown.qcow2
$ mv ~/.local/share/gnome-boxes/images/boxes-unknown.qcow2 ~/.local/share/gnome-boxes/images/boxes-unknown

then boot the VM.

Hi,

thanks so far… It’s still not over :\


Boxes-WARNING **: machine.vala:576: Failed to start oS Tumbleweed: Unable to start domain: internal error: process exited while connecting to monitor: 2015-05-21T23:39:19.479393Z qemu-system-x86_64: -drive file=/home/philipp/.local/share/gnome-boxes/images/boxes-unknown,if=none,id=drive-ide0-0-0,format=qcow2,cache=none: could not open disk image /home/philipp/.local/share/gnome-boxes/images/boxes-unknown: Image is not in qcow2 format

Any idea? I mean, I did not change the format of anything willingly. ****.

Just a FYI and not intended to discourage your efforts…
I myself ran into this issue (needing to enlarge / ) on one of my VMs today, so this is what I did… The approach and utilities I used should work using any virtualization technology and even any disk format.

As I described earlier, sometimes you also need to enlarge the disk. Even if you might originally want to simply re-size some other partition to make room for enlarging the root partition, IMO it’s simpler and likely a better long term decision to just enlarge the disk so that you’re not making another partition smaller(possibly causing another future problem). In this case, I decided to simply create a new, larger disk and then to clone the old disk to the new.

I decided to use Clonezilla to do the whole disk cloning, and if necessary to use gpart-live to modify the individual partitions. Other options should also be good like using dd to block copy/clone, or using other utilities.

  1. Create a new disk with the desired new size. Leave it attached to the vm, I found that Clonezilla requires this to “see” both disks.
  2. Configure the Guest to boot to Clonezilla
    2a. Select the “Advanced” instead of default options. Select disk to disk cloning and no NTFS options, everything else default, including options to write boot to the new disk.
    2b. Select and verify sda as the source (which likely will always be the case, but doublecheck by observing the disk sizes).
  3. Shutdown
  4. Disable CDROM or otherwise force boot to disk
  5. Remove the original virtual disk, leaving only the new disk.
  6. Boot to your new disk.
  7. Inspect and verify all is running correctly. You can use “df” to view your partitions and partition usage.
  8. Shutdown.
  9. Configure gparted-live in the Guest CDROM
  10. Boot to gparted-live, like myself despite authorizing Clonezilla to auto expand to fill the disk, it didn’t happen and you’ll find unformatted/unpartitioned disk space
  11. Re-size / to fill the empty space
    12 Shutdown
  12. Boot to your system and verify the success of your operations by running “df” again.

HTH,
TSU

It complains about the image not being in “qcow2” format (see the highlighted text in the error message I quoted).
Try to convert the disk to “qcow2” as I described in my previous post.

Yep, I totally missed that, thank you.

It worked really well and now it’s absolutely fine. Thanks all of you for your helpfulness. Special thanks to @DanneStrat for his patience!