mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 10:09:07 +00:00
Merge pull request #3370 from guillaumerose/swap
Create swap file only if absent
This commit is contained in:
commit
4dc5d0a3fb
@ -26,7 +26,7 @@ onboot:
|
|||||||
command: ["/usr/bin/mountie", "/var/lib"]
|
command: ["/usr/bin/mountie", "/var/lib"]
|
||||||
# make a swap file on the mounted disk
|
# make a swap file on the mounted disk
|
||||||
- name: swap
|
- name: swap
|
||||||
image: linuxkit/swap:v0.7
|
image: linuxkit/swap:f8b0434963b4c9114db473aab3b9409bccd4f85b
|
||||||
command: ["/swap.sh", "--path", "/var/lib/swap", "--size", "1024M"]
|
command: ["/swap.sh", "--path", "/var/lib/swap", "--size", "1024M"]
|
||||||
# mount-vpnkit mounts the 9p share used by vpnkit to coordinate port forwarding
|
# mount-vpnkit mounts the 9p share used by vpnkit to coordinate port forwarding
|
||||||
- name: mount-vpnkit
|
- name: mount-vpnkit
|
||||||
|
@ -18,7 +18,7 @@ onboot:
|
|||||||
image: linuxkit/mount:v0.7
|
image: linuxkit/mount:v0.7
|
||||||
command: ["/usr/bin/mountie", "/var/external"]
|
command: ["/usr/bin/mountie", "/var/external"]
|
||||||
- name: swap
|
- name: swap
|
||||||
image: linuxkit/swap:v0.7
|
image: linuxkit/swap:f8b0434963b4c9114db473aab3b9409bccd4f85b
|
||||||
# to use unencrypted swap, use:
|
# to use unencrypted swap, use:
|
||||||
# command: ["/swap.sh", "--path", "/var/external/swap", "--size", "1G"]
|
# command: ["/swap.sh", "--path", "/var/external/swap", "--size", "1G"]
|
||||||
command: ["/swap.sh", "--path", "/var/external/swap", "--size", "1G", "--encrypt"]
|
command: ["/swap.sh", "--path", "/var/external/swap", "--size", "1G", "--encrypt"]
|
||||||
|
@ -115,7 +115,13 @@ done
|
|||||||
### Required? exit 1
|
### Required? exit 1
|
||||||
### Else? exit 0
|
### Else? exit 0
|
||||||
|
|
||||||
|
if [ "$ENCRYPT" == "true" ]; then
|
||||||
|
SWAPDEV=/dev/mapper/swapfile
|
||||||
|
else
|
||||||
|
SWAPDEV=$path
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f $path ] || ! [ $(stat -c "%s" $path) == $(disksize_to_count 1 $size) ]; then
|
||||||
## Allocate the file
|
## Allocate the file
|
||||||
dd if=/dev/zero of=$path bs=1024 count=$(disksize_to_count 1024 $size)
|
dd if=/dev/zero of=$path bs=1024 count=$(disksize_to_count 1024 $size)
|
||||||
chmod 0600 $path
|
chmod 0600 $path
|
||||||
@ -127,11 +133,9 @@ if [ "$ENCRYPT" == "true" ]; then
|
|||||||
#losetup ${loop} ${path}
|
#losetup ${loop} ${path}
|
||||||
|
|
||||||
cryptsetup open --type plain --key-file /dev/urandom --key-size=256 --cipher=aes-cbc-essiv:sha256 --offset=0 ${path} swapfile
|
cryptsetup open --type plain --key-file /dev/urandom --key-size=256 --cipher=aes-cbc-essiv:sha256 --offset=0 ${path} swapfile
|
||||||
SWAPDEV=/dev/mapper/swapfile
|
|
||||||
else
|
|
||||||
SWAPDEV=$path
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## mkswap and swapon the device
|
|
||||||
/sbin/mkswap $SWAPDEV
|
/sbin/mkswap $SWAPDEV
|
||||||
|
fi
|
||||||
|
|
||||||
/sbin/swapon $SWAPDEV
|
/sbin/swapon $SWAPDEV
|
||||||
|
Loading…
Reference in New Issue
Block a user