Commit 5ab618bd authored by Leigh B Stoller's avatar Leigh B Stoller

Minor changes to support linux images. Minor bug fixes.

parent 562b2f87
......@@ -39,6 +39,7 @@ sub usage()
my $optlist = "dix:r:";
my $debug = 1;
my $infomode = 0;
my $islinux = 0;
my $VMPATH = "/var/emulab/vms/vminfo";
my $EXTRAFS = "/scratch";
my $VGNAME = "xen-vg";
......@@ -122,7 +123,7 @@ close(XM);
$xminfo{"disksizes"} = "";
#
# Copy the kernel into the directory and change xminfo.
# Copy the kernel (and ramdisk) into the directory and change xminfo.
#
if (! -e $xminfo{"kernel"}) {
Fatal($xminfo{"kernel"} . " does not exist");
......@@ -132,6 +133,21 @@ system("cp " . $xminfo{"kernel"} . " $kernel") == 0
or Fatal("Could not copy kernel to $kernel");
$xminfo{"kernel"} = basename($xminfo{"kernel"});
if (exists($xminfo{"ramdisk"})) {
if (! -e $xminfo{"ramdisk"}) {
Fatal($xminfo{"ramdisk"} . " does not exist");
}
my $ramdisk = "$EXTRAFS/$role/" . basename($xminfo{"ramdisk"});
system("cp " . $xminfo{"ramdisk"} . " $ramdisk") == 0
or Fatal("Could not copy ramdisk to $ramdisk");
$xminfo{"ramdisk"} = basename($xminfo{"ramdisk"});
#
# Yuck. Need a better way to determine this.
#
$islinux = 1;
}
#
# Parse the disk info.
#
......@@ -156,11 +172,11 @@ foreach my $device (keys(%diskinfo)) {
my $spec = $diskinfo{$device}->{"spec"};
my $dev;
my $filename;
if ($spec =~ /,(sd\w+),/) {
if ($spec =~ /,(sd\w+),/ || $spec =~ /,(xvd\w+),/) {
$dev = $1;
}
else {
fatal("Could not parse $spec");
Fatal("Could not parse $spec");
}
$filename = "$role/$dev";
......@@ -168,7 +184,7 @@ foreach my $device (keys(%diskinfo)) {
# Figure out the size of the LVM.
#
my $lv_size = `lvs -o lv_size --noheadings --units g $device`;
fatal("Could not get lvsize for $device")
Fatal("Could not get lvsize for $device")
if ($?);
chomp($lv_size);
$lv_size =~ s/^\s+//;
......@@ -197,13 +213,13 @@ foreach my $device (keys(%diskinfo)) {
#
my $opts = "";
if (defined($options{"x"})) {
if ($device =~ /sda/) {
$opts = "-b";
if ($device =~ /sda/ || $device =~ /xvda/) {
$opts = ($islinux ? "-l" : "-b");
}
}
else {
if (! ($device =~ /disk/)) {
$opts = "-b";
$opts = ($islinux ? "-l" : "-b");
}
}
if ($infomode) {
......@@ -232,7 +248,7 @@ else {
$XMINFO = "$EXTRAFS/$role/xm.conf";
open(XM, ">$XMINFO")
or fatal("Could not open $XMINFO: $!");
or Fatal("Could not open $XMINFO: $!");
foreach my $key (keys(%xminfo)) {
my $val = $xminfo{$key};
if ($val =~ /^\[/) {
......@@ -256,16 +272,16 @@ sub CreateExtraFS()
if (-e $EXTRAFS);
system("mkdir $EXTRAFS") == 0
or fatal("mkdir($EXTRAFS) failed");
or Fatal("mkdir($EXTRAFS) failed");
system("/usr/sbin/lvcreate -n extrafs -L 100G $VGNAME") == 0
or fatal("lvcreate failed");
system("/sbin/lvcreate -n extrafs -L 100G $VGNAME") == 0
or Fatal("lvcreate failed");
system("mke2fs -j /dev/$VGNAME/extrafs") == 0
or fatal("mke2fs failed");
or Fatal("mke2fs failed");
system("mount /dev/$VGNAME/extrafs $EXTRAFS") == 0
or fatal("mount failed");
or Fatal("mount failed");
}
sub Fatal($)
......
......@@ -34,7 +34,7 @@ sub usage()
{
print "Usage: restorevm.pl [-d] [-t targetdir] vnodeid path\n" .
" -d Debug mode.\n".
" -t Write new xm.conf and copy kernel to targetdir\n".
" -t Write new xm.conf and copy kernel/ramdisk to targetdir\n".
" -i Info mode only\n";
exit(-1);
}
......@@ -51,7 +51,6 @@ my $IMAGEDUMP = "imagedump";
$| = 1;
use libvnode_xen;
use libvnode;
# From the library
my $VGNAME = $libvnode_xen::VGNAME;
......@@ -125,17 +124,28 @@ while (<XM>) {
close(XM);
#
# Localize the path to the kernel. Copy out if there is a target dir.
# Localize the path to the kernel (ramdisk). Copy out if there is a target dir.
#
if (defined($targetdir)) {
if (!$infomode) {
system("/bin/cp -pf $path/" . $xminfo{"kernel"} .
" $targetdir/" . $xminfo{"kernel"});
if (exists($xminfo{"ramdisk"})) {
system("/bin/cp -pf $path/" . $xminfo{"ramdisk"} .
" $targetdir/" . $xminfo{"ramdisk"});
}
}
$xminfo{"kernel"} = $targetdir . "/" . $xminfo{"kernel"};
if (exists($xminfo{"ramdisk"})) {
$xminfo{"ramdisk"} = $targetdir . "/" . $xminfo{"ramdisk"};
}
}
else {
$xminfo{"kernel"} = $path . "/" . $xminfo{"kernel"};
if (exists($xminfo{"ramdisk"})) {
$xminfo{"ramdisk"} = $path . "/" . $xminfo{"ramdisk"};
}
}
#
......@@ -194,7 +204,7 @@ foreach my $physinfo (keys(%diskinfo)) {
my $spec = $diskinfo{$physinfo};
my $dev;
my $filename;
if ($spec =~ /,(sd\w+),/) {
if ($spec =~ /,(sd\w+),/ || $spec =~ /,(xvd\w+),/) {
$dev = $1;
}
else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment