[PATCHv2] New API: part_expand_gpt.
by Maxim Perevedentsev
This action moves second(backup) GPT header to the end of the disk.
It is usable in in-place image expanding, since free space after
second GPT header is unusable. To use additional space, we have
to move second header. This is what sgdisk -e does.
However, sgdisk -e may perform additional actions if the partition
table has unexpected params (e.g. if we call sgdisk -e /dev/sda1,
it may fix partition table thus destroying the filesystem).
To prevent such cases, we do a dry-run at first and fail if
additional actions are scheduled.
---
daemon/parted.c | 33 ++++++++++++++++++++
generator/actions.ml | 14 +++++++++
src/MAX_PROC_NR | 2 +-
tests/daemon/Makefile.am | 3 +-
tests/daemon/test-expand-gpt.pl | 69 +++++++++++++++++++++++++++++++++++++++++
5 files changed, 119 insertions(+), 2 deletions(-)
create mode 100755 tests/daemon/test-expand-gpt.pl
diff --git a/daemon/parted.c b/daemon/parted.c
index df6b7e7..033c136 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -928,3 +928,36 @@ do_part_get_mbr_part_type (const char *device, int partnum)
reply_with_error ("strdup failed");
return NULL;
}
+
+int
+do_part_expand_gpt(const char *device)
+{
+ CLEANUP_FREE char *err = NULL;
+
+ /* If something is broken, sgdisk may try to correct it.
+ * (e.g. recreate partition table and so on).
+ * We do not want such behavior, so dry-run at first.*/
+ int r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
+ str_sgdisk, "--pretend", "-e", device, NULL);
+
+ if (r == -1) {
+ reply_with_error ("%s --pretend -e %s: %s", str_sgdisk, device, err);
+ return -1;
+ }
+ if (err && strlen(err) != 0) {
+ /* Unexpected actions. */
+ reply_with_error ("%s --pretend -e %s: %s", str_sgdisk, device, err);
+ return -1;
+ }
+
+ /* Now we can do a real run. */
+ r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR,
+ str_sgdisk, "-e", device, NULL);
+
+ if (r == -1) {
+ reply_with_error ("%s -e %s: %s", str_sgdisk, device, err);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index 7ab8ee4..3a14683 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12787,6 +12787,20 @@ See also L<ntfsresize(8)>, L<resize2fs(8)>, L<btrfs(8)>, L<xfs_info(8)>." };
longdesc = "\
This is the internal call which implements C<guestfs_feature_available>." };
+ { defaults with
+ name = "part_expand_gpt"; added = (1, 31, 29);
+ style = RErr, [Device "device"], [];
+ proc_nr = Some 459;
+ optional = Some "gdisk";
+ shortdesc = "move backup GPT header to the end of the disk";
+ longdesc = "\
+Move backup GPT data structures to the end of the disk.
+This is useful in case of in-place image expand
+since disk space after backup GPT header is not usable.
+This is equivalent to C<sgdisk -e>.
+
+See also L<sgdisk(8)>." };
+
]
(* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index c92ddb6..658bd78 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-458
+459
diff --git a/tests/daemon/Makefile.am b/tests/daemon/Makefile.am
index bb380c5..329b00c 100644
--- a/tests/daemon/Makefile.am
+++ b/tests/daemon/Makefile.am
@@ -25,7 +25,8 @@ check_DATA = captive-daemon.pm
TESTS = \
test-daemon-start.pl \
- test-btrfs.pl
+ test-btrfs.pl \
+ test-expand-gpt.pl
TESTS_ENVIRONMENT = $(top_builddir)/run --test $(VG)
diff --git a/tests/daemon/test-expand-gpt.pl b/tests/daemon/test-expand-gpt.pl
new file mode 100755
index 0000000..637b90e
--- /dev/null
+++ b/tests/daemon/test-expand-gpt.pl
@@ -0,0 +1,69 @@
+#!/usr/bin/env perl
+# Copyright (C) 2015 Maxim Perevedentsev mperevedentsev(a)virtuozzo.com
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use strict;
+use warnings;
+
+use Sys::Guestfs;
+
+sub tests {
+ my $g = Sys::Guestfs->new ();
+
+ foreach ("gpt", "mbr") {
+ $g->disk_create ("disk_$_.img", "qcow2", 50 * 1024 * 1024);
+ $g->add_drive ("disk_$_.img");
+ }
+
+ $g->launch ();
+
+ $g->part_disk ("/dev/sda", "gpt");
+ $g->part_disk ("/dev/sdb", "mbr");
+
+ $g->close ();
+
+ die if system ("qemu-img resize disk_gpt.img 100M &>/dev/null");
+
+ $g = Sys::Guestfs->new ();
+
+ foreach ("gpt", "mbr") {
+ $g->add_drive ("disk_$_.img");
+ }
+
+ $g->launch ();
+ die if $g->part_expand_gpt ("/dev/sda");
+
+ my $output = $g->debug ("sh", ["sgdisk", "-p", "/dev/sda"]);
+ die if $output eq "";
+ $output =~ s/\n/ /g;
+ $output =~ s/.*last usable sector is (\d+).*/$1/g;
+
+ my $end_sectors = 100 * 1024 * 2 - $output;
+ die unless $end_sectors <= 34;
+
+ # Negative tests.
+ eval { $g->part_expand_gpt ("/dev/sdb") };
+ die unless $@;
+ eval { $g->part_expand_gpt ("/dev/sda1") };
+ die unless $@;
+}
+
+eval { tests() };
+system ("rm -f disk_*.img");
+if ($@) {
+ die;
+}
+exit 0
--
1.8.3.1
8 years, 10 months
Re: [Libguestfs] [libguestfs] RFE: virt-builder ability to print definition for single template (new option or expand --notes) (#20)
by Richard W.M. Jones
On Mon, Dec 28, 2015 at 03:51:51PM -0800, Ryan Sawhill Aroha wrote:
> The `virt-builder --notes <TEMPLATE>` command is nice, but I really wish it printed the full template definition, eg, something like this:
>
> ```
> $ virt-builder --notes centos-70
>
> [centos-70]
> name=CentOS 70
> osinfo=centos70
> arch=x86_64
> file=centos-70xz
> checksum=cf9ae295f633fbd04e575eeca16f372e933c70c3107c44eb06864760d04354aa94b4f356bfc9a598c138e687304a52e96777e4467e7db1ec0cb5b2d2ec61affc
> format=raw
> size=6442450944
> compressed_size=213203844
> expand=/dev/sda3
> notes=CentOS 70
>
> This CentOS image contains only unmodified @Core group packages
>
> It is thus very minimal The kickstart and install script can be
> found in the libguestfs source tree:
>
> builder/website/centossh
> ```
One problem with this is that the 'index' format isn't the only
metadata format we now support. (SimpleStreams is another).
However there is an intermediate format we use internally, and those
fields could be printed by --notes or some other mechanism.
https://github.com/libguestfs/libguestfs/blob/master/builder/index.mli
This would be suitable for an RFE in Bugzilla.
> Or maybe it could be like `virt-builder --list-format long --list`
> (all prettified), but only for a particular template
>
> I think normal users need this option to be able to check the
> `osinfo=` value for use with `virt-install` without having to
> scroll/grep through all their templates
We definitely need a way to get at the osinfo information more easily.
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
8 years, 10 months
[PATCH] init: Use .rodata instead of .data.
by Richard W.M. Jones
This allows sharing of the read only data between supermin binaries
running on the same machine.
Thanks: Christian Vogel
See thread: https://news.ycombinator.com/item?id=10816921
---
src/bin2s.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/bin2s.pl b/src/bin2s.pl
index 0f892f8..ccb060b 100755
--- a/src/bin2s.pl
+++ b/src/bin2s.pl
@@ -26,7 +26,7 @@ print $ofh <<"EOF";
\t.globl\t_binary_${infile}_end
\t.globl\t_binary_${infile}_size
-\t.section\t.data
+\t.section\t.rodata
_binary_${infile}_start:
EOF
--
2.5.0
8 years, 10 months
Re: [Libguestfs] [libguestfs] RFE: virt-builder new option (--offline maybe) to allow running only from cache (#21)
by Richard W.M. Jones
On Mon, Dec 28, 2015 at 04:50:47PM -0800, Ryan Sawhill Aroha wrote:
> I love virt-builder It's great
>
> However, I don't always have internet access Further, some of my
> repos are on private networks and I'm don't always have the
> appropriate VPN established to see them
By 'repo' do you mean a virt-builder repo or a repo used for
installing packages (eg. a yum/apt repo)?
For the latter, the --attach option might be useful.
For the former, we should have a way to skip repos or DTRT without the
network being available. Pino - what do you think?
> I wish virt-builder had an option that would skip checking in with
> your remote repos and only use cache I think that would be a huge
> win
IIRC, currently if a *template* exists in the cache, then it won't
download it. However that doesn't help if the repo is inaccessible.
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
8 years, 10 months
Re: [Libguestfs] [libguestfs] RFE: virt-builder option to auto-detect image format (#19)
by Richard W.M. Jones
On Mon, Dec 28, 2015 at 03:36:53PM -0800, Ryan Sawhill Aroha wrote:
> Hi there
>
> The repo definition at http://libguestfsorg/download/builder/index
> contains `format=raw` data for each template, eg:
>
> ```
> [centos-6]
> name=CentOS 66
> osinfo=centos66
> arch=x86_64
> file=centos-6.xz
> revision=6
> checksum=fc403ea3555a5608a25ad30ce2514b67288311a7197ddf9fb664475820f26db2bd95a86be9cd6e3f772187b384a02e0965430456dd518d343a80457057bc5441
> format=raw
> size=6442450944
> compressed_size=199265736
> expand=/dev/sda3
> notes=CentOS 66
> ```
>
> I haven't looked at the source, but it seems that `virt-builder`
> doesn't do anything with that metadata
>
> According to `man virt-builder`, it always assumes `--format raw`
The format parameter in the metadata and the --format option are
related, but different things.
The format= metadata tells virt-builder the format of the original
template (ie. centos-6.xz is raw format after decompression). Image
format auto-detection is a security risk [although to be fair really
not in this particular case], and so it's better to specify the
format.
The --format parameter is what format the virt-builder end user would
like your final image to be.
So if format=raw and --format qcow2, then virt-builder knows it must
convert the image. This is the code:
https://github.com/libguestfs/libguestfs/blob/master/builder/builder.ml#L...
The --format command line parameter defaults to raw (and this is
documented in the manual). It doesn't matter what the original
template format was.
> Why? I've built my own repo with all xz-compressed qcow images and
> it seems crazy to me that `virt-builder` can't auto-detect this;
> instead, I have to specify `--format qcow2` (or else vb converts
> them from qcow2 to raw)
So virt-builder is behaving as per specification above.
My initial thought was that we could have an `output_format=...' line
in the metadata. However that has a couple of problems:
(1) Other metadata format like SimpleStreams doesn't support this.
(2) It breaks the virt-builder contract because we have documented in
the manual that the default output format (ie. if --format is not
specified) is raw.
However, read on ...
> Halp! Can we either change the default behavior to look for
> `format=qcow2|raw` in the template definition if `--format` isn't
> specified, or if you're unhappy changing the behavior, could we add
> `--format=auto`?
We couldn't call it "auto", since --format=auto is used in other
virt-* tools contexts to mean to do unsafe autodetection of the
format.
I don't mind if we called it something else, perhaps `--format=input'?
It just has to be a name that could never be used as a real disk
format (like 'qcow2' or 'vmdk').
The RFE process is described here:
http://libguestfs.org/guestfs-faq.1.html#how-do-i-propose-a-feature
https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Vi...
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
8 years, 11 months
Can I update a specific package with virt-customize/virt-sysprep
by Yaniv Kaul
I'm using an image (Fedora cloud) which apparently doesn't have iSCSI
kernel module available as-is. I therefore need to update kernel-core in
order to get it.
Is there a way I can do it via virt-sysprep / virt-customize?
I would like on the first boot already to use iSCSI (I'm using a script
there to already login to a target, etc.), so first boot (+ it'll require
an additional boot anyway) is too late for this.
Is there a way to do it, as it seem 'update' updates everything (and thus
bloats my image a bit).
TIA,
Y.
8 years, 11 months
Question: ntfs mount forbidden in rhel-7 branch
by Maxim Perevedentsev
Hello everyone!
I guess this is a frequent question, but how can I mount ntfs partition
using libguestfs rhel-7?
As I see from the commit bound to RHBZ#1240276, this was intentionally
made impossible, for rhel-7 branches. It is true?
I'd like to use ntfs mount functionality, but I'd like to use mainstream
version of libguestfs as well (the version designed for rhel-7 is
expected to be quite reliable).
So could you please explain why ntfs mounting was forbidden (except for
virt-* programs), and how to work around this (I see two options: drop
this patch or set_program("virt-hack")).
Thanks in advance!
--
Your sincerely,
Maxim Perevedentsev
8 years, 11 months
IRC question: can virt-sparsify output to stdout instead of a file?
by Richard W.M. Jones
01:19 < bananapie> without using a named pipe, can virt-sparsify output to stdout instead of a file?
01:20 < bananapie> called from a bash script*
01:43 < bananapie> if I use a named pipe, it says 'Could not refresh total sector count: Operation not permitted'
02:33 < bananapie> ok. I found the answer, virt-sparsify doesn't read linearly, so named pipes doesn't work :(
No.
However, for copying mode (not --inplace), the longer answer is it
could be modified to make it work:
https://rwmj.wordpress.com/2014/10/14/streaming-nbd-server/#content
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
8 years, 11 months
[PATCH 0/3] supermin: add --include-packagelist
by Pino Toscano
Hi,
to ease debugging issues with appliances (e.g. when used in libguestfs),
using --include-packagelist will add a file containing the list of all
the packages used.
Thanks,
Pino Toscano (3):
ext2: add ext2fs_chmod and ext2fs_chown
chroot: factor out file copy code
Add --include-packagelist
src/build.ml | 42 +++++++++++++++++++++++++------
src/chroot.ml | 29 ++++++++++++++++++---
src/ext2.ml | 18 +++++++++++++-
src/ext2fs-c.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/ext2fs.ml | 2 ++
src/ext2fs.mli | 2 ++
src/prepare.ml | 3 ++-
src/supermin.ml | 9 +++++--
src/supermin.pod | 11 ++++++++
9 files changed, 176 insertions(+), 16 deletions(-)
--
2.1.0
8 years, 11 months
[PATCH 1/2] launch: direct: manually compose iscsi:// URIs
by Pino Toscano
Move the creation of iscsi URIs away from make_uri, composing them
manually: this is needed because libxml assumes colons (':') to separate
user and password for the authority part, while with iscsi URIs the
separator is percentage ('%'), which would be percent-encoded by libxml.
---
src/launch-direct.c | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/src/launch-direct.c b/src/launch-direct.c
index 559a032..a26b9c4 100644
--- a/src/launch-direct.c
+++ b/src/launch-direct.c
@@ -1274,9 +1274,34 @@ guestfs_int_drive_source_qemu_param (guestfs_h *g, const struct drive_source *sr
return make_uri (g, "https", src->username, src->secret,
&src->servers[0], src->u.exportname);
- case drive_protocol_iscsi:
- return make_uri (g, "iscsi", NULL, NULL,
- &src->servers[0], src->u.exportname);
+ case drive_protocol_iscsi: {
+ CLEANUP_FREE char *escaped_hostname = NULL;
+ CLEANUP_FREE char *escaped_target = NULL;
+ CLEANUP_FREE char *userauth = NULL;
+ char port_str[16];
+ char *ret;
+
+ escaped_hostname =
+ (char *) xmlURIEscapeStr(BAD_CAST src->servers[0].u.hostname,
+ BAD_CAST "");
+ /* The target string must keep slash as it is, as exportname contains
+ * "iqn/lun".
+ */
+ escaped_target =
+ (char *) xmlURIEscapeStr(BAD_CAST src->u.exportname, BAD_CAST "/");
+ if (src->username != NULL && src->secret != NULL)
+ userauth = safe_asprintf (g, "%s%%%s@", src->username, src->secret);
+ if (src->servers[0].port != 0)
+ snprintf (port_str, sizeof port_str, ":%d", src->servers[0].port);
+
+ ret = safe_asprintf (g, "iscsi://%s%s%s/%s",
+ userauth != NULL ? userauth : "",
+ escaped_hostname,
+ src->servers[0].port != 0 ? port_str : "",
+ escaped_target);
+
+ return ret;
+ }
case drive_protocol_nbd: {
CLEANUP_FREE char *p = NULL;
--
2.1.0
8 years, 11 months