Maxim Perevedentsev
2015-Sep-15 13:31 UTC
[Libguestfs] Question: running appliance commands over guest fs (resize2fs -P).
Hello everyone! I am working on resizing qcow2 images using virt-resize+liguestfs. E.g. I when shrinking a partition, I have to resize filesystem using resize2fs-size. The problem is that I cannot find out minimal partition size (aka resize2fs -P). The only way is calling "resize2fs-size 1K", wait for resize2fs to claim "resize2fs: New size smaller than minimum (510050)" and parse this output. It is known that resize2fs carries out complex calculations (no always correct) to get minimal size, so statvfs/tune2fs-l cannot help. The questions are: 1) How to get minimal partition size (equal to resize2fs -P)? 2) More general, how to execute commands from appliance but make them run over image (which may not have anything but filesystem) - I saw something like that in source. Thanks in advance! -- Your sincerely, Maxim Perevedentsev
Richard W.M. Jones
2015-Sep-15 13:57 UTC
Re: [Libguestfs] Question: running appliance commands over guest fs (resize2fs -P).
On Tue, Sep 15, 2015 at 04:31:46PM +0300, Maxim Perevedentsev wrote:> Hello everyone! > > I am working on resizing qcow2 images using virt-resize+liguestfs.If you're shrinking, I believe a better way to do this is to sparsify the image.> E.g. I when shrinking a partition, I have to resize filesystem using > resize2fs-size. The problem is that I cannot find out minimal > partition size (aka resize2fs -P). The only way is calling > "resize2fs-size 1K", wait for resize2fs to claim "resize2fs: New > size smaller than minimum (510050)" and parse this output. > > It is known that resize2fs carries out complex calculations (no > always correct) to get minimal size, so statvfs/tune2fs-l cannot > help. > > The questions are: > 1) How to get minimal partition size (equal to resize2fs -P)?There's no binding for that, but it would be a worthwhile addition to the API.> 2) More general, how to execute commands from appliance but make > them run over image (which may not have anything but filesystem) - I > saw something like that in source.Not sure I understand the question? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Maxim Perevedentsev
2015-Sep-15 14:28 UTC
Re: [Libguestfs] Question: running appliance commands over guest fs (resize2fs -P).
On 09/15/2015 04:57 PM, Richard W.M. Jones wrote:> On Tue, Sep 15, 2015 at 04:31:46PM +0300, Maxim Perevedentsev wrote: >> Hello everyone! >> >> I am working on resizing qcow2 images using virt-resize+liguestfs. > If you're shrinking, I believe a better way to do this is to sparsify > the image.And how would it help? If I shrink, a want a VM to occupy less maximum space. virt-sparsify (I guess you are talking about it) will reduce space taken by guest disk image by now, but won't tighten the upper limit for guest. -- Your sincerely, Maxim Perevedentsev
Richard W.M. Jones
2015-Sep-15 14:37 UTC
Re: [Libguestfs] Question: running appliance commands over guest fs (resize2fs -P).
On Tue, Sep 15, 2015 at 05:17:16PM +0300, Maxim Perevedentsev wrote:> On 09/15/2015 04:57 PM, Richard W.M. Jones wrote: > >>2) More general, how to execute commands from appliance but make > >>them run over image (which may not have anything but filesystem) - I > >>saw something like that in source. > >Not sure I understand the question? > > As I understand, guestfs runs its own kernel-like daemon that can > run its own commands. It is used to run e.g. resize2fs or e2fsck > over loaded disk images. But those two utilities require the > partition not to be mounted, so they are run by daemon and do not > require anything to exists on partition. > > In API I found only the 'command' command which requires the > partition to be mounted and have kernel image on it. This cannot > operate on empty or non-mounted partition.You probably want to use the guestfs_debug API, ie: char *cmd[] = { "resize2fs", "-P", ..., NULL }; char *ret = guestfs_debug (g, "sh", cmd); It's better to add a new API however, and not difficult either: http://libguestfs.org/guestfs.3.html#adding-a-new-api-action Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Maxim Perevedentsev
2015-Sep-15 15:04 UTC
Re: [Libguestfs] Question: running appliance commands over guest fs (resize2fs -P).
On 09/15/2015 05:37 PM, Richard W.M. Jones wrote:> On Tue, Sep 15, 2015 at 05:17:16PM +0300, Maxim Perevedentsev wrote: >> On 09/15/2015 04:57 PM, Richard W.M. Jones wrote: >>>> 2) More general, how to execute commands from appliance but make >>>> them run over image (which may not have anything but filesystem) - I >>>> saw something like that in source. >>> Not sure I understand the question? >> As I understand, guestfs runs its own kernel-like daemon that can >> run its own commands. It is used to run e.g. resize2fs or e2fsck >> over loaded disk images. But those two utilities require the >> partition not to be mounted, so they are run by daemon and do not >> require anything to exists on partition. >> >> In API I found only the 'command' command which requires the >> partition to be mounted and have kernel image on it. This cannot >> operate on empty or non-mounted partition. > You probably want to use the guestfs_debug API, ie: > > char *cmd[] = { "resize2fs", "-P", ..., NULL }; > char *ret = guestfs_debug (g, "sh", cmd);Yeah! This is just what I was looking for. Thank you :-)> It's better to add a new API however, and not difficult either: > > http://libguestfs.org/guestfs.3.html#adding-a-new-api-action > > Rich.I'll try to submit a patch when I'll have time. -- Your sincerely, Maxim Perevedentsev
Possibly Parallel Threads
- Question: running appliance commands over guest fs (resize2fs -P).
- Re: Question: running appliance commands over guest fs (resize2fs -P).
- Fwd: Re: Question: running appliance commands over guest fs (resize2fs -P).
- Re: Question: running appliance commands over guest fs (resize2fs -P).
- Re: Question: running appliance commands over guest fs (resize2fs -P).