switch-to-configuration: Handle swap devices
This commit is contained in:
parent
be5486813b
commit
a4a90685ea
@ -70,7 +70,7 @@ sub parseFstab {
|
|||||||
$line =~ s/#.*//;
|
$line =~ s/#.*//;
|
||||||
next if $line =~ /^\s*$/;
|
next if $line =~ /^\s*$/;
|
||||||
my @xs = split / /, $line;
|
my @xs = split / /, $line;
|
||||||
$res{$xs[1]} = { device => $xs[0], fsType => $xs[2], options => $xs[3] };
|
$res{$xs[1]} = { device => $xs[0], fsType => $xs[2], options => $xs[3] // "" };
|
||||||
}
|
}
|
||||||
return %res;
|
return %res;
|
||||||
}
|
}
|
||||||
@ -124,18 +124,26 @@ sub pathToUnitName {
|
|||||||
|
|
||||||
# Compare the previous and new fstab to figure out which filesystems
|
# Compare the previous and new fstab to figure out which filesystems
|
||||||
# need a remount or need to be unmounted. New filesystems are mounted
|
# need a remount or need to be unmounted. New filesystems are mounted
|
||||||
# automatically by starting local-fs.target. FIXME: might be nicer if
|
# automatically by starting local-fs.target. Also handles swap
|
||||||
# we generated units for all mounts; then we could unify this with the
|
# devices. FIXME: might be nicer if we generated units for all
|
||||||
# unit checking code above.
|
# mounts; then we could unify this with the unit checking code above.
|
||||||
my %prevFstab = parseFstab "/etc/fstab";
|
my %prevFstab = parseFstab "/etc/fstab";
|
||||||
my %newFstab = parseFstab "@out@/etc/fstab";
|
my %newFstab = parseFstab "@out@/etc/fstab";
|
||||||
foreach my $mountPoint (keys %prevFstab) {
|
foreach my $mountPoint (keys %prevFstab) {
|
||||||
my $prev = $prevFstab{$mountPoint};
|
my $prev = $prevFstab{$mountPoint};
|
||||||
my $new = $newFstab{$mountPoint};
|
my $new = $newFstab{$mountPoint};
|
||||||
my $unit = pathToUnitName($mountPoint). ".mount";
|
my $unit = pathToUnitName($mountPoint). ".mount" if $prev->{fsType} ne "swap";
|
||||||
if (!defined $new) {
|
if (!defined $new) {
|
||||||
# Entry disappeared, so unmount it.
|
if ($prev->{fsType} eq "swap") {
|
||||||
push @unitsToStop, $unit;
|
# Swap entry disappeared, so turn it off. Can't use
|
||||||
|
# "systemctl stop" here because systemd has lots of alias
|
||||||
|
# units that prevent a stop from actually calling
|
||||||
|
# "swapoff".
|
||||||
|
system("@utillinux@/sbin/swapoff", $prev->{device});
|
||||||
|
} else {
|
||||||
|
# Filesystem entry disappeared, so unmount it.
|
||||||
|
push @unitsToStop, $unit;
|
||||||
|
}
|
||||||
} elsif ($prev->{fsType} ne $new->{fsType} || $prev->{device} ne $new->{device}) {
|
} elsif ($prev->{fsType} ne $new->{fsType} || $prev->{device} ne $new->{device}) {
|
||||||
# Filesystem type or device changed, so unmount and mount it.
|
# Filesystem type or device changed, so unmount and mount it.
|
||||||
write_file($restartListFile, { append => 1 }, "$unit\n");
|
write_file($restartListFile, { append => 1 }, "$unit\n");
|
||||||
@ -178,7 +186,7 @@ sub unique {
|
|||||||
# start both at the same time because we'll get a "Failed to add path
|
# start both at the same time because we'll get a "Failed to add path
|
||||||
# to set" error from systemd.
|
# to set" error from systemd.
|
||||||
my @start = unique(
|
my @start = unique(
|
||||||
"default.target", "local-fs.target",
|
"default.target", "local-fs.target", "swap.target",
|
||||||
split('\n', read_file($restartListFile, err_mode => 'quiet') // ""));
|
split('\n', read_file($restartListFile, err_mode => 'quiet') // ""));
|
||||||
print STDERR "starting the following units: ", join(", ", @start), "\n";
|
print STDERR "starting the following units: ", join(", ", @start), "\n";
|
||||||
system("@systemd@/bin/systemctl", "start", "--", @start) == 0 or $res = 4;
|
system("@systemd@/bin/systemctl", "start", "--", @start) == 0 or $res = 4;
|
||||||
|
@ -147,7 +147,7 @@ let
|
|||||||
preferLocalBuild = true;
|
preferLocalBuild = true;
|
||||||
buildCommand = systemBuilder;
|
buildCommand = systemBuilder;
|
||||||
|
|
||||||
inherit (pkgs) systemd;
|
inherit (pkgs) systemd utillinux;
|
||||||
|
|
||||||
inherit children;
|
inherit children;
|
||||||
kernelParams =
|
kernelParams =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user