Commit 93a3a065 authored by Ryan Jackson's avatar Ryan Jackson

Lots of linux "MFS" changes

* linuxmfs: (27 commits)
  Use LookupByIP in the local area case
  Don't check server cert in MFS environment
  Add wipe-all-disks-on-reloading code
  Generate random UUID for linux root fs
  Cleanup of mdev.conf; sane device permissions
  New root password
  add kmem group
  Make sure ETHERTYPE_LOOPBACK is defined
  Add teachswitch to the build
  Add support for old GNU tar format
  New root passwd
  Make 'permissions' target work again
  Fixes to device permissions
  Add osconfig to the build
  Add the file command to build
  Make osconfig work on linux MFS
  Detach any loopback devices left over after mounting initrds.
  Fix for handling ide devices as swap partitions
  Make sure F10's dhclient state gets wiped
  Make sure to reread partition table after writing image
  ...
parent 0467c247
......@@ -9,7 +9,7 @@ STAGING_DIR = $(PWD)/buildroot/build_i386/staging_dir
INITRAMFS = $(PWD)/initramfs.gz
BOOT_PATH = $(PWD)/boot
MODULES := busybox zlib linux dropbear testbed hdparm target_template sudo e2fsprogs openssl wget perl portmap
MODULES := busybox zlib linux dropbear testbed hdparm target_template sudo e2fsprogs openssl wget perl portmap file
INSTALL_MODULES := $(addsuffix -install,$(MODULES))
EXTRACT_MODULES := $(addsuffix -extract,$(MODULES))
PATCH_MODULES := $(addsuffix -patch,$(MODULES))
......@@ -62,7 +62,7 @@ devices: $(FAKEROOT_ENVIRONMENT)
$(SCRIPTS_PATH)/makedevs.sh \
$(SCRIPTS_PATH)/devices $(TARGET_PATH)
permissions: $(FAKEROOT_ENVIRONMENT) devices target-install
permissions: $(FAKEROOT_ENVIRONMENT) devices install
$(STAGING_DIR)/usr/bin/fakeroot -s $(FAKEROOT_ENVIRONMENT) \
-i $(FAKEROOT_ENVIRONMENT) \
$(SCRIPTS_PATH)/fixperms.sh $(TARGET_PATH)
......
......@@ -30,7 +30,7 @@ fd0u720 b 0x2 0x10 0 0 640
fd0u800 b 0x2 0x78 0 0 640
fd0u820 b 0x2 0x34 0 0 640
fd0u830 b 0x2 0x44 0 0 640
full c 0x1 0x7 0 0 600
full c 0x1 0x7 0 0 666
fwmonitor c 0x24 0x3 0 0 600
hda b 0x3 0x0 0 0 640
hda1 b 0x3 0x1 0 0 640
......@@ -65,14 +65,14 @@ mcdx b 0x14 0x0 0 0 640
mem c 0x1 0x1 0 0 640
mixer c 0xe 0x0 0 0 640
mixer1 c 0xe 0x10 0 0 640
null c 0x1 0x3 0 0 644
null c 0x1 0x3 0 0 666
par0 c 0x6 0x0 0 0 640
par1 c 0x6 0x1 0 0 640
par2 c 0x6 0x2 0 0 640
port c 0x1 0x4 0 0 640
ptmx c 0x5 0x2 0 0 644
ptmx c 0x5 0x2 0 0 666
pts d 0x0 0x0 0 0 755
random c 0x1 0x8 0 0 444
random c 0x1 0x8 0 0 666
route c 0x24 0x0 0 0 600
rtc c 0xa 0x87 0 0 640
sda b 0x8 0x0 0 0 640
......@@ -89,7 +89,7 @@ stderr l 0x0 0x0 0 0 777 fd/2
stdin l 0x0 0x0 0 0 777 fd/0
stdout l 0x0 0x0 0 0 777 fd/1
tprobe c 0x46 0x0 0 0 644
tty c 0x5 0x0 0 0 644
tty c 0x5 0x0 0 0 666
tty0 c 0x4 0x0 0 0 600
tty1 c 0x4 0x1 0 0 600
tty2 c 0x4 0x2 0 0 600
......@@ -118,6 +118,6 @@ ttyS6 c 0x4 0x46 0 0 644
ttyS7 c 0x4 0x47 0 0 644
ttyS8 c 0x4 0x48 0 0 644
ttyS9 c 0x4 0x49 0 0 644
urandom c 0x1 0x9 0 0 444
zero c 0x1 0x5 0 0 644
urandom c 0x1 0x9 0 0 666
zero c 0x1 0x5 0 0 666
i2c-0 c 0x59 0x0 0 0 664
......@@ -70,7 +70,7 @@ CONFIG_INSTALL_APPLET_SYMLINKS=y
# CONFIG_INSTALL_SH_APPLET_SYMLINK is not set
# CONFIG_INSTALL_SH_APPLET_HARDLINK is not set
# CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER is not set
CONFIG_PREFIX="/home/rdjackso/testbed/mfs/linux_mfs/target/"
CONFIG_PREFIX="/home/rdjackso/gits/testbed/mfs/linux_mfs/target/"
#
# Busybox Library Tuning
......@@ -121,7 +121,7 @@ CONFIG_TAR=y
CONFIG_FEATURE_TAR_CREATE=y
# CONFIG_FEATURE_TAR_AUTODETECT is not set
CONFIG_FEATURE_TAR_FROM=y
# CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY is not set
CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY=y
# CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY is not set
CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
CONFIG_FEATURE_TAR_LONG_OPTIONS=y
......
......@@ -23,7 +23,7 @@ clean:
LIBS := $(addprefix $(TARGET_PATH)/lib/, libext2fs.so libe2p.so libcom_err.so libblkid.so libuuid.so)
install: $(TARGET_PATH)/sbin/mke2fs $(TARGET_PATH)/sbin/tune2fs $(TARGET_PATH)/sbin/e2fsck $(LIBS)
install: $(TARGET_PATH)/sbin/mke2fs $(TARGET_PATH)/sbin/tune2fs $(TARGET_PATH)/sbin/e2fsck $(TARGET_PATH)/usr/bin/uuidgen $(LIBS)
$(E2FSPROGS_PATH)/.extract-stamp:
mkdir -p $(TARGET_BUILD_PATH)
......@@ -86,6 +86,11 @@ $(E2FSPROGS_PATH)/misc/tune2fs: $(E2FSPROGS_PATH)/.config-stamp
$(TARGET_CONFIGURE_OPTS) LD=i386-linux-uclibc-gcc
touch $@
$(E2FSPROGS_PATH)/misc/uuidgen: $(E2FSPROGS_PATH)/.config-stamp
LDFLAGS="-rpath ../lib" PATH=$(STAGING_DIR)/usr/bin:$(PATH) $(MAKE) -C $(E2FSPROGS_PATH) \
$(TARGET_CONFIGURE_OPTS) LD=i386-linux-uclibc-gcc
touch $@
$(E2FSPROGS_PATH)/lib/%.so: $(E2FSPROGS_PATH)/.config-stamp
LDFLAGS="-rpath ../lib" PATH=$(STAGING_DIR)/usr/bin:$(PATH) $(MAKE) -C $(E2FSPROGS_PATH) \
$(TARGET_CONFIGURE_OPTS) LD=i386-linux-uclibc-gcc
......@@ -110,8 +115,8 @@ $(TARGET_PATH)/sbin/e2fsck: $(E2FSPROGS_PATH)/e2fsck/e2fsck
install -m 755 $< \
$(TARGET_PATH)/sbin/e2fsck
$(STRIPCMD) --strip-unneeded $(TARGET_PATH)/sbin/e2fsck
ln -s $@ $(dir $@)/fsck.ext2
ln -s $@ $(dir $@)/fsck.ext3
ln -sf $@ $(dir $@)/fsck.ext2
ln -sf $@ $(dir $@)/fsck.ext3
touch -c $@
$(TARGET_PATH)/sbin/tune2fs: $(E2FSPROGS_PATH)/misc/tune2fs
......@@ -120,3 +125,10 @@ $(TARGET_PATH)/sbin/tune2fs: $(E2FSPROGS_PATH)/misc/tune2fs
$(TARGET_PATH)/sbin/tune2fs
$(STRIPCMD) --strip-unneeded $(TARGET_PATH)/sbin/tune2fs
touch -c $@
$(TARGET_PATH)/usr/bin/uuidgen: $(E2FSPROGS_PATH)/misc/uuidgen
install -d -m 755 $(TARGET_PATH)/usr/bin
install -m 755 $(E2FSPROGS_PATH)/misc/uuidgen \
$(TARGET_PATH)/usr/bin/uuidgen
$(STRIPCMD) --strip-unneeded $(TARGET_PATH)/usr/bin/uuidgen
touch -c $@
include ../../variables.mk
FILE_VERSION = 5.03
LIBMAGIC_VERSION = 1.0.0
FILE_PATH = $(TARGET_BUILD_PATH)/file-$(FILE_VERSION)
.PHONY: extract patch config \
file install clean all
all: file
extract: $(FILE_PATH)/.extract-stamp
patch: $(FILE_PATH)/.patch-stamp
config: $(FILE_PATH)/.config-stamp
file: $(FILE_PATH)/src/.libs/file
install: $(TARGET_PATH)/usr/bin/file $(TARGET_PATH)/usr/share/misc/magic
clean:
PATH=$(STAGING_DIR)/usr/bin:$(PATH) $(MAKE) -C $(FILE_PATH) clean
rm -f $(FILE_PATH)/.build-stamp $(FILE_PATH)/.config-stamp
$(FILE_PATH)/.extract-stamp:
mkdir -p $(TARGET_BUILD_PATH)
cd $(TARGET_BUILD_PATH); tar xzf $(SOURCE_PATH)/file/file-$(FILE_VERSION).tar.gz
touch $@
$(FILE_PATH)/.patch-stamp: $(FILE_PATH)/.extract-stamp
$(SCRIPTS_PATH)/patch-kernel.sh $(FILE_PATH) $(SOURCE_PATH)/file/ '*.patch'
touch $@
$(FILE_PATH)/.config-stamp: $(FILE_PATH)/.patch-stamp
rm -f $(FILE_PATH)/config.cache
(cd $(FILE_PATH); \
PATH=$(STAGING_DIR)/usr/bin:$(PATH) \
$(HOST_CONFIGURE_OPTS) \
./configure \
--target=i386-linux-uclibc \
--host=i386-linux-uclibc \
--build=x86_64-linux-gnu \
--prefix=/usr \
--exec-prefix=/usr \
--bindir=/usr/bin \
--sbindir=/usr/sbin \
--libdir=/lib \
--libexecdir=/usr/lib \
--sysconfdir=/etc \
--datadir=/usr/share \
--localstatedir=/var \
--mandir=/usr/man \
--infodir=/usr/info \
)
touch $@
#--enable-elf-shlibs --enable-dynamic-e2fsck --disable-swapfs \
#--enable-elf-shlibs \
$(FILE_PATH)/src/.libs/file: $(FILE_PATH)/.config-stamp
PATH=$(STAGING_DIR)/usr/bin:$(PATH) \
CC=$(TARGET_CC) \
$(MAKE) -C $(FILE_PATH) \
$(TARGET_CONFIGURE_OPTS) LD=i386-linux-uclibc-gcc
touch $@
$(TARGET_PATH)/usr/share/misc/magic:
install -d -m 755 $(TARGET_PATH)/usr
install -d -m 755 $(TARGET_PATH)/usr/share
install -d -m 755 $(TARGET_PATH)/usr/share/misc
cat $(FILE_PATH)/magic/Header $(FILE_PATH)/magic/Localstuff \
$(FILE_PATH)/magic/Magdir/* > $@
touch -c $@
$(TARGET_PATH)/usr/bin/file: $(FILE_PATH)/src/.libs/file
install -d -m 755 $(TARGET_PATH)/usr
install -d -m 755 $(TARGET_PATH)/usr/bin
install -d -m 755 $(TARGET_PATH)/usr/lib
install -m 755 $< $@
install -m 644 $(FILE_PATH)/src/.libs/libmagic.so.$(LIBMAGIC_VERSION) $(TARGET_PATH)/usr/lib
$(STRIPCMD) --strip-unneeded $@
$(STRIPCMD) --strip-unneeded $(TARGET_PATH)/usr/lib/libmagic.so.$(LIBMAGIC_VERSION)
$(STAGING_DIR)/usr/bin/ldconfig -r $(TARGET_PATH)
touch -c $@
......@@ -6,6 +6,7 @@ adm:x:4:
tty:x:5:
disk:x:6:
wheel:x:10:root
kmem:x:15:
utmp:x:43:
staff:x:50:
haldaemon:x:68:
......
.* 0:0 640 @ /sbin/hotplug
# root:disk
[hs]d[a-z][a-z]*[0-9]* 0:6 660
ram[0-9][0-9]* 0:6 660
console 0:0 600
full 0:0 666
kmsg 0:0 660
null 0:0 666
ptmx 0:0 666
random 0:0 666
rtc[0-9][0-9] 0:0 660
tty 0:0 666
urandom 0:0 666
zero 0:0 666
tty[0-9][0-9]* 0:0 660
# root:kmem
kmem 0:15 640
mem 0:15 640
# Default entry
.* 0:0 600 @/sbin/hotplug
root:$1$EZlbduRT$jgrNUE36P93icY33sSxEX/:10933:0:99999:7:::
root:$1$8hBhgqAf$mSe/dEYfBMm2iMIskyNrp1:10933:0:99999:7:::
bin:*:10933:0:99999:7:::
daemon:*:10933:0:99999:7:::
adm:*:10933:0:99999:7:::
......
......@@ -2,7 +2,7 @@ include ../../variables.mk
BUILDROOT := $(PWD)/$(BUILDROOT)
PROGS := imageunzip imagezip frisbee growdisk tmcc.bin binoffset groklilo
PROGS := imageunzip imagezip frisbee growdisk tmcc.bin binoffset groklilo teachswitch
BUILD_TARGETS := $(PROGS)
INSTALL_TARGETS := $(addsuffix -install,$(PROGS))
......@@ -10,7 +10,7 @@ INSTALL_TARGETS := $(addsuffix -install,$(PROGS))
.PHONY: $(BUILD_TARGETS) all
.PHONY: $(INSTALL_TARGETS) script-install install
TESTBED_PATH = /home/rdjackso/testbed
TESTBED_PATH = /home/rdjackso/gits/testbed
TESTBED_BUILD_PATH = $(TARGET_BUILD_PATH)/testbed
TMCD_PATH = $(TESTBED_PATH)/tmcd
GROKLILO_PATH = $(TESTBED_PATH)/cdrom/groklilo
......@@ -19,12 +19,13 @@ TESTBEDOBJ_PATH = /home/rdjackso/testbed-obj
FRISBEE_PATH = $(TESTBED_PATH)/os/frisbee.redux
BINOFFSET_PATH = $(TESTBED_PATH)/tools/binoffset
IMAGEZIP_PATH = $(TESTBED_PATH)/os/imagezip
TEACHSWITCH_PATH = $(TESTBED_PATH)/tools/teachswitch
TMCD_OBJ_PATH = $(TESTBEDOBJ_PATH)/tmcd
TMCC_OBJ_PATH = $(TARGET_BUILD_PATH)/tmcc
CFLAGS = -Os
INSTALLED_BINS := $(addprefix $(TARGET_PATH)/usr/, \
$(addprefix bin/, binoffset imagezip imageunzip tmcc.bin frisbee) \
$(addprefix bin/, binoffset imagezip imageunzip tmcc.bin frisbee teachswitch) \
$(addprefix sbin/, groklilo growdisk))
all: $(BUILD_TARGETS)
......@@ -62,11 +63,11 @@ script-install:
install -m 755 $(TMCD_PATH)/linux/freebsd_to_linux_disk $(TARGET_PATH)/etc/testbed
install -m 755 $(TMCD_PATH)/linux/check_disklabel $(TARGET_PATH)/etc/testbed
install -m 755 $(TMCD_PATH)/linux/remap_ide_disks $(TARGET_PATH)/etc/testbed
install -m 755 $(TMCD_PATH)/linux/get_edd_map $(TARGET_PATH)/etc/testbed
install -m 755 $(TMCD_PATH)/linux/extract_kernel_info $(TARGET_PATH)/etc/testbed
install -m 755 $(TMCD_PATH)/linux/extract_image_info $(TARGET_PATH)/etc/testbed
install -m 755 $(TMCD_PATH)/linux/extract_initrd_info $(TARGET_PATH)/etc/testbed
install -m 755 $(TMCD_PATH)/linux/linux_slicefix $(TARGET_PATH)/etc/testbed
install -m 755 $(TMCD_PATH)/linux/get_edd_map.pl $(TARGET_PATH)/etc/testbed
#install -m 755 $(TMCD_PATH)/linux/extract_kernel_info $(TARGET_PATH)/etc/testbed
#install -m 755 $(TMCD_PATH)/linux/extract_image_info $(TARGET_PATH)/etc/testbed
#install -m 755 $(TMCD_PATH)/linux/extract_initrd_info $(TARGET_PATH)/etc/testbed
install -m 755 $(TMCD_PATH)/linux/linux_slicefix.pl $(TARGET_PATH)/etc/testbed
install -m 755 $(TESTBED_PATH)/install/newclient $(TARGET_PATH)/etc/testbed
install -m 755 $(TMCD_PATH)/common/paths.sh $(TARGET_PATH)/etc/emulab
install -m 755 $(TMCD_PATH)/common/paths.pm $(TARGET_PATH)/etc/emulab
......@@ -77,6 +78,7 @@ script-install:
install -m 755 $(TMCD_PATH)/common/watchdog $(TARGET_PATH)/etc/testbed
install -m 755 $(TMCD_PATH)/common/update $(TARGET_PATH)/etc/testbed
install -m 755 $(TMCD_PATH)/common/tmcc.pl $(TARGET_PATH)/usr/bin/tmcc
install -m 755 $(TMCD_PATH)/common/osconfig $(TARGET_PATH)/etc/testbed
ln -sf /usr/bin/tmcc $(TARGET_PATH)/etc/testbed/tmcc
install -m 755 $(TMCD_PATH)/common/config/librc.pm $(TARGET_PATH)/etc/testbed
install -m 755 $(TMCD_PATH)/common/config/rc.config $(TARGET_PATH)/etc/testbed/rc
......@@ -109,6 +111,8 @@ groklilo-install: $(TARGET_PATH)/usr/sbin/groklilo
tmcc.bin-install: $(TARGET_PATH)/usr/bin/tmcc.bin
teachswitch-install: $(TARGET_PATH)/usr/bin/teachswitch
clean:
rm -rf $(TESTBED_BUILD_PATH)
......@@ -140,6 +144,15 @@ $(TESTBED_BUILD_PATH)/growdisk:
$(GROWDISK_PATH)/growdisk.c
$(STRIPCMD) --strip-unneeded $@
$(TESTBED_BUILD_PATH)/teachswitch:
mkdir -p $(TESTBED_BUILD_PATH)
PATH=$(STAGING_DIR)/usr/bin:$(PATH) \
$(CROSS_COMPILER_PREFIX)gcc \
-o $@ \
-Os \
$(TEACHSWITCH_PATH)/teachswitch.c
$(STRIPCMD) --strip-unneeded $@
# ARGH! tmcc wants to link against libtb just for the errorc function in libtb/log.c.
# libtb in turn wants libmysql. There's no point building all of libtb and its
# required libs under uclibc, so I'm going to skip the testbed makefiles and
......
root:$1$EZlbduRT$jgrNUE36P93icY33sSxEX/:10933:0:99999:7:::
root:$1$d4yEnmIw$sgWS70/2fWIgUjk5dZD0t0:10933:0:99999:7:::
bin:*:10933:0:99999:7:::
daemon:*:10933:0:99999:7:::
adm:*:10933:0:99999:7:::
......
......@@ -7,7 +7,7 @@
use strict;
use English;
use Getopt::Std;
use Data::Dumper;
#use Data::Dumper;
#
# This script is intended to be invoked only from the MFS at this point. The
......@@ -67,7 +67,10 @@ if ($EUID != 0) {
" Must be root to run this script!\n");
}
my $WGET = "/usr/local/bin/wget";
my $WGET = "/usr/bin/wget";
if (! -x $WGET) {
$WGET = "/usr/local/bin/wget";
}
my $debug = 0;
my $optlist = "m:M:f:s:D:a:ndc";
......@@ -305,7 +308,11 @@ sub doUpdate($$$) {
}
my $doit = 0;
my $cmdstr = "$WGET -o /tmp/update.wget.log -O /tmp/update.file '$uurl'";
my $cmdstr = $WGET;
# For MFS environments we don't currently install any CA certificates, so
# force wget to skip the cert check.
$cmdstr .= " --no-check-certificate" if (-f "$ETCDIR/ismfs");
$cmdstr .= " -o /tmp/update.wget.log -O /tmp/update.file '$uurl'";
print STDERR "update URL: '$cmdstr'\n";
my $retval = system($cmdstr);
if ($retval) {
......@@ -336,7 +343,7 @@ sub doUpdate($$$) {
return 0;
}
if ($mimetype eq "application/x-gzip") {
if ($mimetype =~ "^application/x-gzip") {
$retval = system("tar -xzf /tmp/update.file -C /var/emulab/update.tmp");
if ($retval) {
print "Error: tar failed!\n";
......
......@@ -33,12 +33,19 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# No configure vars.
#
my $sudo = "/usr/local/bin/sudo";
my $sudo;
my $zipper = "/usr/local/bin/imagezip";
my $slice = "";
my $device;
my $filename;
for my $path (qw#/usr/local/bin /usr/bin#) {
if (-e "$path/sudo") {
$sudo = "$path/sudo";
last;
}
}
#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
......
#! /usr/bin/perl
use Data::Dumper;
use constant EDD_PREFIX => '/sys/firmware/edd';
use strict;
......
......@@ -9,9 +9,15 @@ my $RM = '/bin/rm';
my $CP = '/bin/cp';
my $CPIO = 'cpio';
my $GZIP = 'gzip';
my $MKSWAP = '/sbin/mkswap';
my $UUIDGEN = 'uuidgen';
my $LOSETUP = 'losetup';
my $TUNE2FS = 'tune2fs';
use constant GZHDR1 => 0x1f8b0800;
use constant GZHDR2 => 0x1f8b0808;
use constant LARGEST_PAGE_SIZE => 0x4000;
use constant UUID_OFFSET => 1036;
# Load up the paths. Done like this in case init code is needed.
BEGIN
......@@ -40,7 +46,7 @@ sub get_uuid
close CMD;
}
elsif (-x $BLKID) {
open CMD, $BLKID || die
open CMD, "$BLKID|" || die
"Couldn't run blkid: $!\n";
while (<CMD>) {
......@@ -74,7 +80,7 @@ sub get_label
close CMD;
}
elsif (-x $BLKID) {
open CMD, $BLKID || die
open CMD, "$BLKID|" || die
"Couldn't run blkid: $!\n";
while (<CMD>) {
......@@ -93,6 +99,13 @@ sub get_label
return $label;
}
sub set_random_rootfs_uuid
{
my ($root) = @_;
system("$TUNE2FS -U random $root");
}
sub kernel_version_compare
{
my ($v1, $v2) = @_;
......@@ -132,6 +145,92 @@ sub find_swap_partitions
return @swap_devices;
}
sub set_swap_uuid
{
my ($device, $uuid) = @_;
my $swap_header;
if (!open DEVICE, "+<$device") {
print STDERR "Couldn't open $device: $!\n";
return 1;
}
my $id;
for (my $i = 0x1000; $i <= LARGEST_PAGE_SIZE; $i <<= 1) {
seek DEVICE, 0, 0;
read DEVICE, $swap_header, $i;
$id = unpack('Z10', substr($swap_header, $i - 10));
last if ($id eq 'SWAPSPACE2');
}
if ($id ne 'SWAPSPACE2') {
print STDERR "Device $device does not contain a new-style swap header\n";
close DEVICE;
return 1;
}
my $new_uuid = pack('H8H4H4H4H12', split(/-/, $uuid));
substr $swap_header, UUID_OFFSET, 16, $new_uuid;
seek DEVICE, 0, 0;
print DEVICE $swap_header;
close DEVICE;
}
sub fix_swap_partitions
{
my ($imageroot, $root, $old_root) = @_;
my @swapdevs;
return undef unless (-x $MKSWAP);
my ($root_disk) = ($root =~ m#^(/dev/[a-z]+)#);
my ($old_root_disk) = ($old_root =~ m#^(/dev/[a-z]+)#);
my @swap_partitions = find_swap_partitions($root_disk);
my ($l, $u) = binary_supports_blkid("$imageroot/sbin/swapon");
for my $part (@swap_partitions) {
my $swapdev = $part;
next if system("$MKSWAP $part");
my $uuid = get_uuid($part);
if ($u) {
if ($uuid) {
$swapdev = "UUID=$uuid";
}
else {
# BusyBox's mkswap doesn't support UUIDs, so
# we'll need to generate it and write it out.
$uuid = `$UUIDGEN`;
chomp $uuid;
set_swap_uuid($swapdev, $uuid);
$swapdev="UUID=$uuid";
}
}
elsif ($old_root) {
$swapdev =~ s#^$root_disk#$old_root_disk#;
}
push @swapdevs, $swapdev;
}
return undef unless (@swapdevs);
my @buffer;
if (!open FSTAB, "+<$imageroot/etc/fstab") {
print STDERR "Failed to open fstab: $!\n";
return undef;
}
@buffer = grep {!/^[^#].*\bswap\b.*$/} <FSTAB>;
for (@swapdevs) {
push @buffer, "$_\tnone\tswap\tsw\t0 0\n";
}
seek FSTAB, 0, 0;
print FSTAB @buffer;
close FSTAB;
}
sub file_replace_root_device
{
my ($imageroot, $file, $old_root, $new_root) = @_;
......@@ -147,7 +246,7 @@ sub file_replace_root_device
seek FILE, 0, 0;
print FILE $_ for (@buffer);
print FILE @buffer;
close FILE;
......@@ -185,15 +284,18 @@ sub rewrite_lilo_config
sub set_runlilo_flag
{
my ($imageroot, $default_entry, $new_root) = @_;
my $cmdline;
open FILE, ">$imageroot/var/emulab/boot/runlilo" ||
die "Couldn't write to runlilo file: $!\n";
$cmdline = "$default_entry root=$new_root";
print FILE "$default_entry root=$new_root\n";
print FILE "$cmdline\n";
close FILE;
return 1;
return $cmdline;
}
sub find_default_grub_entry
......@@ -255,7 +357,7 @@ sub set_grub_root_device
if (not defined $grub_disk) {
$grub_disk = $root;
$grub_disk =~ s/^[hs]d(.).*$/$1/;
$grub_disk =~ s/^\/dev\/[hs]d(.).*$/$1/;
$grub_disk =~ y/[a-h]/[0-7]/;
print "Found GRUB root device by guessing\n";
}
......@@ -271,7 +373,7 @@ sub set_grub_root_device
push @buffer, $_;
}
seek FILE, 0, 0;
print FILE $_ for (@buffer);
print FILE @buffer;
close FILE;
}
......@@ -547,6 +649,19 @@ sub check_initrd
`$UMOUNT "$initrd_dir" > /dev/null 2> /dev/null`;
`$RM -rf "$initrd_dir" "$decompressed_initrd"`;
my @loopdevs;
open LOSETUP, "$LOSETUP|";
while (<LOSETUP>) {
chomp;
split /:/;
push @loopdevs, $_[0];
}
for my $dev (@loopdevs) {
`$LOSETUP -d $dev`;
}
return ($handles_label, $handles_uuid);
}
......@@ -637,6 +752,7 @@ sub main
my $lilo_default;
my $lilo_commandline = 0;
set_random_rootfs_uuid($root);
my $fstype = mount_image($root, $imageroot);
my $uuid = get_uuid($root);
my $label = get_label($root);
......@@ -648,7 +764,7 @@ sub main
}
elsif ($bootloader eq 'grub') {
for (qw#/boot/grub/grub.conf /etc/grub.conf /boot/grub/menu.lst#) {
if (-f $_) {
if (-f "$imageroot/$_") {
$grub_config = $_;
last;
}
......@@ -733,6 +849,9 @@ sub main
set_grub_root_device($imageroot, $grub_config, $root);
}
fix_swap_partitions($imageroot, $root,
$kernel_has_ide ? $old_root : undef );
update_random_seed($imageroot);
hardwire_boss_node($imageroot);
......
......@@ -14,7 +14,7 @@ require 'ctime.pl';
#
my $DUMPDATES = "/etc/dumpdates";
my @DBFILES = ();
my @SYSVARDIRS = ("lib/dhcp", "lib/dhcp3", "spool/clientmqueue",
my @SYSVARDIRS = ("lib/dhcp", "lib/dhclient", "lib/dhcp3", "spool/clientmqueue",
"log/audit", "log/account", "log/mysql", "log/ntpstats");
my @VARDIRS = ("logs", "db", "jails", "boot", "lock");
my @SOCKETS = ("/dev/log", "/var/run/acpid.socket");
......
......@@ -100,13 +100,13 @@ install_mbr()
return 0
fi
if ! [ -r $MBR_PATH/mbr{$new_mbr_ver}.dd ]; then
if ! [ -r $MBR_PATH/mbr${new_mbr_ver}.dd ]; then
echo "WARNING: cannot find MBR version $new_mbr_ver, not installed"
return 255
fi
echo "Installing MBR version $new_mbr_ver ..."
dd if=$MBR_PATH/mbr{$new_mbr_ver}.dd of=$disk bs=512 count=1
dd if=$MBR_PATH/mbr${new_mbr_ver}.dd of=$disk bs=512 count=1
# Linux won't re-read the partition table unless told to do so.
# hdparm could be used for this, but it may not be installed.
......@@ -198,6 +198,16 @@ get_buffer_sizes()
echo $memargs
}
find_disks() {
local disks
for d in /sys/block/[sh]d*; do
disks="$disks $d"
done
echo $disks
}
# FIXME shouldn't hard code "/images"
write_image()
{
......@@ -260,6 +270,19 @@ write_image()
$BINDIR/tmcc state RELOADING
case $STATUS in
*ALLOCATED=emulab-ops/reloading*)
disks=`find_disks`
for d in $disks; do
#[ $d = $DISK ] && continue
mount | grep "^/dev/$d" > /dev/null && continue
zap_superblocks /dev/$d
echo "Invalidating MBR on /dev/$d"
dd if=/dev/zero of=/dev/$d bs=512 count=1
done
;;
esac
if [ $protocol = frisbee ]; then
$BINDIR/frisbee -m $address -p $port -s $slice $FRISBEE_OPTS $disk
rc=$?
......
......@@ -138,6 +138,8 @@ dofreebsd() {
fstype=ufs
fsopts=ro
elif [ $OS = Linux ]; then
echo "Reloading partition table for $disk..."
echo w | /sbin/fdisk /dev/$disk > /dev/null 2>&1
rootdev=/dev/`$BINDIR/check_disklabel $disk $part`
[ "$rootdev" = /dev/ ] && exit 1
fstype=ufs
......
......@@ -27,6 +27,11 @@
#include <linux/if_arp.h>
#endif
/* Not defined under uClibc */
#ifndef ETHERTYPE_LOOPBACK
#define ETHERTYPE_LOOPBACK 0x9000
#endif
const int MAX_INTERFACES = 8;
const int SLEEP_TIME = 30;
#if defined(__FreeBSD__)
......
......@@ -154,7 +154,7 @@ else {
if (!IsControlNetIP($ip)) {
SPITERROR("notlocal");
}
$node = Node::Lookup($ip);
$node = Node::LookupByIP($ip);
if ($node) {
$node_id = $node->node_id();
}
......
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