2013-08-16 15:21:59 +02:00
|
|
|
#!/bin/sh
|
2018-07-16 20:45:36 +02:00
|
|
|
|
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
# Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv)
|
2022-10-24 14:44:30 +00:00
|
|
|
# Copyright (C) 2022-present Team LibreELEC (https://libreelec.tv)
|
2010-10-23 19:54:08 +02:00
|
|
|
|
2012-05-19 02:28:16 +02:00
|
|
|
. /etc/swap.conf
|
2013-10-18 19:43:12 +03:00
|
|
|
. /etc/profile
|
2012-05-19 02:28:16 +02:00
|
|
|
|
2013-08-16 15:21:59 +02:00
|
|
|
if [ -f /storage/.config/swap.conf ]; then
|
|
|
|
|
. /storage/.config/swap.conf
|
2012-05-19 02:28:16 +02:00
|
|
|
fi
|
|
|
|
|
|
2013-10-18 19:43:12 +03:00
|
|
|
if [ -e /dev/.storage_netboot ] ; then
|
|
|
|
|
logger -t Boot "### netbooting... swap disabled ###"
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2022-10-24 14:44:30 +00:00
|
|
|
if [ ! "${SWAP_ENABLED}" = "yes" ] ; then
|
2014-01-04 00:08:43 +01:00
|
|
|
logger -t Boot "### swap disabled via configfile ###"
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2022-10-24 14:44:30 +00:00
|
|
|
SWAP=$(blkid -t TYPE="swap" -o device)
|
2010-10-23 19:54:08 +02:00
|
|
|
|
2013-08-16 15:21:59 +02:00
|
|
|
case $1 in
|
|
|
|
|
create)
|
2022-10-24 14:44:30 +00:00
|
|
|
if [ -z "${SWAP}" ] && [ ! -f "${SWAPFILE}" ]; then
|
|
|
|
|
mkdir -p "$(dirname ${SWAPFILE})"
|
|
|
|
|
dd if=/dev/zero of="${SWAPFILE}" bs=1M count="${SWAPFILESIZE}"
|
|
|
|
|
chmod 0600 "${SWAPFILE}"
|
|
|
|
|
mkswap "${SWAPFILE}"
|
2011-09-12 19:26:05 +02:00
|
|
|
fi
|
2013-08-16 15:21:59 +02:00
|
|
|
;;
|
|
|
|
|
mount)
|
2022-10-24 14:44:30 +00:00
|
|
|
{ [ -z "${SWAP}" ] && [ -f "${SWAPFILE}" ]; } && SWAP="${SWAPFILE}"
|
|
|
|
|
for i in ${SWAP}; do
|
|
|
|
|
swapon -p 10000 "${i}"
|
2013-08-16 15:21:59 +02:00
|
|
|
done
|
|
|
|
|
;;
|
|
|
|
|
unmount)
|
|
|
|
|
swapoff -a
|
|
|
|
|
;;
|
|
|
|
|
esac
|