[PATCH V2] virt-sysprep:add ipconfig for preparation
by Wanlong Gao
Hi Rich:
V1->V2: add the documentation.
Any comments?
Thanks,
Wanlong Gao
---------------------------------------------------------------------------------------------------
Add the the ipconfig for vir-prep.
Usage like below:
[root@Allen ~]# virt-sysprep --ipconfig="eth0:192.168.1.2,255.255.255.0,192.168.1.1" --enable=ipconfig -d clone-6u1
OR
[root@Allen ~]# virt-sysprep -d clone-6u1
Signed-off-by: Wanlong Gao <gaowanlong(a)cn.fujitsu.com>
---
clone/virt-sysprep.in | 51 +++++++++++++++++++++++++++++++++++++++++++++++-
clone/virt-sysprep.pod | 19 ++++++++++++++++++
2 files changed, 69 insertions(+), 1 deletion(-)
diff --git a/clone/virt-sysprep.in b/clone/virt-sysprep.in
index d505532..557d46a 100644
--- a/clone/virt-sysprep.in
+++ b/clone/virt-sysprep.in
@@ -26,7 +26,7 @@ version="@PACKAGE_VERSION@"
TEMP=`getopt \
-o a:c:d:vVx \
- --long help,add:,connect:,domain:,enable:,format::,hostname:,list-operations,selinux-relabel,no-selinux-relabel,verbose,version \
+ --long help,add:,connect:,domain:,enable:,format::,hostname:,ipconfig:,list-operations,selinux-relabel,no-selinux-relabel,verbose,version \
-n $program -- "$@"`
if [ $? != 0 ]; then
echo "$program: problem parsing the command line arguments"
@@ -91,6 +91,9 @@ while true; do
--hostname)
hostname_param="$2"
shift 2;;
+ --ipconfig)
+ ipconfig_param="$2"
+ shift 2;;
--list-operations)
enable=list
shift;;
@@ -135,6 +138,7 @@ if [ -z "$enable" ]; then
dhcp_client_state=yes
dhcp_server_state=yes
hostname=yes
+ ipconfig=yes
logfiles=yes
mail_spool=yes
net_hwaddr=yes
@@ -150,6 +154,7 @@ elif [ "$enable" = "list" ]; then
echo "dhcp-client-state"
echo "dhcp-server-state"
echo "hostname"
+ echo "ipconfig"
echo "logfiles"
echo "mail-spool"
echo "net-hwaddr"
@@ -168,6 +173,7 @@ else
dhcp-client-state) dhcp_client_state=yes ;;
dhcp-server-state) dhcp_server_state=yes ;;
hostname) hostname=yes ;;
+ ipconfig) ipconfig=yes ;;
logfiles) logfiles=yes ;;
mail-spool) mail_spool=yes ;;
net-hwaddr) net_hwaddr=yes ;;
@@ -286,6 +292,49 @@ if [ "$hostname" = "yes" ]; then
esac
fi
+#FIXME: This may not work OK for IPv6 ?
+if [ "$ipconfig" = "yes" ]; then
+ case "$type/$distro" in
+ linux/fedora|linux/rhel)
+ if [ -d $mnt/etc/sysconfig/network-scripts ]; then
+ if [ -z $ipconfig_param ]; then
+ rm_ipconfig ()
+ {
+ sed '/^IPADDR=/d;/^BOOTPROTO=/d;/^NETMASK=/d;/^GATEWAY=/d;/^DNS/d' \
+ < "$1" > "$1.new"
+ echo "BOOTPROTO=dhcp" >> "$1.new"
+ mv -f "$1.new" "$1"
+ }
+ export -f rm_ipconfig
+ find $mnt/etc/sysconfig/network-scripts \
+ -name 'ifcfg-*' -type f \
+ -exec bash -c 'rm_ipconfig "$0"' {} \;
+ else
+ for (( i=1; i<8 ; i+=2 )); do
+ __device=$(echo "$ipconfig_param" | awk -v j=$i -F: '{print $j}')
+ if [ -z $__device ]; then
+ break
+ fi
+ __ipconfig=$(echo "$ipconfig_param" | awk -v j=$((i+1)) -F: '{print $j}')
+ __config_file=$(echo "$mnt/etc/sysconfig/network-scripts/ifcfg-$__device")
+ if [ -e $__config_file ]; then
+ __ip=$(echo "$__ipconfig" | awk -F, '{print $1}')
+ __mask=$(echo "$__ipconfig" | awk -F, '{print $2}')
+ __gw=$(echo "$__ipconfig" | awk -F, '{print $3}')
+ sed '/^IPADDR=/d;/^BOOTPROTO=/d;/^NETMASK=/d;/^GATEWAY=/d;/^DNS/d' \
+ < "$__config_file" > "$__config_file.new"
+ echo "IPADDR=$__ip" >> "$__config_file.new"
+ echo "BOOTPROTO=static" >> "$__config_file.new"
+ echo "NETMASK=$__mask" >> "$__config_file.new"
+ echo "GATEWAY=$__gw" >> "$__config_file.new"
+ mv -f "$__config_file.new" "$__config_file"
+ fi
+ done
+ fi
+ fi
+ esac
+fi
+
if [ "$logfiles" = "yes" ]; then
case "$type" in
linux)
diff --git a/clone/virt-sysprep.pod b/clone/virt-sysprep.pod
index 5cab3eb..c699887 100755
--- a/clone/virt-sysprep.pod
+++ b/clone/virt-sysprep.pod
@@ -121,6 +121,17 @@ security problem with malicious guests (CVE-2010-3851).
Change the hostname. See the L</hostname> operation below.
If not given, defaults to C<localhost.localdomain>.
+=item B<--ipconfig> "device1:ipaddr,netmask,gateway:device2:ipaddr,..."
+
+Change the IP configuration. See the L</ipconfig> operation below.
+If not given, defaults to C<dhcp>.
+
+For example:
+
+ --ipconfig "eth0:192.168.122.2,255.255.255.0,192.168.122.1:eth1:192.168.122.3,255.255.255.0,192.168.122.1"
+
+You can configure the IP of any existent net device in the guest.
+
=item B<--list-operations>
List the operations supported by the virt-sysprep program.
@@ -191,6 +202,14 @@ I<--hostname> parameter.
If the I<--hostname> parameter is not given, then the hostname is
changed to C<localhost.localdomain>.
+=head2 ipconfig
+
+Changes the IP configuration of the guest to the value given in
+the I<--ipconfig> parameter.
+
+If the I<--ipconfig> parameter is not given, then the IP configuration
+all changed to C<dhcp>.
+
=head2 logfiles
Remove many log files.
--
1.7.10.rc0
12 years, 9 months
Compilation troubles
by Alessandro Dentella
Hi,
I'm trying to compile hivex library that I just discovered. I'd use binaries
but I only have an i386 ubuntu and debian so I tryied to compile.
./configure finished with incouraging::
-----------------------------------------------------------
Thank you for downloading hivex 1.3.3
This is how we have configured the optional components for you today:
OCaml bindings ...................... no
Perl bindings ....................... yes
Python bindings ..................... yes
Ruby bindings ....................... no
If any optional component is configured 'no' when you expected 'yes'
then you should check the preceeding messages.
Please report bugs back to the mailing list:
http://www.redhat.com/mailman/listinfo/libguestfs
Next you should type 'make' to build the package,
then 'make check' to run the tests.
------------------------------------------------------------
but then compilation end badly::
Making all in xml
make[2]: Entering directory `/tmp/hivex-1.3.3/xml'
CCLD hivexml
hivexml-hivexml.o: In function `main':
/tmp/hivex-1.3.3/xml/hivexml.c:96: undefined reference to `rpl_getopt'
/tmp/hivex-1.3.3/xml/hivexml.c:110: undefined reference to `rpl_optind'
/tmp/hivex-1.3.3/xml/hivexml.c:154: undefined reference to `rpl_optind'
collect2: ld returned 1 exit status
make[2]: *** [hivexml] Error 1
make[2]: Leaving directory `/tmp/hivex-1.3.3/xml'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/tmp/hivex-1.3.3'
make: *** [all] Errore 2
And I'm not enought skilled to understand it. The error is on ubuntu 10.04.
A complete log can be viewd at http://pastebin.com/0s9UnxPh
thanks for any possible hints
sandro
*:-)
PS: I dont have libguestfs as I just need to batch modify (preferably via
Python) some profile NTUSER.DAT. My understanding is that hivex does not
depend on libguestfs.
12 years, 9 months
[PATCH] Coalesce printable characters in debug and trace messages (RHBZ#802109).
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
---
src/events.c | 25 +++++++++++++++++--------
1 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/src/events.c b/src/events.c
index f707e0b..9a1ca76 100644
--- a/src/events.c
+++ b/src/events.c
@@ -120,8 +120,7 @@ guestfs___call_callbacks_message (guestfs_h *g, uint64_t event,
event == GUESTFS_EVENT_TRACE) &&
(g->verbose || event == GUESTFS_EVENT_TRACE)) {
int from_appliance = event == GUESTFS_EVENT_APPLIANCE;
- size_t i;
- char c;
+ size_t i, i0;
/* APPLIANCE => <buf>
* LIBRARY => libguestfs: <buf>\n
@@ -147,13 +146,23 @@ guestfs___call_callbacks_message (guestfs_h *g, uint64_t event,
* Case 2: Messages from other sources: These messages should NOT
* contain \n or \r. If they do, it is escaped. However we also
* need to print a real end of line after these messages.
+ *
+ * RHBZ#802109: Because stderr is usually not buffered, avoid
+ * single 'putc' calls (which translate to a 1 byte write), and
+ * try to send longest possible strings in single fwrite calls
+ * (thanks to Jim Meyering for the basic approach).
*/
+#define NO_ESCAPING(c) \
+ (c_isprint ((c)) || (from_appliance && ((c) == '\n' || (c) == '\r')))
+
for (i = 0; i < buf_len; ++i) {
- c = buf[i];
- if (c_isprint (c) || (from_appliance && (c == '\n' || c == '\r')))
- putc (c, stderr);
- else {
- switch (c) {
+ if (NO_ESCAPING (buf[i])) {
+ i0 = i;
+ while (i < buf_len && NO_ESCAPING (buf[i]))
+ ++i;
+ fwrite (&buf[i0], 1, i-i0, stderr);
+ } else {
+ switch (buf[i]) {
case '\0': fputs ("\\0", stderr); break;
case '\a': fputs ("\\a", stderr); break;
case '\b': fputs ("\\b", stderr); break;
@@ -163,7 +172,7 @@ guestfs___call_callbacks_message (guestfs_h *g, uint64_t event,
case '\t': fputs ("\\t", stderr); break;
case '\v': fputs ("\\v", stderr); break;
default:
- fprintf (stderr, "\\x%x", (unsigned) c);
+ fprintf (stderr, "\\x%x", (unsigned) buf[i]);
}
}
}
--
1.7.9.1
12 years, 9 months
[PATCH 0/5] Fixes to resize2fs (RHBZ#755729, RHBZ#801640)
by Richard W.M. Jones
https://bugzilla.redhat.com/show_bug.cgi?id=755729
This bug reports that the error message printed by the resize2fs API
calls (which comes directly from the resize2fs command) says:
Please run 'e2fsck -f /dev/vda1' first.
That command is not possible from guestfish (where it would be
'e2fsck-f' or 'e2fsck ... forceall:true').
Fixing that bug caused this bug:
https://bugzilla.redhat.com/show_bug.cgi?id=801640
By replacing the error message, we inadvertently replaced an important
(and different) error message:
Please run 'e2fsck -fy /dev/vda1' to fix the filesystem
after the aborted resize operation.
which occurs *after* a resize operation fails.
I proposed that we don't try editing error messages at all, even when
(as in 755729) this leads to some slightly inappropriate text being
printed in guestfish.
Trying to replace error messages is an open-ended task. It risks
causing more bugs, and it obscures what the underlying utility is
trying to say. Google exists, and people can use it to resolve
these problems.
This patch series starts by reverting the original fix.
Patch 4/5 causes the resize2fs* APIs to automatically run 'e2fsck -f'
when necessary, both simplifying the API and avoiding 755729.
Patch 5/5 documents the whole mess.
Rich.
12 years, 9 months
[PATCH 1/2] Close all file descriptors in the recovery process.
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
If the parent process uses a pipe (or any fd, but pipes are a
particular problem), then the recovery process would hold open the
file descriptor(s) of the pipe, meaning that it could not be fully
closed in the parent. Because the recovery process doesn't use
exec(2), this wasn't avoidable even using FD_CLOEXEC.
Avoid this by closing all file descriptors when starting the recovery
process.
---
src/launch.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/src/launch.c b/src/launch.c
index 1dc23f4..a9af445 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -844,9 +844,21 @@ launch_appliance (guestfs_h *g)
if (g->recovery_proc) {
r = fork ();
if (r == 0) {
+ int fd, max_fd;
pid_t qemu_pid = g->pid;
pid_t parent_pid = getppid ();
+ /* Close all other file descriptors. This ensures that we don't
+ * hold open (eg) pipes from the parent process.
+ */
+ max_fd = sysconf (_SC_OPEN_MAX);
+ if (max_fd == -1)
+ max_fd = 1024;
+ if (max_fd > 65536)
+ max_fd = 65536; /* bound the amount of work we do here */
+ for (fd = 0; fd < max_fd; ++fd)
+ close (fd);
+
/* It would be nice to be able to put this in the same process
* group as qemu (ie. setpgid (0, qemu_pid)). However this is
* not possible because we don't have any guarantee here that
--
1.7.9.1
12 years, 9 months
ESX Cluster
by John Holland
>
>Hello,
>we are learning how to use virt-v2v and are about to look at converting
>VMware instances. Our VMware admin
>says that the VMware server setup is a windows box with three linux
>boxes in a cluster.
>
>
>Does it matter which linux box we connect to ?
>
>Is it adequate to install libvirt and sshd on that box to enable the
>transfer? Does it need the PKI stuff - cacert.pem etc?
>
>
>Thanks,
>John Holland
12 years, 9 months
Re: [Libguestfs] mounting using guestfish
by Richard W.M. Jones
[Please remember to post all questions on the mailing list]
On Thu, Mar 08, 2012 at 09:41:19PM +0700, Tho Huynh wrote:
> Can I mount the guest's file system into a folder/path (mountpoint)
> in the host machine using guestfish?
No, but you don't need to.
> And accessing that folder equal to accessing the guest's file
> system. What I'm trying to do is to copy a file from one guest to
> another directly but to achieve full disk speed.
Guestfish cannot connect to two guests at the same time, so you would
need to download the file from one guest and upload it to the other.
(I'm still assuming here that you are using libguestfs live). eg:
guestfish --live -d Source download /some/file /tmp/file
guestfish --live -d Destination upload /tmp/file /some/file
If that isn't fast enough or you need to avoid the local copy, it is
possible to connect two handles together and copy the file directly
between them, but you'd have to write a script against the API (eg. in
Perl/Python/etc).
. . .
In the *non-live* case, there is another method: add the disks of both
guests, 'launch', and copy the file between mountpoints (see the
'mkmountpoint' command). Surprisingly, this is not necessarily going
to be faster than downloading and uploading. This method also has
some limitations -- it's not possible to use two guests that have
conflicting volume group names; and even security issues -- a
malicious guest could interfere with the other guest.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
12 years, 9 months
[PATCH] Fix the default value of "pgroup".
by Qixiang Wan
As the document said, the default value of "pgroup" should be false.
Signed-off-by: Qixiang Wan <qwan(a)redhat.com>
---
fish/fish.c | 2 +-
src/guestfs.c | 3 +++
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/fish/fish.c b/fish/fish.c
index 575fe99..fbacbb9 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -406,7 +406,7 @@ main (int argc, char *argv[])
sigaction (SIGINT, &sa, NULL);
sigaction (SIGQUIT, &sa, NULL);
- guestfs_set_pgroup (g, 1);
+ guestfs_set_pgroup (g, 0);
}
/* Old-style -i syntax? Since -a/-d/-N and -i was disallowed
diff --git a/src/guestfs.c b/src/guestfs.c
index 3493d79..2ff506b 100644
--- a/src/guestfs.c
+++ b/src/guestfs.c
@@ -143,6 +143,9 @@ guestfs_create (void)
*/
g->msg_next_serial = 0x00123400;
+ /* Default is 'false' to allow users to interrupt the subprocess. */
+ g->pgroup = 0;
+
/* Default is uniprocessor appliance. */
g->smp = 1;
--
1.7.7.6
12 years, 9 months
Re: [Libguestfs] copy file from host to live guest (speed)
by Richard W.M. Jones
On Wed, Mar 07, 2012 at 05:57:45AM -0800, THO HUYNH wrote:
> I tried to copy file from host to the running guest after I had
> mounted the guest but it`s seemed slow. The speed is about 6-8
> MB/s. I thought it would be the same with real hard drive (about
> 20MB/s).
Is this using 'guestmount --live'?
Unfortunately FUSE is inefficient, particularly the way we implement
it in guestmount.
If you use 'guestfish --live' and the 'upload' command, you should be
able to get full disk speed easily.
> If I have more than one guest, will they share the 6-8 MB bandwidth ?
If the guest storage is on different spindles, then you should be able
to max out each spindle (using guestfish, not guestmount). If they
all share the same disk spindle, then of course it will share the disk
bandwidth.
> Are there anyway to improve the performance ?
Definitely use guestfish, or the libguestfs API directly.
If you want to copy in large amounts of data, then *sometimes* it can
be advantageous to prepare an ISO containing the data in advance:
http://libguestfs.org/guestfs.3.html#uploading
but you should measure it because it might not actually be faster,
since uploads use virtio-serial which is very fast.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
12 years, 9 months
p2v with cciss failure
by Mike Brady
I have continued on with my attempts to get p2v working will little success.
I have changed my server to Fedora 16 and finally got an XP with a
single SATA disk (sda) to work. I think that this means that the
current virt-p2v.iso just doesn't work with the packages that are
available on Centos 6 at the moment.
However, the machines that I currently need to actually migrate all
have cciss controllers of some sort in them. For testing I have two
very different servers with different controllers in them that both
use the cciss driver that fail to complete the transfer of the image.
Debug output is listed below, but doesn't give me any clues as to what
to look at next.
Mar 1 10:44:16 c2cl00 virt-v2v[6721]: p2v-server started.
Mar 1 10:44:16 c2cl00 virt-v2v[6721]: Received: LIST_PROFILES
Mar 1 10:44:16 c2cl00 virt-v2v[6721]: Sent: LIST 1#012libvirt
Mar 1 10:45:50 c2cl00 kernel: lo: Disabled Privacy Extensions
Mar 1 10:46:24 c2cl00 virt-v2v[6721]: Received: SET_PROFILE libvirt
Mar 1 10:46:24 c2cl00 virt-v2v[6721]: Sent: OK
Mar 1 10:46:24 c2cl00 virt-v2v[6721]: Received: METADATA 224
Mar 1 10:46:24 c2cl00 virt-v2v[6721]: Read 224 bytes
Mar 1 10:46:24 c2cl00 virt-v2v[6721]: Sent: OK
Mar 1 10:46:24 c2cl00 virt-v2v[6721]: Received: PATH 320016572416
/dev/cciss/c0d0
Mar 1 10:46:24 c2cl00 virt-v2v[6721]: Pool: $VAR1 = bless( do{\(my $o
= 23313248)}, 'Sys::Virt::StoragePool' );
Mar 1 10:46:25 c2cl00 virt-v2v[6721]: Sent: OK
Mar 1 10:46:25 c2cl00 virt-v2v[6721]: Received: CONTAINER RAW
Mar 1 10:46:25 c2cl00 virt-v2v[6721]: Sent: OK
Mar 1 10:46:25 c2cl00 virt-v2v[6721]: Received: DATA 320016572416
Mar 1 10:46:25 c2cl00 virt-v2v[6721]: Read 4194304 bytes
Mar 1 10:46:25 c2cl00 virt-v2v[6721]: Read 4194304 bytes
Mar 1 10:46:25 c2cl00 virt-v2v[6721]: Read 4194304 bytes
.
.
.
Mar 1 11:33:12 c2cl00 virt-v2v[6721]: Read 4194304 bytes
Mar 1 11:33:12 c2cl00 virt-v2v[6721]: Read 4194304 bytes
Mar 1 11:33:12 c2cl00 virt-v2v[6721]: Read 65536 bytes
Mar 1 11:33:14 c2cl00 virt-v2v[6721]: Sent: ERROR Error receiving data:
Mar 1 11:33:14 c2cl00 virt-v2v[6721]: FATAL: Error receiving data:
Mar 1 11:33:14 c2cl00 virt-v2v[6721]: WARNING: Error messages were
written to /var/log/virt-p2v-server.1330551856.log.
Mar 1 11:33:14 c2cl00 virt-v2v[6721]: p2v-server exited.
Mar 1 11:33:14 c2cl00 virt-v2v[6721]: Automatically cleaning up
volume win2008-cciss_c0d0 from pool {pool}.
The file /var/log/virt-p2v-server.1330551856.log contains
-----Start
virt-v2v: Error receiving data:
-----End
This failure is repeatable for each server in that each will fail at
the same point if I try the transfer again. The amount of data
transferred before failure for each server is different.
I have tried different array configurations and the transfer fails
with differing, but repeatable for that particular configuration,
amounts of data transferred.
The destination storage pool is an LVM volume group and the volume is
not "Automatically cleaning up" as the log says and is not called
"pool" as I think that the log is indicating.
The virt-p2v.iso being used was created on a Fedora 16 32 bit machine
and has virt-v2v 0.8.5 installed, as does the server that I am now
using.
At this point I am leaning towards there being an issue with the cciss
drivers on the virt-p2v.iso, but am not sure what to try next.
Any help would be appreciated.
Thanks
Mike
12 years, 9 months