Out of RAM: Increase a meagre swapfile under Linux

Swap space is an area set aside for use in the event that physical RAM becomes full. On a Linux machine, when the system runs out of RAM inactive pages are moved to the Swap Space freeing up RAM.

Whilst building a Yocto Image on an old machine with limited RAM I was getting repeated failures during the compilation of qtbase. Analysis of the kernel log revealed that there was a shortage of memory, and hence a need to increase the swap space.

You can determine the current status of the swap space using the following command

$ sudo swapon --show
NAME      TYPE SIZE   USED PRIO
/swapfile file   2G 265.9M   -2

To increase the size of the swapfile, begin by disabling the swap space, and then remove the existing swapfile.

sudo swapoff /swapfile
sudo rm /swapfile

You can now create a new blank swapfile, set the permissions associated with it, and then re-enable the swap space.

sudo dd if=/dev/zero of=/swapfile bs=1M count=8192
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Yocto: How to assign variables with examples

  • = A hard assignment. The variable is assigned as soon as the statement is evaluated. If the assignment contains a reference to another variable then that reference will be included in the assignment rather that the value of the reference.
  • ?= Defines a variable only if it is undefined at the time of parsing.
  • ??= Assignment does not occur until the end of the parsing process.
  • := Immediate variable expansion
  • += Appending with spaces.
  • =+ Prepending with spaces.
  • .= Appending without spaces.
  • =. Prepending without spaces.

Assignment Using Overrides

Variables can be appended or prepended using the override style syntax. In the example below B becomes equal to “bval additional data” and C becomes equal to “additional data cval”. Note that no additional spaces are include over what is in the original variable definitions.

B = "bval"
B_append = " additional data"
C = "cval"
C_prepend = "additional data "

Removal of data can also be accomplished. In the following example FOO becomes equal to “ghi abcdef”. Note that surrounding spaces are also removed.

FOO = "abc def ghi abcdef abc def abc def"
FOO_remove = "abc def"

Examples

In the following example the value of A is set to “aval”. The value of B is set to “pre${A}post”. In other words the value of B becomes dependent on the value of A at the times it is referenced. If the value of A changes between references to B the value of B will be different at those times.

A = "aval"
B = "pre${A}post"

The following code includes some immediate variable assignment. The value of A becomes “test 123” as the values of A and B are unassigned at the time of As assignment.

T = "123"
A := "${B} ${A} test ${T}"

The following code uses a soft assignment. A is only assigned if the value is currently unassigned. The code therefore results in A being given the value of “one”

A ?= "one"
A ?= "two"

The following code uses weak assignment. A is not assigned until the end of the parsing process and is therefore given a value of “two”

A ??= "one"
A ??= "two"

Yocto: base_contains

The base_contains function is used to return a value based on a search of a named variable for a given value. The following line of code for example would search the DISTRO_FEATURES variable for the text bluetooth and if found it would return the text bluez5 otherwise we would get a blank.

"${@base_contains('DISTRO_FEATURES', 'bluetooth', 'bluez5', '', d)}"

Yocto: Setting the root password

To set the root password under a Yocto build you need to add the following code to the local.conf file located in the build/conf directory.

INHERIT += "extrausers"
EXTRA_USERS_PARAMS = "usermod -p Rbna8drt0yYLk root;"

Where the Rbna8drt0yYLk value is generated via the command

$ openssl passwd <password>