Commit 6a4d682c authored by Mike Hibler's avatar Mike Hibler
Browse files

(For now) fedora-specific rc.linux file to initialize the swap partition

ala freebsd7/rc.freebsd.  We need this currently for the new remote nodes
where we have to load partition images and not a whole disk image (because
we download a copy of the image to the hard drive and we cannot have that
mounted and reload the entire disk).  Anyway, with a single partition image
the swap partition will not be "loaded", aka initialized, and we are left
without swap.  Now the rc.linux script takes care of that on first boot.
parent 1f8b900a
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
# Copyright (c) 2000-2005, 2007 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -82,7 +82,7 @@ sysetc-onceonly-install:
@$(MYINSTALL) $(SRCDIR)/syslog.conf $(SYSETCDIR)/syslog.conf
script-install: dir-install $(SCRIPTS)
@echo "fedora-specific script-install done"
$(INSTALL) -m 755 $(SRCDIR)/rc.linux $(BINDIR)/rc
sfs-install:
@echo "no fedora-specific sfs files"
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2007 University of Utah and the Flux Group.
# All rights reserved.
#
use English;
use Getopt::Std;
my $FSTAB = "/etc/fstab";
my $script = $0;
sub swapenable();
sub addswap($$);
# Turn off line buffering on output
$| = 1;
#
# Figure out if there is a swap device, add it to fstab and intialize if
# necessary.
#
swapenable();
exit(0);
sub swapenable()
{
if (!open(FD, "<$FSTAB")) {
print STDERR "*** WARNING: could not open $FSTAB for reading, ".
"no swap enabled\n";
return;
}
while (<FD>) {
my ($fs,$mpt,$type,$opt) = split;
if ($type eq "swap") {
close(FD);
return;
}
}
close(FD);
#
# No swap device.
# Identify the root disk and see if we can locate a Linux swap partition
# on it.
#
my $rdisk;
my $rootfs = `df / | grep /dev/`;
if ($rootfs =~ /^(\/dev\/[a-z]+)\d+/) {
$rdisk = $1;
} else {
print STDERR "*** WARNING: could not identify root disk, ".
"no swap enabled\n";
return;
}
@lines = `fdisk -l $rdisk 2>/dev/null | grep 'Linux swap'`;
if ($? != 0) {
print STDERR "*** WARNING: could not read MBR of $rdisk, ".
"no swap enabled\n";
return;
}
chomp(@lines);
foreach $line (@lines) {
if ($line =~ /^\/dev\/(\S+)\s+\d+\s+\d+\s+(\d+)\+?/) {
my $dev = $1;
my $size = $2;
addswap($dev, $size);
return;
}
}
print STDERR "*** WARNING: could not locate a suitable swap device, ".
"no swap enabled\n";
}
sub addswap($$)
{
my ($dev,$size) = @_;
print "Using /dev/$dev ($size sectors) for swap\n";
if (system("mkswap /dev/$dev")) {
print STDERR "*** WARNING: could not initialize swap on /dev/$dev, ".
"no swap enabled\n";
exit(0);
}
if (system("swapon /dev/$dev")) {
print STDERR "*** WARNING: could not enable swap on /dev/$dev, ".
"no swap enabled\n";
exit(0);
}
if (!open(FD, ">>$FSTAB")) {
print STDERR "*** WARNING: could not add /dev/$dev to $FSTAB, ".
"swap enabled this boot only\n";
}
print FD "# the following added by $script\n";
print FD "/dev/$dev\t\tswap\tswap\tdefaults\t0\t0\n";
close(FD);
print "Swap enabled\n";
}
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