Close #574: swap file support/encrypted swap on rx51 (#585)

This adds a custom swap file service, which allows specifying a
recommended swap size in the deviceinfo file via
`deviceinfo_swap_size_recommended`. For the N900 this defaults
to 1024 MB now. As the swap file is created in the root partition,
we have encrypted swap now (unless encryption is disabled with
`--no-fde`).
This commit is contained in:
clayton craft 2017-09-20 18:32:19 +00:00 committed by Oliver Smith
parent bf6f5cb884
commit 220cd7b442
8 changed files with 153 additions and 14 deletions

View file

@ -1,6 +1,6 @@
pkgname=device-nokia-rx51
pkgver=1
pkgrel=16
pkgrel=17
pkgdesc="Nokia N900"
url="https://github.com/postmarketOS"
arch="noarch"
@ -56,7 +56,7 @@ package() {
"$pkgdir"/usr/share/bkeymaps/us/rx51_us.bmap.gz
}
sha512sums="998790a43f6994ef919ac5b629ef23d76e3bcdf5e80987af996bec71c86bace7510e1ca59c20b14faf79dc986ad8c74c5cb5c44c9043905e877ebecc06232b4c deviceinfo
sha512sums="0c88afd6169f22f75f50c8475690b447eedbe29b24d7feb425dd2725f9a32482602cee32d0cfd6028f59cde03343a07bc5f951904a72ca4f62c460a79b2a4b00 deviceinfo
1b89309dd4fe7ee0ba37c6224a0152d6864bb1c7bc4e96918a57e01bebc4173559855ae9673887223de4a8baa3191c8ad88ec8594776a4110cdb19a7be790db4 uboot-script.cmd
3d55e34b95791636e44a5f41754f3d0de039dbba41f7a556d43a95c9e64afcfa930046b4b96b40020b6f196096ffba93514682927e32fa4488686fdd19c6da5a backlight-enable.sh
98c554a709d6e8da5835bd792d833355d830fca1cfea12ec7fe4f41d1d1126389c51a8a392a7f94093473c19263cc6846cc40d7e179c2facf12db2d68ff923f9 90-touchscreen-dev.rules
@ -64,4 +64,4 @@ sha512sums="998790a43f6994ef919ac5b629ef23d76e3bcdf5e80987af996bec71c86bace7510e
df5dcae9a32d04ba2fed8b4dbb8722f8d56d063a288dfbaeca37806bdbb8ba4de639b392859b9f24040a1032456d5dcd754f51314e3ab66515b91ae1e03c93a7 acpi_handler.sh
7761aec6e6e219245b006e7bdc1d19812e9c5915cf3e64bb3dd46bb4b5570c1715650b53a1fc1007cb814076b5d81be0a66ba7ebf06d9a1fa4e364725c3ee633 acpi.map
c9ff8b5968fe94007e1139db5ae76f3ee6c214356bff297b9672276c6adb332ba2342b6ca54cf7992d6556f3c68a13ef49ae5e61abe86154935514034170e228 rx51_us.map
f340da5af204292350969cfdc0e541b96aec5857deeb20d3db5fe6cbb7d84c21cceb505f80db0df5486d9eb325cdce140255f227ed3ac1abc162fc9724e2d9a3 device-nokia-rx51.post-install"
12d5c1cc4295bbcaad5f0aa7dc73055ed062e53be2d249c2d067624da8fe373fc3c49f68462797d0fc3b9a79079ca657aece77437319dc9772c2624844873891 device-nokia-rx51.post-install"

View file

@ -28,11 +28,6 @@ fi
if [ -z "$(grep /boot /etc/fstab)" ]; then
echo "/dev/dm-0 /boot ext2 defaults 0 0" >> /etc/fstab
fi
# Add swap to fstab & enable swap on device startup
if [ -z "$(grep /dev/mmcblk1p3 /etc/fstab)" ]; then
echo "/dev/mmcblk1p3 none swap defaults 0 0" >> /etc/fstab
fi
rc-update add swap default
# Set RTC device for hwclock
if [ -z "$(grep /dev/rtc0 /etc/conf.d/hwclock)" ]; then

View file

@ -15,6 +15,7 @@ deviceinfo_external_disk_install="true"
deviceinfo_flash_methods="0xFFFF"
deviceinfo_generate_legacy_uboot_initfs="true"
deviceinfo_arch="armhf"
deviceinfo_swap_size_recommended="1024"
# Splash screen
deviceinfo_screen_width="800"

View file

