Swapfile should be renewed
Program fails on dphys-swapfile setup, as swapfile got not successfully removed before.
/DietPi/dietpi/func/dietpi-set_dphys-swapfile 1
DietPi-Swapfile
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Mode: Generating new swapfile
[ INFO ] DietPi-dphys-swapfile | Size = 1072 MB
[ INFO ] DietPi-dphys-swapfile | Location = /mnt/sda/dietpi_userdata/.swapfile
[ OK ] DietPi-dphys-swapfile | dphys-swapfile swapoff
[ INFO ] DietPi-dphys-swapfile | Deleting existing swapfile (/mnt/sda/dietpi_userdata/.swapfile)
[FAILED] DietPi-dphys-swapfile | dphys-swapfile setup
[ INFO ] DietPi-dphys-swapfile | exit_code = 1
[ INFO ] DietPi-dphys-swapfile | VERSION:v6.4 | HW_MODEL:2 | HW_ARCH:2 | DISTRO:5
[ INFO ] DietPi-dphys-swapfile | Log file contents:
want /mnt/sda/dietpi_userdata/.swapfile=1072MByte, checking existing
...
2018-03-09 21:03:16 root@micha:~# rm $(cat /etc/dphys-swapfile | grep -m1 '^CONF_SWAPFILE=' | sed 's/.*=//')
2018-03-09 21:03:45 root@micha:~# l /mnt/sda/dietpi_userdata/.swapfile
ls: cannot access '/mnt/sda/dietpi_userdata/.swapfile': No such file or directory
2018-03-09 21:03:50 root@micha:~# /DietPi/dietpi/func/dietpi-set_dphys-swapfile 1
[ OK ] Root access verified.
DietPi-Swapfile
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Mode: Generating new swapfile
[ INFO ] DietPi-dphys-swapfile | Size = 1072 MB
[ INFO ] DietPi-dphys-swapfile | Location = /mnt/sda/dietpi_userdata/.swapfile
[ OK ] DietPi-dphys-swapfile | dphys-swapfile swapoff
[ INFO ] DietPi-dphys-swapfile | Deleting existing swapfile (/mnt/sda/dietpi_userdata/.swapfile)
[ OK ] DietPi-dphys-swapfile | dphys-swapfile setup
[ OK ] DietPi-dphys-swapfile | dphys-swapfile swapon
[ INFO ] DietPi-dphys-swapfile | Setting /tmp tmpfs size: 1024M
[ OK ] DietPi-dphys-swapfile | mount -o remount,size=1024M tmpfs /tmp
bash -x run and found the exact same rm command. DietPi-Swapfile
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Mode: Generating new swapfile
[ INFO ] DietPi-dphys-swapfile | Size = 1072 MB
[ INFO ] DietPi-dphys-swapfile | Location = /mnt/sda/dietpi_userdata/.swapfile
[ OK ] DietPi-dphys-swapfile | dphys-swapfile swapoff
[ INFO ] DietPi-dphys-swapfile | Deleting existing swapfile (/mnt/sda/dietpi_userdata/.swapfile)
[FAILED] DietPi-dphys-swapfile | rm /mnt/sda/dietpi_userdata/.swapfile
[ INFO ] DietPi-dphys-swapfile | exit_code = 1
[ INFO ] DietPi-dphys-swapfile | VERSION:v6.4 | HW_MODEL:2 | HW_ARCH:2 | DISTRO:5
[ INFO ] DietPi-dphys-swapfile | Log file contents:
rm: cannot remove '/mnt/sda/dietpi_userdata/.swapfile': Operation not permitted
Found the issue:
dphys-swapfile swapoff on my RPi2 does not really disable swapfile. htop still shows it in use.swapoff -a on the other hand works, as well as dphys-swapfile uninstall. To stay with dphys-swapfile commands (which seem just wrappers for the default swapon/off from mount package I think dphys-swapfile uninstall needs to be added before dphys-swapfile setup / before swapfile removal / as swap file removal.dphys-swapfile swapoff does not work, as directly before we set swap location back to default, which is then tried to apply swapoff on: https://github.com/Fourdee/DietPi/blob/testing/dietpi/func/dietpi-set_dphys-swapfile#L123-L124On VM the command does not fail, but the file is not removed as well:
DietPi-Swapfile
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Mode: Generating new swapfile
[ INFO ] DietPi-dphys-swapfile | Size = 1059 MB
[ INFO ] DietPi-dphys-swapfile | Location = /mnt/dietpi_userdata/.swapfile
[ OK ] DietPi-dphys-swapfile | dphys-swapfile swapoff
[ INFO ] DietPi-dphys-swapfile | Deleting existing swapfile (/mnt/dietpi_userdata/.swapfile)
[ OK ] DietPi-dphys-swapfile | dphys-swapfile setup
[ OK ] DietPi-dphys-swapfile | dphys-swapfile swapon
[ INFO ] DietPi-dphys-swapfile | Setting /tmp tmpfs size: 1024M
[ OK ] DietPi-dphys-swapfile | mount -o remount,size=1024M tmpfs /tmp
root@VM-Stretch:~# /DietPi/dietpi/func/dietpi-set_dphys-swapfile 1
[ OK ] Root access verified.
DietPi-Swapfile
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Mode: Generating new swapfile
[ INFO ] DietPi-dphys-swapfile | Size = 1059 MB
[ INFO ] DietPi-dphys-swapfile | Location = /mnt/dietpi_userdata/.swapfile
[ OK ] DietPi-dphys-swapfile | dphys-swapfile swapoff
[ INFO ] DietPi-dphys-swapfile | Deleting existing swapfile (/mnt/dietpi_userdata/.swapfile)
[ OK ] DietPi-dphys-swapfile | dphys-swapfile setup
[ OK ] DietPi-dphys-swapfile | dphys-swapfile swapon
[ INFO ] DietPi-dphys-swapfile | Setting /tmp tmpfs size: 1024M
[ OK ] DietPi-dphys-swapfile | mount -o remount,size=1024M tmpfs /tmp
root@VM-Stretch:~# l /mnt/dietpi_userdata/.swapfile
-rw------- 1 root root 1110441984 Mar 9 23:15 /mnt/dietpi_userdata/.swapfile
DietPi-Swapfile
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Mode: Disable swapfile
[ OK ] DietPi-dphys-swapfile | dphys-swapfile swapoff
[ INFO ] DietPi-dphys-swapfile | Deleting existing swapfile (/mnt/dietpi_userdata/.swapfile)
[ INFO ] DietPi-dphys-swapfile | Setting /tmp tmpfs size: 494M
[ OK ] DietPi-dphys-swapfile | mount -o remount,size=494M tmpfs /tmp
root@VM-Stretch:~# l /mnt/dietpi_userdata/
total 1084908
drwxrwxr-x 2 dietpi dietpi 4096 Mar 1 22:49 downloads
-rw-r--r-- 1 root root 476627 Mar 4 19:01 mariadb-database-backup.sql
drwxrwxr-x 2 dietpi dietpi 4096 Mar 1 22:49 Music
drwxrwx--- 6 www-data www-data 4096 Feb 26 22:42 nextcloud_data
drwxrwxr-x 2 dietpi dietpi 4096 Mar 1 22:49 Pictures
-rw------- 1 root root 1110441984 Mar 9 23:15 .swapfile
drwxrwxr-x 2 dietpi dietpi 4096 Mar 1 22:49 Video
root@VM-Stretch:~# l /mnt/dietpi_userdata/.swapfile
-rw------- 1 root root 1110441984 Mar 9 23:15 /mnt/dietpi_userdata/.swapfile
Maybe just on RPi, maybe just or in combination with swapfile on external drive, the command fails. But on every device removal of swapfile does not work. Somehow it does work if done manually. But within script dphys-swapfile uninstall seems to be necessary:
root@VM-Stretch:~# dphys-swapfile swapoff
root@VM-Stretch:~# l /mnt/dietpi_userdata/.swapfile
-rw------- 1 root root 1110441984 Mar 9 23:15 /mnt/dietpi_userdata/.swapfile
root@VM-Stretch:~# dphys-swapfile uninstall
root@VM-Stretch:~# l /mnt/dietpi_userdata/.swapfile
ls: cannot access '/mnt/dietpi_userdata/.swapfile': No such file or directory
@MichaIng
Confirmed, good spot ๐
Notes (i'll edit/add more during testing):
#Swap on RootFS
root@DietPi:~# /DietPi/dietpi/func/dietpi-set_dphys-swapfile 20 /mnt/dietpi_userdata/.swapfile
Log file contents:
swapon: /mnt/63bb57bf-839e-4aaa-8f63-bacfa3349c78/dietpi_userdata/.swapfile:
swapon failed: Device or resource busy
remove dphys-swapfile, handle this in our scripts ourselves?
https://askubuntu.com/a/126049
Hey guys,
I was attempting to install DietPi and also got the same error.
I'm not sure if it is because I'm attempting to install it on a 2gb SD
(my 16gb died yeterday), I can try later in a bigger one to check if its
not just lackage of disk space since my disk is like this:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/root 1817488 1801088 0 100% /
==LOG==
Log file contents:
want /var/swap=1567MByte, generating swapfile ...
@raibtoffoletto
I'm not sure if it is because I'm attempting to install it on a 2gb SD
Hi,
DietPi requires a 4GB minimum SD card, to ensure a stable experience and sufficient swapfile based on total memory: http://dietpi.com/phpbb/viewtopic.php?f=8&t=9#p9
Previously, it was possible to set swapfile size to 0 in dietpi.txt, however, due to previous issues with swapfile generation on some images, we had to forcefully recreate them for all devices in v6.4 patch, overwriting any previous setting.
@MichaIng
Regardless of the above, we should add a freespace check, before creating the new swapfile? Maybe a new global?
G_FREESPACE path size_required
#size_required=in MB
root@DietPi:~# G_CHECK_FREESPACE / 10000;echo $?
[ OK ] Free space check: path=/ | available=11451 | required=10000
0
root@DietPi:~# G_CHECK_FREESPACE / 10000000; echo $?
[FAILED] Free space check: path=/ | available=11451 | required=10000000
1
@raibtoffoletto
Try running the following command to revert swapfile to 0MB:
/DietPi/dietpi/func/dietpi-set_dphys-swapfile 0
@Fourdee
Thanks a lot! I'm so sorry, I didn't see the 4gb requirement on the instructions.
(I was looking at an out-of-date guide somewhere and I didn't check it).
Anyway, I managed by copying var/ to an external usb and edit it to mount via /etc/fstab before first boot.
The install went without problems.
The problem was that with the swap error, the installation breaks and I don't have access anymore do
DietPi scripts... couldn't figure it out why. Anyway, I was attempting something out of the min specs....
@MichaIng
Resolved:
https://github.com/Fourdee/DietPi/blob/testing/dietpi/func/dietpi-set_dphys-swapfile#L102-L124
faallocate for speedy swapfile generation. Downside is possible fragmentation, however, shouldnt affect solid state drives.Tested:
@Fourdee
Very good, I thought already the same, after some research, that the main benefit of dphys-swapfile seems to be the automatic swap size determination, which we anyway choose ourself. Thus should be possible to skip this package and use native swap file methods of mount.
This eliminates other ideas I had to install/uninstall dphys-swapfile on setting/removing swapfile, e.g. for VMs, where we want to avoid them anyway.
dietpi-config needs adjusted swap size location: free -m | grep -im1 'Swap:' | awk '{print $2}' or read from new swap settings file. Will do commit later: https://github.com/Fourdee/DietPi/blob/testing/dietpi/dietpi-config#L1161-L1167
โฌ: Fast commit done: https://github.com/Fourdee/DietPi/commit/3bc8f5f2f53bc18c700fc0d5e1407c6769fa050e
free -m always shows the swap file size of 0, even if completely disabled, right? Otherwise add || [ -z "$swap_size" ]] for swap_text='Disabled'?
Added PR, as some more code affected to remove fstab entry when disabling swap and reduce/reorder code: https://github.com/Fourdee/DietPi/pull/1611
What do you think about skipping swap.conf and add swap location to dietpi.txt instead? I would also like to see swap location within dietpi-config, as it should be recommended to move it to external drive if available to reduce SD wear.
@MichaIng
and add swap location to dietpi.txt instead? I would also like to see swap location within dietpi-config,
Yep to both ๐
I also missed a few things in dietpi-software. I'll make the changes and send a commit.
Completed.
Most helpful comment
@MichaIng
Resolved:
https://github.com/Fourdee/DietPi/blob/testing/dietpi/func/dietpi-set_dphys-swapfile#L102-L124
faallocatefor speedy swapfile generation. Downside is possible fragmentation, however, shouldnt affect solid state drives.Tested: