wjmnelis
Posts: 31
Joined: Thu Oct 26, 2017 5:03 pm

With overlay of root, swap does not work

Fri Oct 11, 2019 5:40 pm

Swap does not work if an overlay over the root file system is defined.

In order to isolate the changes when compiling and installing a large program, and to extract the (compiled and linked) files needed to install that program on another RPi, an overlay of the root file system was defined. A 32 [GiB] SD card is used to install buster, and after configuration of Raspbian on an RPi, the SD card is modified using gparted. The large partition is halved and another partition (of about the same size) is defined. The RPi starts with this new partitioning of the SD card. The additional partition is mounted on /mnt. A modified version of script overlayRoot.sh (see http://wiki.psuter.ch/doku.php?id=solve ... _partition) is used. The modification is to use the additional partition in stead of tempfs file system(s).

It works, except for swap. In the 'upper dir', file /var/swap has been created with the configured size, but examination of /proc/meminfo shows that there is no swap space available. Various ways of stopping and starting, disabling and enabling dphys-swapfile all result in error message:

swapon: /var/swap: swapon failed: Invalid argument.

The status of the file systems is:

Code: Select all

pi@rpi3r:~ $ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
mmcblk0     179:0    0 29,7G  0 disk 
├─mmcblk0p1 179:1    0  256M  0 part /boot
├─mmcblk0p2 179:2    0 14,6G  0 part /ro
└─mmcblk0p3 179:3    0 14,9G  0 part /mnt
pi@rpi3r:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/mmcblk0p2   15G  9,2G  4,6G  67% /ro
overlayfs-root   15G  2,1G   12G  15% /
devtmpfs        459M     0  459M   0% /dev
tmpfs           464M     0  464M   0% /dev/shm
tmpfs           464M  6,4M  457M   2% /run
tmpfs           5,0M  4,0K  5,0M   1% /run/lock
tmpfs           464M     0  464M   0% /sys/fs/cgroup
tmpfs            16M  4,0K   16M   1% /tmp
tmpfs           1,0M   32K  992K   4% /overlay/xymon
tmpfs           1,0M  4,0K 1020K   1% /var/lib/xymon/tmp
/dev/mmcblk0p3   15G  2,1G   12G  15% /mnt
/dev/mmcblk0p1  253M   52M  201M  21% /boot
overlayfs       1,0M   32K  992K   4% /var/lib/xymon/www
tmpfs            93M     0   93M   0% /run/user/1000
pi@rpi3r:~ $cat /proc/meminfo | fgrep Swap
SwapCached:            0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
pi@rpi3r:~ $ 

What is needed to use swap space on the new root file system?

wjmnelis
Posts: 31
Joined: Thu Oct 26, 2017 5:03 pm

Re: With overlay of root, swap does not work

Tue Oct 22, 2019 2:08 pm

Well, to answer my question at least partially: use a swap partition in stead of a swap file.

I did not succeed in getting swapping to a swap file to work. The swap file, /var/swap, is created but is not used. On a Linux laptop, the overlay partition is resized to free up 2 [GiB]. In this space, a swap partition is defined. The swap file definition is then entered in the initial root file system in file /etc/fstab. The entries with respect to the SD card are:

Code: Select all

PARTUUID=5e3da3da-01	/boot		vfat	defaults	0	2
PARTUUID=5e3da3da-02	/		ext4	defaults,noatime 0	1
PARTUUID=5e3da3da-03	/mnt		ext4	defaults,noatime 0	1
PARTUUID=5e3da3da-04	none		swap	defaults	0	0
Then on the RPi 3B, the swap partition is activated:

Code: Select all

sudo mkswap /dev/mmcblk0p4
sudo swapon /dev/mmcblk0p4
After a reboot, swap is activ and being used. however, file /var/swap is still being generated although it is not used.

The current SD card layout and the file systems are:

Code: Select all

pi@rpi3r:~ $ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
mmcblk0     179:0    0 29,7G  0 disk 
├─mmcblk0p1 179:1    0  256M  0 part /boot
├─mmcblk0p2 179:2    0 14,6G  0 part /ro
├─mmcblk0p3 179:3    0 12,9G  0 part /mnt
└─mmcblk0p4 179:4    0    2G  0 part [SWAP]
pi@rpi3r:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/mmcblk0p2   15G  7,2G  6,6G  53% /ro
overlayfs-root   13G  313M   12G   3% /
devtmpfs        459M     0  459M   0% /dev
tmpfs           464M     0  464M   0% /dev/shm
tmpfs           464M   13M  451M   3% /run
tmpfs           5,0M  4,0K  5,0M   1% /run/lock
tmpfs           464M     0  464M   0% /sys/fs/cgroup
tmpfs           1,0M  200K  824K  20% /var/lib/xymon/tmp
tmpfs            16M  4,0K   16M   1% /tmp
tmpfs           1,0M   52K  972K   6% /overlay/xymon
/dev/mmcblk0p3   13G  313M   12G   3% /mnt
/dev/mmcblk0p1  253M   52M  201M  21% /boot
overlayfs       1,0M   52K  972K   6% /var/lib/xymon/www
tmpfs            93M     0   93M   0% /run/user/1000
pi@rpi3r:~ $ 

epoch1970
Posts: 3711
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: With overlay of root, swap does not work

Tue Oct 22, 2019 3:32 pm

FYI, I think there is now a new option in raspi-config to configure a rootfs overlay filesystem.
Never used it, no idea how it performs.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Return to “Advanced users”