@ -1,16 +1,23 @@
pkgname=postmarketos-base
pkgver=2
pkgrel=9
pkgver=3
pkgrel=0
pkgdesc="Meta package for minimal postmarketos base"
url="https://github.com/postmarketOS"
arch="noarch"
license="GPL3+"
depends="alpine-base haveged cryptsetup wpa_supplicant iw openssh mosh
tmux htop nano postmarketos-mkinitfs eudev sudo"
tmux htop nano postmarketos-mkinitfs eudev sudo util-linux"
makedepends=""
install="$pkgname.post-install"
subpackages=""
source="sudoers firmwareload.sh 50-firmware.rules $install"
source="
sudoers
firmwareload.sh
50-firmware.rules
swapfile/swapfile
swapfile/swapfile.init
swapfile/swapfile.conf
$install"
options="!check"
package() {
@ -21,8 +28,19 @@ package() {
install -D -m755 "$srcdir"/firmwareload.sh \
"$pkgdir"/usr/lib/firmwareload.sh
# Install swapfile
install -Dm755 "$srcdir"/swapfile \
"$pkgdir"/sbin/swapfile
install -Dm644 "$srcdir"/swapfile.conf \
"$pkgdir"/etc/conf.d/swapfile
install -Dm755 "$srcdir"/swapfile.init \
"$pkgdir"/etc/init.d/swapfile
}
sha512sums="c6de3b44bc45b9f9c641a7e34c69a481ee39b99ac0251cd28f2b3aae49c1a8d1ca448f4936b7942b1a8b8f7c18a5415c938098765ed8cf08456543800160e64b sudoers
38dc75c0ed32b76dccd3d8e7e8173e8b7d91847cf2b07123f376b95af46b4f89798b24f45302a0726fdc1cf253aecaac140f431735ac5c6511553f790badd0af firmwareload.sh
0b098828080055d3646ea54891cb0e1b578cbc30f5e16f7284f2814c08192f18079a38fb686d192715ae6a3d2cd6625d9e3cf99f234a6f0d94088bb0cb2ce43d 50-firmware.rules
b3bf756c5100cc49260d38014faada287bbbba3da4d404f08b76db1b925adc0d30a37e1c37e318f4f698ca353790d715b825cf18fe1bb81a6988976b051530b2 postmarketos-base.post-install"
3ceeee37f558e7c95ad973692b6a437f997e6b46c3d1c2257ddfb1529a5633477373aa123c7f08164e818daae50acb203d151379f27ca11bd458809e6a0d4de7 swapfile
f5cc0f1265955d2646e5f099dd4b5d4c287945bfc18c16044db57670d456f55c678fc11cc59e6dab3fa340832ce869d516302a3a35c13518539ed0cedca51819 swapfile.init
e0d2d48b82a03239a4c0a00acaf83e00d397c23a8d7c71053d4e2a383357c22dcedef9e81b0e12a1d7514e1fdbe0bb3eb82613d18b29034a7ce5447f13c84a53 swapfile.conf
05d72e10ddba17a8f4584cd5223d58f53809c42f8ab3ab71fa50bf2a9da390661ed470fe8b8f0296959d23141d8a61b3a233c45db5c3236fbd814115363b0006 postmarketos-base.post-install"

View file

@ -9,7 +9,7 @@ done
for service in hwclock modules sysctl hostname bootmisc syslog; do
rc-update -q add $service boot
done
for service in haveged sshd udev wpa_supplicant; do
for service in haveged sshd udev wpa_supplicant swapfile; do
rc-update -q add $service default
done
for service in mount-ro killprocs savecache; do

View file

@ -0,0 +1,95 @@
#!/bin/sh
#################################################################################
# Copyright 2017 Clayton Craft <clayton@craftyguy.net>
#
# This file is part of postmarketos-base
#
# postmarketos-base is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# postmarketos-base is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this postmarketos-base. If not, see <http://www.gnu.org/licenses/>.
#################################################################################
# $1 = swap file location
function remove_old_swap() {
local _swap_file=$1
swapoff ${_swap_file} 2>/dev/null
rm ${_swap_file}
if [ -e ${_swap_file} ]; then
echo "Unable to remove old swap file!"
exit 1
fi
}
# $1 = swap file location
# $2 = swap file size
function make_swap() {
local _swap_file=$1
local _swap_size=$2
# Allocate space on disk for swap
fallocate -l ${_swap_size}M ${_swap_file}
# Set correct file permissions for swap file
chown root:root ${_swap_file}
chmod 600 ${_swap_file}
#format swap file
mkswap ${_swap_file} 1>/dev/null
}
if [ "$(id -u)" != "0" ]; then
echo "This script can only be run as root"
exit 1
fi
config=/etc/conf.d/swapfile
if [ ! -f ${config} ]; then
echo "Unable to find config at: ${config}"
exit 1
fi
# deviceinfo is a pmOS-specific thing, but it's not *required*
source /etc/deviceinfo
source /etc/conf.d/swapfile
# Configure swap size. Size is in MB
# If size in config is unset then use value from deviceinfo,
# or default to 0 if neither is set
if [ -z "${swap_size}" ]; then
if [ -n "${deviceinfo_swap_size_recommended}" ]; then
swap_size=${deviceinfo_swap_size_recommended}
else
swap_size=0
fi
fi
if [ "${swap_size}" == "0" ]; then
echo "Configured swap file size is 0, skipping creation."
exit 0
fi
swap_file="${swap_file:-/swapfile}"
echo "Setting up swap file of size ${swap_size}MB at ${swap_file}..."
# Clean up old swap file
if [ -f ${swap_file} ]; then
remove_old_swap ${swap_file}
fi
# Create swap file
make_swap ${swap_file} ${swap_size}
# Activate swap file
swapon ${swap_file}
echo "Successfully activated swap file!"
exit 0

View file

@ -0,0 +1,3 @@
swap_file=/swapfile
# Size is in MB
# swap_size=1024

View file

@ -0,0 +1,27 @@
#!/sbin/openrc-run
depend()
{
after localmount
}
start()
{
ebegin "Activating swap file"
/sbin/swapfile
eend $?
}
stop()
{
ebegin "Deactivating swap file"
/sbin/swapoff -a >/dev/null
eend $?
}
restart()
{
ebegin "Restarting swap file"
start
eend $?
}