Jump to content

Moving SWAP to SATA or external drive


Recommended Posts

Installed image Jessie server (Legacy) on the board BananaPi. Connected HDD SATA, create two partitions /dev/sda1 (swap) and /dev/sda2 (ext4). The system moved to /dev/sda2. How to move a swap of the /var/swap (in /etc/fstab) on /dev/sda1? How does the script /tmp/create_swap.sh? It starts with the system?

Link to comment
Share on other sites

Hi mate,

log in your system with terminal and do commands.

 

1) you need to be sure swap is not used

swapoff -a

 

2) move swap to different location or create new one swap file or swap partition. Second is better, first simple to create.

Here is example for 1G swap file:

dd if=/dev/zero bs=1M count=1024 of=/var/swap.img

 

3)change path and filename if necessary in fstab

 

nano /etc/fstab

 

4)run command "swapon -a" or reboot

 

Sent from my Redmi Note 2 using Tapatalk

Link to comment
Share on other sites

Hi again,

I found great article about swap folow link below. But I must mention something important. Swap file does not contain any valuable information. So it has not sense to move it. We just delete old, create new one and change path if it is a file somewhere on filesystem or UUID if it is partition in fstab.

I do prefer to create swap partition on the end of sdcard or microsd because even value on label of card says it is 8GB every brand has different capacity. And this difference can be sometimes more than 100MB. So I decided to shrink root partition to 7.5GB and rest of capacity is swap partition. When I need to clone whole microsd I delete swap partition first, then I use simple dd command to clone it with bootloader and everything and for last I do create new swap partition.

 

Somebody can say I can do same with simple script which can resize root and left swap like originally was inside root because we do not want to use swap at all on slow these cards and it is here for emergency.

 

Answer is you have right. Swapfile on microsd card is for emergency cases only because it has low I/O bandwitch and I personally do prefer using swap partition if it is necessary on singleboard computers with sata port attached ssd's (even somebody can protest we do swaps on spindle drives because it do not lower it's lifetime).

 

https://www.linux.com/news/all-about-linux-swap-space

Link to comment
Share on other sites

@technik007_cz @electric

 

 

I found great article about swap folow link below. But I must mention something important. Swap file does not contain any valuable information. So it has not sense to move it. We just delete old, create new one and change path if it is a file somewhere on filesystem or UUID if it is partition in fstab.


 

Answer is you have right. Swapfile on microsd card is for emergency cases only because it has low I/O bandwitch and I personally do prefer using swap partition if it is necessary on singleboard computers with sata port attached ssd's (even somebody can protest we do swaps on spindle drives because it do not lower it's lifetime).

 

 

1/ paranoid mode: shred the swap because it may leak sensitive information, then delete :)

 

2/ IMHO, why bothering to partition a SD card for a swap space?

Considering SD card I/O is very slow, my guess just create a file on top of the ext4 root filesystem, then "mkswap" the file, then add it to /etc/fstab at the end of the list

 

Of course, unless you are doing full hibernation (swap partition needed I guess), the extra CPU overhead of ext4 is small & less risky compared to partition manipulation.

Link to comment
Share on other sites

Maybe not understood my question.
I mean how to move swap file is on armbian 5.10?
swap created script /tmp/create_swap.h. He runs like that with the system and creates a swap (maybe).
I suppose that the script can be turned off (how?), and then do everything in Linux:

 

Hi mate,
log in your system with terminal and do commands.

1) you need to be sure swap is not used
swapoff -a

2) move swap to different location or create new one swap file or swap partition. Second is better, first simple to create.
Here is example for 1G swap file:
dd if=/dev/zero bs=1M count=1024 of=/var/swap.img

3)change path and filename if necessary in fstab

nano /etc/fstab

4)run command "swapon -a" or reboot

Sent from my Redmi Note 2 using Tapatalk

 

Link to comment
Share on other sites

I tried to find script called "create_swap.sh" but I cannot find it in my system.

 

I introduced a bug in early April preventing our firstrun script (that enables swap each and every time it gets executed by creating a separate script called /tmp/create_swap.sh) from disabling itself. Zador fixed that in the meantime (one single line has to be removed otherwise on a few boards firstrun gets always executed): https://github.com/igorpecovnik/lib/commit/bf9f64b494bc900ded92b8d1c99f321ff8512dc8#diff-7563a343fbfc02b76915df346c297ba1

 

So either remove this line in /etc/init.d/firstrun manually or upgrade to 5.11. Afterwards you can move swap to whereever you want.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines