[xen-tools-dev] [PATCH] Use dom0 resolv.conf when chrooting
Stéphane Jourdois
sjourdois at gmail.com
Sat Jul 10 12:52:16 CEST 2010
Temporarily use resolv.conf from dom0 when chrooting into domU,
to be able to run apt-get and yum inside chroot.
This permits to use different nameservers in domU, and does not
break install nor offline update from dom0.
---
bin/xen-create-image | 17 +++++++++++++++--
bin/xen-update-image | 15 +++++++++++++++
hooks/centos-4/20-setup-yum | 5 -----
hooks/centos-5/20-setup-yum | 6 ------
hooks/dapper/20-setup-apt | 6 ------
hooks/debian/20-setup-apt | 6 ------
hooks/edgy/20-setup-apt | 6 ------
hooks/fedora-core-6/20-setup-yum | 7 -------
hooks/gentoo/60-copy-host-files | 7 -------
hooks/intrepid/20-setup-apt | 6 ------
hooks/karmic/20-setup-apt | 6 ------
11 files changed, 30 insertions(+), 57 deletions(-)
diff --git a/bin/xen-create-image b/bin/xen-create-image
index e27e740..3f651fe 100755
--- a/bin/xen-create-image
+++ b/bin/xen-create-image
@@ -742,7 +742,7 @@ use Digest::MD5 qw/ md5_hex /;
use Env;
use File::Path qw/ mkpath /;
use File::Temp qw/ tempdir /;
-use File::Copy qw/ cp /;
+use File::Copy qw/ mv cp /;
use Getopt::Long;
use Pod::Usage;
@@ -3516,6 +3516,11 @@ sub runCustomisationHooks
}
}
+ #
+ # Copy dom0's resolv.conf to domU
+ #
+ mv("$MOUNT_POINT/etc/resolv.conf", "$MOUNT_POINT/etc/resolv.conf.old") if -f "$MOUNT_POINT/etc/resolv.conf";
+ cp("/etc/resolv.conf", "$MOUNT_POINT/etc/resolv.conf");
#
# Actually run the appropriate hooks
@@ -3531,10 +3536,18 @@ sub runCustomisationHooks
logprint("Done\n");
#
+ # Restore domU's resolv.conf if needed
+ #
+ if (-f "$MOUNT_POINT/etc/resolv.conf") {
+ mv("$MOUNT_POINT/etc/resolv.conf.old", "$MOUNT_POINT/etc/resolv.conf");
+ } else {
+ unlink "$MOUNT_POINT/etc/resolv.conf";
+ }
+
+ #
# Unmount /proc in the guest install.
#
runCommand("umount $MOUNT_POINT/proc");
-
}
diff --git a/bin/xen-update-image b/bin/xen-update-image
index 307088c..b7fa08c 100755
--- a/bin/xen-update-image
+++ b/bin/xen-update-image
@@ -105,6 +105,7 @@ The LICENSE file contains the full text of the license.
use strict;
use English;
use File::Temp qw/ tempdir /;
+use File::Copy qw/ mv cp /;
use Getopt::Long;
use Pod::Usage;
@@ -287,6 +288,11 @@ sub updateXenImage
if ( ( -e $tmp . "/usr/bin/apt-get" ) &&
( -x $tmp . "/usr/bin/apt-get" ) )
{
+ #
+ # Copy dom0's resolv.conf to domU
+ #
+ mv("$tmp/etc/resolv.conf", "$tmp/etc/resolv.conf.old") if -f "$tmp/etc/resolv.conf";
+ cp("/etc/resolv.conf", "$tmp/etc/resolv.conf");
#
# Now run the update command.
@@ -300,6 +306,15 @@ sub updateXenImage
system(
"DEBIAN_FRONTEND=noninteractive chroot $tmp /usr/bin/apt-get upgrade --yes --force-yes"
);
+
+ #
+ # Restore domU's resolv.conf if needed
+ #
+ if (-f "$tmp/etc/resolv.conf") {
+ mv("$tmp/etc/resolv.conf.old", "$tmp/etc/resolv.conf");
+ } else {
+ unlink "$tmp/etc/resolv.conf";
+ }
}
else
{
diff --git a/hooks/centos-4/20-setup-yum b/hooks/centos-4/20-setup-yum
index 96c1f14..8fed170 100755
--- a/hooks/centos-4/20-setup-yum
+++ b/hooks/centos-4/20-setup-yum
@@ -27,11 +27,6 @@ logMessage Script $0 starting
#
-# DNS is probably required to run "yum update".
-#
-cp /etc/resolv.conf ${prefix}/etc
-
-#
# Update yum
#
if [ ! -d ${prefix}/proc ]; then
diff --git a/hooks/centos-5/20-setup-yum b/hooks/centos-5/20-setup-yum
index a962f7e..acb363d 100755
--- a/hooks/centos-5/20-setup-yum
+++ b/hooks/centos-5/20-setup-yum
@@ -27,12 +27,6 @@ logMessage Script $0 starting
#
-# DNS is probably required to run "yum update".
-#
-cp /etc/resolv.conf ${prefix}/etc
-
-
-#
# Update yum
#
if [ ! -d ${prefix}/proc ]; then
diff --git a/hooks/dapper/20-setup-apt b/hooks/dapper/20-setup-apt
index 2566236..475f8c6 100755
--- a/hooks/dapper/20-setup-apt
+++ b/hooks/dapper/20-setup-apt
@@ -29,12 +29,6 @@ logMessage Script $0 starting
#
-# You will probably need DNS to run "apt-get update"
-#
-cp /etc/resolv.conf ${prefix}/etc
-
-
-#
# Attempt to auto-magically detect the use of a Proxy for apt-get, and
# replicate that setup in our new guest.
#
diff --git a/hooks/debian/20-setup-apt b/hooks/debian/20-setup-apt
index 9c8189b..28097d4 100755
--- a/hooks/debian/20-setup-apt
+++ b/hooks/debian/20-setup-apt
@@ -28,12 +28,6 @@ logMessage Script $0 starting
#
-# You'll probably need DNS to run "apt-get update".
-#
-cp /etc/resolv.conf ${prefix}/etc
-
-
-#
# Attempt to auto-magically detect the use of a Proxy for apt-get, and
# replicate that setup in our new guest.
#
diff --git a/hooks/edgy/20-setup-apt b/hooks/edgy/20-setup-apt
index 557e914..a0e185f 100755
--- a/hooks/edgy/20-setup-apt
+++ b/hooks/edgy/20-setup-apt
@@ -29,12 +29,6 @@ logMessage Script $0 starting
#
-# You will probably need DNS to run "apt-get update"
-#
-cp /etc/resolv.conf ${prefix}/etc
-
-
-#
# Attempt to auto-magically detect the use of a Proxy for apt-get, and
# replicate that setup in our new guest.
#
diff --git a/hooks/fedora-core-6/20-setup-yum b/hooks/fedora-core-6/20-setup-yum
index dfbf5e9..84a7ddf 100755
--- a/hooks/fedora-core-6/20-setup-yum
+++ b/hooks/fedora-core-6/20-setup-yum
@@ -27,13 +27,6 @@ logMessage Script $0 starting
#
-# DNS is probably required to run "yum update".
-#
-cp /etc/resolv.conf ${prefix}/etc
-
-
-
-#
# Update yum
#
if [ ! -d ${prefix}/proc ]; then
diff --git a/hooks/gentoo/60-copy-host-files b/hooks/gentoo/60-copy-host-files
index 253ded5..6202ad1 100755
--- a/hooks/gentoo/60-copy-host-files
+++ b/hooks/gentoo/60-copy-host-files
@@ -25,12 +25,6 @@ logMessage Script $0 starting
#
-# Copy "required" files from our host.
-#
-cp /etc/resolv.conf ${prefix}/etc
-
-
-#
# If the host has sudo then copy the configuration file, and install
# the package
#
@@ -41,7 +35,6 @@ if [ -e /etc/sudoers ]; then
#
# Copy file and fixup permissions.
#
- cp /etc/resolv.conf ${prefix}/etc
chown root:root ${prefix}/etc/sudoers
chmod 440 ${prefix}/etc/sudoers
diff --git a/hooks/intrepid/20-setup-apt b/hooks/intrepid/20-setup-apt
index 557e914..a0e185f 100755
--- a/hooks/intrepid/20-setup-apt
+++ b/hooks/intrepid/20-setup-apt
@@ -29,12 +29,6 @@ logMessage Script $0 starting
#
-# You will probably need DNS to run "apt-get update"
-#
-cp /etc/resolv.conf ${prefix}/etc
-
-
-#
# Attempt to auto-magically detect the use of a Proxy for apt-get, and
# replicate that setup in our new guest.
#
diff --git a/hooks/karmic/20-setup-apt b/hooks/karmic/20-setup-apt
index 557e914..a0e185f 100755
--- a/hooks/karmic/20-setup-apt
+++ b/hooks/karmic/20-setup-apt
@@ -29,12 +29,6 @@ logMessage Script $0 starting
#
-# You will probably need DNS to run "apt-get update"
-#
-cp /etc/resolv.conf ${prefix}/etc
-
-
-#
# Attempt to auto-magically detect the use of a Proxy for apt-get, and
# replicate that setup in our new guest.
#
--
1.5.6.5
More information about the xen-tools-dev
mailing list