mfs 6.61 KB
Newer Older
1 2 3 4 5 6
#
# 
#
use strict;
use libinstall;
use installvars;
7
use emutil;
8

Leigh B Stoller's avatar
Leigh B Stoller committed
9 10 11
my $MFSTARBALL	    = ($ELABINELAB ?
		       "tftpboot-elabinelab.tar.gz" :
		       "tftpboot-latest.tar.gz");
12
my $MFSURL	    = "http://www.emulab.net/downloads/$MFSTARBALL";
13
my $MFSCONSOLE      = $NODECONSOLE;
14
my $MFSDESCRIPTORS  = "$TOP_SRCDIR/install/descriptors-mfs.xml";
15
my $LOCALIZE_MFS    = "$PREFIX/sbin/localize_mfs";
16
my $ZONEINFO	    = "/usr/share/zoneinfo";
17 18 19 20 21

sub Install($$$)
{
    my ($server, $isupdate, $impotent) = @_;

22
    #
23
    # Configure can override setting it here.
24 25 26 27 28 29
    #
    # XXX defaulting this based on the OS running on the boss node is sketchy.
    # It should really be based on the LCD of the experiment nodes. Quite
    # likely, multiple MFSes will be needed as newer HW will not be supported
    # by older MFSes and vice versa.
    #
30
    if ($MFSVERSION eq "") {
31 32 33 34 35
	if (($FBSD_MAJOR > 10 || ($FBSD_MAJOR == 10 && $FBSD_MINOR >= 3)) &&
	    $FBSD_ARCH eq "amd64") {
	    $MFSVERSION = "10-64";
	}
	elsif ($FBSD_MAJOR > 8 || ($FBSD_MAJOR == 8 && $FBSD_MINOR >= 2)) {
36 37 38 39 40
	    if ($FBSD_ARCH eq "amd64") {
		$MFSVERSION = "8-64";
	    } else {
		$MFSVERSION = "82";
	    }
41 42
	}
	elsif ($FBSD_MAJOR > 7 || $FBSD_MAJOR == 7 && $FBSD_MINOR >= 2) {
43 44 45 46 47
	    $MFSVERSION = "72";
	}
	else {
	    $MFSVERSION = "62";
	}
48
    }
49 50 51 52
    if ($MFSVERSION eq "62" || $MFSVERSION eq "47") {
	$MFSTARBALL = "tftpboot-legacy.tar.gz";
	$MFSURL = "http://www.emulab.net/downloads/$MFSTARBALL";
    }
53

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    #
    # Want to recreate the directory and start over. 
    #
    if ($isupdate) {
	Phase "tftpboot_rename", "Backing up $TFTP_DIR", sub {
	    DoneIfDoesntExist($TFTP_DIR);
	    BackupDirectoryFatal($TFTP_DIR);
	    ExecQuietFatal("/bin/rm -rf $TFTP_DIR")
		if (!$impotent);
	};
	Phase "tftpboot_recreate", "Recreating $TFTP_DIR", sub {
	    DoneIfExists($TFTP_DIR);
	    mkdir $TFTP_DIR,0775 or
		PhaseFail("Unable to create $TFTP_DIR : $!");
	    ExecQuietFatal("$CHGRP tbadmin $TFTP_DIR");
	};
    }

72 73
    Phase "mfs", "Setting up MFSs", sub {
	my $localfile = "$TFTP_DIR/tftpboot.tar.gz";
74
	my $kernelvers;
75 76 77 78 79 80 81 82 83 84 85 86 87
	
	Phase "mfsfetch", "Fetching MFS tarball", sub {
	    DoneIfExists($localfile);
	    FetchFileFatal($MFSURL, $localfile);
	};
	Phase "mfsunpack", "Unpacking MFS tarball", sub {
	    DoneIfExists("$TFTP_DIR/README");
	    ExecQuietFatal("$TAR xzf $localfile -C $TFTP_DIR");
	};
	#
	# Its the generic stuff; must localize.
	#
	my $fv = $MFSVERSION;
88 89 90 91 92 93 94 95 96 97 98 99 100

	#
	# XXX hack, hack. Right now there is no FreeBSD 11 MFS,
	# just a FreeBSD 11 kernel to use with FreeBSD 10 MFS.
	#
	if ($fv eq "11-64") {
	    $fv = "10-64";
	    if (-x "$TFTP_DIR/freebsd/boot/kernel11" ||
		-x "$TFTP_DIR/freebsd10-64/boot/kernel11") {
		$kernelvers = 11;
	    }
	}

101
	if (! -e "$TFTP_DIR/freebsd${fv}") {
102 103 104 105 106
	    if ($fv eq "10-64") {
		$fv = "8-64";
	    } else {
		$fv = "47";
	    }
107 108 109 110 111
	}
	my $pdir = ".";
	if (-d "$TFTP_DIR/pxeboot${fv}") {
	    $pdir = "pxeboot${fv}";
	}
Leigh B Stoller's avatar
Leigh B Stoller committed
112 113 114
	elsif (-d "$TFTP_DIR/pxeboot72") {
	    $pdir = "pxeboot72";
	}
115 116 117 118
	my $cons = $MFSCONSOLE;
	if (! -e "$TFTP_DIR/$pdir/pxeboot.emu-${cons}") {
	    $cons = "sio";
	}
Leigh B Stoller's avatar
Leigh B Stoller committed
119
	Phase "pxemv", "Using ${cons} version of $pdir", sub {
120 121
	    DoneIfExists("$TFTP_DIR/pxeboot.emu");
	    ExecQuietFatal("cd $TFTP_DIR; ".
Leigh B Stoller's avatar
Leigh B Stoller committed
122
			   "$CP -p $pdir/pxeboot.emu-${cons} pxeboot.emu");
123 124 125 126
	};
	Phase "freemv", "Using freebsd${fv} version of admin MFS", sub {
	    DoneIfExists("$TFTP_DIR/freebsd");
	    ExecQuietFatal("cd $TFTP_DIR; $MV freebsd${fv} freebsd");
127 128 129 130 131 132 133
	    # find the best MFS kernel to use
	    if (!$kernelvers) {
		if (-x "$TFTP_DIR/freebsd/boot/kernel10") {
		    $kernelvers = 10;
		} elsif (-x "$TFTP_DIR/freebsd/boot/kernel9") {
		    $kernelvers = 9;
		}
134
	    }
135 136 137 138
	};
	Phase "frismv", "Using frisbee${fv} version of disk load MFS", sub {
	    DoneIfExists("$TFTP_DIR/frisbee");
	    ExecQuietFatal("cd $TFTP_DIR; $MV frisbee${fv} frisbee");
139 140 141 142 143 144 145
	    # find the best MFS kernel to use
	    if (!$kernelvers) {
		if (-x "$TFTP_DIR/frisbee/boot/kernel10") {
		    $kernelvers = 10;
		} elsif (-x "$TFTP_DIR/frisbee/boot/kernel9") {
		    $kernelvers = 9;
		}
146
	    }
147 148 149 150 151 152 153 154 155
	};
	#
	# Older tarballs didn't have FBSD-specific versions of newnode MFS.
	#
	if (! -e "$TFTP_DIR/freebsd.newnode") {
	    Phase "newnode", "Using freebsd${fv} version of newnode MFS", sub {
		DoneIfExists("$TFTP_DIR/freebsd.newnode");
		ExecQuietFatal("cd $TFTP_DIR; ".
			       "$MV freebsd${fv}.newnode freebsd.newnode");
156 157 158 159 160 161 162
		# find the best MFS kernel to use
		if (!$kernelvers) {
		    if (-x "$TFTP_DIR/freebsd.newnode/boot/kernel10") {
			$kernelvers = 10;
		    } elsif (-x "$TFTP_DIR/freebsd.newnode/boot/kernel9") {
			$kernelvers = 9;
		    }
163
		}
164 165 166
	    };
	}

167 168 169 170 171 172
	#
	# Before we localize, need to set the MFS password sitevar,
	# since localize will break otherwise.
	#
	Phase "password", "Setting up MFS password", sub {
	    my $passhash;
173 174 175 176

	    # Skip in update mode.
	    PhaseSkip("update mode")
		if ($isupdate);
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
	    
	    my ($status, @output) =
		ExecQuiet("$PREFIX/sbin/setsitevar -c $IMAGEPASSWORDSITEVAR");
	    PhaseFail("setsitevar failed")
		if ($status);
	    if (@output) {
		chomp($output[0]);
		PhaseSkip("already set")
		    if ($output[0] ne "");
	    }

	    #
	    # Use the same password for everything.
	    #
	    if (defined($password)) {
		$passhash = PassWordHash($password);
	    }
	    else {
		#
		# Use current root password, since we know people will
		# choose reasonable root passwords.
		#
		($status,@output) =
		    ExecQuiet("egrep '^root:' /etc/master.passwd");
		PhaseFail("egrep failed")
		    if ($status);
		if (@output && $output[0] ne '' &&
		    $output[0] =~ /^root:([^:]*)/) {
		    $passhash = $1;
		}
	    }
	    PhaseFail("Could not determine image password")
		if (!defined($passhash));

	    ExecQuietFatal("$PREFIX/sbin/setsitevar ".
			   "   $IMAGEPASSWORDSITEVAR '$passhash'");
	};

215
	#
216
	# Localize the MFSs
217
	#
218 219 220
	# This opt says to include igb cruft. Needed on G8s.
	#
	my $opt = ($PROTOGENI_GENIRACK ? "-i" : "");
221
	if ($kernelvers) {
222
	    $opt .= " -F $kernelvers";
223
	}
224
	
225 226 227 228
	Phase "localize", "Localizing the MFSes", sub {
	    foreach my $mfs ("frisbee", "freebsd", "freebsd.newnode") {
		Phase "$mfs", "Localizing $mfs", sub {
		    DoneIfExists("$TFTP_DIR/$mfs/boot/mfsroot.gz");
229
		    ExecQuietFatal("$LOCALIZE_MFS $opt $TFTP_DIR/$mfs");
230 231
		};
	    }
232 233 234
	};

	#
Leigh B Stoller's avatar
Leigh B Stoller committed
235 236 237
	# Load the descriptors into the DB. Inside an elabinelab these are
	# already loaded, but the script will just skip over them without
	# raising an error.
238
	#
239 240 241 242 243 244 245
	if (!$isupdate) {
	    Phase "descriptors", "Loading the Image and OS IDS", sub {
		ExecQuietFatal("cd $TOP_OBJDIR/install; ".
			       "   $SUDO -u $PROTOUSER $WAP ".
			       "   perl load-descriptors $MFSDESCRIPTORS");
	    };
	}
246 247 248 249 250 251 252 253
	PhaseSucceed("done");
    };
    return 0;
}

# Local Variables:
# mode:perl
# End: