It depends on whether you’re shrinking the volume or extending it.
Extending
If you know that you are extending you’re pretty much safe. To be even more confident you could replace lvresize with lvextend and compare current volume size (sudo lvdisplay /dev/qubes_dom0/root, displayed as “LV Size”) with free space available in the volume group (sudo vgdisplay qubes_dom0, displayed as “Free PE / Size”). If volume group has enough free space to get the root volume to 40 GiB it will work.
Another precaution you could take is to ensure your filesystem is ext (resize2fs resizes ext filesystems). See “Type” in the output of df -hT /dev/mapper/qubes_dom0-root.
sudo lvextend --size 40G /dev/qubes_dom0/root resizes the volume up to the specified size.
sudo resize2fs /dev/mapper/qubes_dom0-root resizes the filesystem on the volume up to the size of the volume. On modern kernels it extends even currently mounted filesystems.
You don’t need to do anything next, at this point usable space have been extended. Use it, I guess?
Shrinking
If you’re shrinking it’s both more risky and more involved. I’ll write a lot but even that is omitting plenty, ask if not sure. First, check information on filesystem on the volume:
$ df -hT /dev/mapper/qubes_dom0-root
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/qubes_dom0-root ext4 60G 11G 48G 18% /
In the output you are first interested in the filesystem type - this will determine the process of shrinking the filesystem. I’ll make an assumption that you have ext4 from now on, but you must not follow if it is not - search for the process applicable to your filesystem.
Next most important thing is Size and Avail. In this example total filesystem size is 60G, 48G of which is unused - this is enough to shrink total size to 40G.
resize2fs cannot shrink mounted filesystems. There are various workarounds for this but they might be complicated for you… Try searching around on this yourself, perhaps you find them better than booting a live OS. If you choose to use a live filesystem, download anything you feel familiar with, like debian live image for example, write it to a USB stick as usual and reboot into it.
I also must add that using a live OS has considerable security implications. Use only if you trust it and know how to use it without undermining security.
Once booted, assuming your Qubes OS drive is encrypted, you must decrypt it. We have documentation on this: How to mount a Qubes partition from another OS — Qubes OS Documentation but it is very limited (and also cryptsetup syntax is old but should work??). You only need the decryption step, perhaps followed by pvscan/vgscan/lvscan if live system doesn’t detect lvm structure autmatically. Another possible problem is live system may not have lvm installed, but I’ll leave lvm installation up to the system documentation.
After booting up live system and unlocking Qubes drive you need to locate the volume again, which should be easy - see “LV path” in the output of sudo lvdisplay qubes_dom0/root.
Once there, you can shrink. I would advise shrinking to a bit less than 40G at first (if you have enough file system free space) - this saves you from figuring out the exact size lvresize is going to shrink the volume to in the next step. After that you can resize the volume and extend the filesystem back to the size of the volume. For example:
$ sudo resize2fs <path_to_lv> 35G
$ sudo lvresize --size 40G <path_to_lv>
$ sudo resize2fs <path_to_lv>
Replace <path_to_lv> above with the path you get from “LV path” in the previous step.
That’s it, you can reboot back into Qubes after this.