Putting the swap in the external usb hd?

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
Post Reply
bbmak
Posts: 24
Joined: Sat Oct 03, 2015 8:25 pm

Putting the swap in the external usb hd?

Post by bbmak »

Hi
Are there any particular reasons not putting the swap file in the external usb hard drive, but in /var/swap?
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Putting the swap in the external usb hd?

Post by Fourdee »

bbmak wrote:Hi
Are there any particular reasons not putting the swap file in the external usb hard drive, but in /var/swap?
The swapfile has a swapiness setting of 1. This means the swapfile is only used if you run out of RAM. Think of it as an emergency only usage.
So unless your system is constantly running out of available RAM, the swapfile will never be used.

Regardless, you have a valid point and i'll add your feature to v104:
https://github.com/Fourdee/DietPi/issues/147
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
User avatar
Fourdee
Site Admin
Posts: 2788
Joined: Tue Feb 06, 2007 1:36 pm

Re: Putting the swap in the external usb hd?

Post by Fourdee »

Done: https://github.com/Fourdee/DietPi/issue ... -165469381
This will be available for v104 and new installations only.

If you want to move your swapfile on your current installation to USB, do the following:
You will need to change the swapfile size if required. Either in the code below, or dietpi-config > advanced after.

Code: Select all

dphys-swapfile swapoff
rm /var/swap
echo -e "CONF_SWAPSIZE=100" > /etc/dphys-swapfile
echo -e "CONF_SWAPFILE=/mnt/usb_1/.swapfile" >> /etc/dphys-swapfile
dphys-swapfile setup
dphys-swapfile swapon
If you find our project or support useful, then we’d really appreciate it if you’d consider contributing to the project however you can.
Donating is the easiest – you can use PayPal or become a DietPi patron.
bbmak
Posts: 24
Joined: Sat Oct 03, 2015 8:25 pm

Re: Putting the swap in the external usb hd?

Post by bbmak »

Yes, I did change the swap file into the usb drive manually. My pi runs out of memory often.

An option to choose either on sd card or usb drive would be good. Because if I unplug the drive, it will throws me an error if I have swap on usb drive. so an option to move swap into usb drive.
testbug

Re: Putting the swap in the external usb hd?

Post by testbug »

I realize this is an old thread, so I just thought I'd ask if this is still the way to go?
Post Reply