This repository has been archived by the owner. It is now read-only.

Enable swap file support (#574) #585

Merged
merged 3 commits into from Sep 20, 2017

Conversation

Projects
None yet
2 participants
@craftyguy
Member

craftyguy commented Sep 15, 2017

This implements swap file support (as discussed in #574), and also removes swap partition settings from the N900.

New deviceinfo variable deviceinfo_swap_size_recommended can be used to specify a swap size for specific devices.

/etc/conf.d/swapfile contains two variables:

  • swap_size which will override deviceinfo_swap_size_recommended
  • swap_file which defaults to /swapfile

If the config file doesn't exist, then the service defaults looks to deviceinfo_swap_size_recommended for size. If that is unset, then the service will not set up any swap file.

PR configures the swapfile service to start on bootup.

If a user wants to reconfigure the swap size while pmos is booted, they just have to edit the config file and to sudo rc-service swapfile restart to have it applied.

Also, as discussed previously, "encrypted swap" comes for "free" since this file exists on the rootfs, which would presumably be encrypted (assuming no --no-fde at install time)

Please test!

Fixes #574

@craftyguy craftyguy self-assigned this Sep 15, 2017

@craftyguy craftyguy requested a review from ollieparanoid Sep 15, 2017

@ollieparanoid

Here is my first iteration of reviewing it, I have not tested it and usually there are more things that stick out once I do that. Thanks for making this PR! 🎉

@craftyguy

This comment has been minimized.

Show comment
Hide comment
@craftyguy

craftyguy Sep 16, 2017

Member

@ollieparanoid

I incorporated your changes and then added some logic to handle a 'bug' I identified.. So now the script will look at swap_size in the config file, if it is unset, then it looks at the deviceinfo_swap_size_recommended variable. It then writes the value of this deviceinfo variable to the config file (if deviceinfo var is not set, then it writes 0 to config).

The reason I did this is because it allows the value in deviceinfo_swap_size_recommended to actually be used by default. The user can then override this by editing the config file and then whatever is in deviceinfo_swap_size_recommended would have no effect on the swap size at that point (including device package updates, those would not override user-specific configuration).

Member

craftyguy commented Sep 16, 2017

@ollieparanoid

I incorporated your changes and then added some logic to handle a 'bug' I identified.. So now the script will look at swap_size in the config file, if it is unset, then it looks at the deviceinfo_swap_size_recommended variable. It then writes the value of this deviceinfo variable to the config file (if deviceinfo var is not set, then it writes 0 to config).

The reason I did this is because it allows the value in deviceinfo_swap_size_recommended to actually be used by default. The user can then override this by editing the config file and then whatever is in deviceinfo_swap_size_recommended would have no effect on the swap size at that point (including device package updates, those would not override user-specific configuration).

@ollieparanoid

Thanks for making the changes! I've tested it now, and added new comments.

@craftyguy

This comment has been minimized.

Show comment
Hide comment
@craftyguy

craftyguy Sep 19, 2017

Member
Member

craftyguy commented Sep 19, 2017

@ollieparanoid

This comment has been minimized.

Show comment
Hide comment
@ollieparanoid

ollieparanoid Sep 19, 2017

Member

Yes it does, good catch! I'll fix it.

Member

ollieparanoid commented Sep 19, 2017

Yes it does, good catch! I'll fix it.

@ollieparanoid

This comment has been minimized.

Show comment
Hide comment
@ollieparanoid

ollieparanoid Sep 19, 2017

Member

Wait a second, could it be that the magical overwrite comes from the /sbin/swapfile? TBH I did not realize that we write to the config file from there. That would make a lot more sense compared to having the bug in OpenRC. If you don't mind, could you check this?

Member

ollieparanoid commented Sep 19, 2017

Wait a second, could it be that the magical overwrite comes from the /sbin/swapfile? TBH I did not realize that we write to the config file from there. That would make a lot more sense compared to having the bug in OpenRC. If you don't mind, could you check this?

@craftyguy

This comment has been minimized.

Show comment
Hide comment
@craftyguy

craftyguy Sep 19, 2017

Member

Wait a second, could it be that the magical overwrite comes from the /sbin/swapfile?

I write the value from deviceinfo_swap_size_recommended to swap_size variable in the conf file here., but only if swap_size is unset (or missing) from the config file.. It (my script) shouldn't delete any existing values (e.g. if swap_size is set), or even replace the comment # swap_size= with a blank line..

Member

craftyguy commented Sep 19, 2017

Wait a second, could it be that the magical overwrite comes from the /sbin/swapfile?

I write the value from deviceinfo_swap_size_recommended to swap_size variable in the conf file here., but only if swap_size is unset (or missing) from the config file.. It (my script) shouldn't delete any existing values (e.g. if swap_size is set), or even replace the comment # swap_size= with a blank line..

craftyguy and others added some commits Sep 15, 2017

Fix variable naming, work around OpenRC bug in config file
Turns out, OpenRC replaces the line, in case it is set to
`#swap_size=1024` (which would be consistent with other conf.d
files), but not if it is set to `# swap_size=1024`.

See also: OpenRC/openrc#165
Remove code to set swap_size
Per discussion in chat, this is not necessary and may cause unintended consequences with openrc.
@ollieparanoid

Tested and working 👍

@ollieparanoid ollieparanoid merged commit 220cd7b into master Sep 20, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@ollieparanoid ollieparanoid deleted the feature/574_swap_file branch Sep 20, 2017

PureTryOut added a commit that referenced this pull request Feb 21, 2018

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`).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.