3
0
Fork 0
forked from mirrors/nixpkgs

* Allow swap devices to be specified by label.

svn path=/nixos/trunk/; revision=7609
This commit is contained in:
Eelco Dolstra 2007-01-10 13:07:57 +00:00
parent cb10364838
commit 24e34612e3
4 changed files with 41 additions and 16 deletions

View file

@ -9,7 +9,9 @@
}
];
swapDevices = ["/dev/sdb1"];
swapDevices = [
{ device = "/dev/sdb1"; }
];
services = {
sshd = {

View file

@ -212,10 +212,19 @@
{
name = ["swapDevices"];
default = [];
example = ["/dev/hda7" "/dev/hdb3" "/var/swapfile"];
example = [
{device="/dev/hda7";}
{device="/var/swapfile";}
{label="bigswap";}
];
description = "
The swap devices and swap files. These must have been
initialised using <command>mkswap</command>.
initialised using <command>mkswap</command>. Each element
should be an attribute set specifying either the path of the
swap device or file (<literal>device</literal>) or the label
of the swap device (<literal>label</literal>, see
<command>mkswap -L</command</command>). Using a label is
recommended.
";
}

View file

@ -46,7 +46,7 @@ import ../upstart-jobs/gather.nix {
# Swapping.
(import ../upstart-jobs/swap.nix {
inherit (pkgs) utillinux;
inherit (pkgs) utillinux library;
swapDevices = config.get ["swapDevices"];
})

View file

@ -1,4 +1,14 @@
{utillinux, swapDevices}:
{library, utillinux, swapDevices}:
let
devicesByPath =
map (x: x.device) (library.filter (x: x ? device) swapDevices);
devicesByLabel =
map (x: x.label) (library.filter (x: x ? label) swapDevices);
in
{
name = "swap";
@ -8,21 +18,25 @@ start on startup
start on new-devices
script
for device in ${toString swapDevices}; do
# !!! Check whether we are already swapping to $device.
for device in ${toString devicesByPath}; do
${utillinux}/sbin/swapon \"$device\" || true
done
# Remove swap devices not listed in swapDevices.
for used in $(cat /proc/swaps | grep '^/' | sed 's/ .*//'); do
found=
for device in ${toString swapDevices}; do
if test \"$used\" = \"$device\"; then found=1; fi
done
if test -z \"$found\"; then
${utillinux}/sbin/swapoff \"$used\" || true
fi
for label in ${toString devicesByLabel}; do
${utillinux}/sbin/swapon -L \"$label\" || true
done
# Remove swap devices not listed in swapDevices.
# !!! disabled because it doesn't work with labels
#for used in $(cat /proc/swaps | grep '^/' | sed 's/ .*//'); do
# found=
# for device in $ {toString swapDevices}; do
# if test \"$used\" = \"$device\"; then found=1; fi
# done
# if test -z \"$found\"; then
# ${utillinux}/sbin/swapoff \"$used\" || true
# fi
#done
end script
";