1
0
mirror of synced 2026-02-12 10:27:13 +00:00

Use dom0 resolv.conf when chrooting

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.
This commit is contained in:
Stéphane Jourdois
2010-07-10 10:51:38 +02:00
parent 674557233f
commit 09f38740c8
11 changed files with 30 additions and 57 deletions

View File

@@ -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
@@ -3530,11 +3535,19 @@ sub runCustomisationHooks
runCommand($customize);
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");
}

View File

@@ -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
{

View File

@@ -26,11 +26,6 @@ fi
logMessage Script $0 starting
#
# DNS is probably required to run "yum update".
#
cp /etc/resolv.conf ${prefix}/etc
#
# Update yum
#

View File

@@ -26,12 +26,6 @@ fi
logMessage Script $0 starting
#
# DNS is probably required to run "yum update".
#
cp /etc/resolv.conf ${prefix}/etc
#
# Update yum
#

View File

@@ -28,12 +28,6 @@ fi
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.

View File

@@ -27,12 +27,6 @@ fi
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.

View File

@@ -28,12 +28,6 @@ fi
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.

View File

@@ -26,13 +26,6 @@ fi
logMessage Script $0 starting
#
# DNS is probably required to run "yum update".
#
cp /etc/resolv.conf ${prefix}/etc
#
# Update yum
#

View File

@@ -24,12 +24,6 @@ fi
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

View File

@@ -28,12 +28,6 @@ fi
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.

View File

@@ -28,12 +28,6 @@ fi
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.