Simple Linux Swap File Creation
-
A simple process for making a swapfile to add swap space to a Linux instance.
sudo fallocate -l 2G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo echo "/swapfile swap swap defaults 0 0">>/etc/fstab
Or to copypasta as a single line:
fallocate -l 2G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile && echo "/swapfile swap swap defaults 0 0">>/etc/fstab
-
When I was using Ubuntu Desktop, I used swapfile instead of a swap partition just so I don't have to waste disk space.
-
@black3dynamite said in Simple Linux Swap File Creation:
When I was using Ubuntu Desktop, I used swapfile instead of a swap partition just so I don't have to waste disk space.
Ubuntu has moved to it as the default, now.
-
@scottalanmiller said in Simple Linux Swap File Creation:
@black3dynamite said in Simple Linux Swap File Creation:
When I was using Ubuntu Desktop, I used swapfile instead of a swap partition just so I don't have to waste disk space.
Ubuntu has moved to it as the default, now.
When did that start?
-
@black3dynamite said in Simple Linux Swap File Creation:
@scottalanmiller said in Simple Linux Swap File Creation:
@black3dynamite said in Simple Linux Swap File Creation:
When I was using Ubuntu Desktop, I used swapfile instead of a swap partition just so I don't have to waste disk space.
Ubuntu has moved to it as the default, now.
When did that start?
Not all that long ago. two versions back, maybe.
-
@black3dynamite said in Simple Linux Swap File Creation:
@scottalanmiller said in Simple Linux Swap File Creation:
@black3dynamite said in Simple Linux Swap File Creation:
When I was using Ubuntu Desktop, I used swapfile instead of a swap partition just so I don't have to waste disk space.
Ubuntu has moved to it as the default, now.
When did that start?
Ubuntu 16.04
https://wiki.ubuntu.com/BionicBeaver/ReleaseNotes -
@scottalanmiller said in Simple Linux Swap File Creation:
A simple process for making a swapfile to add swap space to a Linux instance.
sudo fallocate -l 2G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo echo "/swapfile swap swap defaults 0 0">>/etc/fstab
Or to copypasta as a single line:
fallocate -l 2G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile && echo "/swapfile swap swap defaults 0 0">>/etc/fstab
This can be done in Noobs OS for raspberry tooo?
-
@lakshmana Should work on any Linux.
-
@scottalanmiller said in Simple Linux Swap File Creation:
A simple process for making a swapfile to add swap space to a Linux instance.
sudo fallocate -l 2G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo echo "/swapfile swap swap defaults 0 0">>/etc/fstab
Or to copypasta as a single line:
fallocate -l 2G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile && echo "/swapfile swap swap defaults 0 0">>/etc/fstab
sudo swapon /swapfile
wasn't working for me. In/var/log/messages
, I was getting these messages.
This works for me:
sudo dd if=/dev/zero of=/swapfile count=2048 bs=1MiB sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo echo "/swapfile swap swap defaults 0 0">>/etc/fstab
-
@scottalanmiller I think I did something similar a few months back to increase performance. Not sure it did much but I guess it hasn't hurt
-
@jmoore said in Simple Linux Swap File Creation:
@scottalanmiller I think I did something similar a few months back to increase performance. Not sure it did much but I guess it hasn't hurt
It reduces performance, but increases capacity.
-
@scottalanmiller said in Simple Linux Swap File Creation:
@jmoore said in Simple Linux Swap File Creation:
@scottalanmiller I think I did something similar a few months back to increase performance. Not sure it did much but I guess it hasn't hurt
It reduces performance, but increases capacity.
Does using a swapfile vs a swap partition reduce performance to the point it is significantly noticeable?
-
@dafyre said in Simple Linux Swap File Creation:
@scottalanmiller said in Simple Linux Swap File Creation:
@jmoore said in Simple Linux Swap File Creation:
@scottalanmiller I think I did something similar a few months back to increase performance. Not sure it did much but I guess it hasn't hurt
It reduces performance, but increases capacity.
Does using a swapfile vs a swap partition reduce performance to the point it is significantly noticeable?
No, that's why it's done now. Swap should be used SO little, and flexibility trumps the tiny performance increase.
-
@scottalanmiller Well that explains it lol. It was a long time ago now so don't remember what my logic was, or if there was any at all
-
Just manually installed CentOS 8 for the first time on my local system to test something, and they still use a swap partition by default.
Warns you if you delete it.
-
@JaredBusch said in Simple Linux Swap File Creation:
Just manually installed CentOS 8 for the first time on my local system to test something, and they still use a swap partition by default.
Warns you if you delete it.
I automatically ignore Fedora and CentOS warning about that.
-
@black3dynamite said in Simple Linux Swap File Creation:
@JaredBusch said in Simple Linux Swap File Creation:
Just manually installed CentOS 8 for the first time on my local system to test something, and they still use a swap partition by default.
Warns you if you delete it.
I ignore Fedora and CentOS warning about that.
-
@black3dynamite said in Simple Linux Swap File Creation:
I automatically ignore Fedora and CentOS warning about that.
I ignored it also. just pointing out the default behavior.