Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-18-2019, 03:08 AM   #1
Registered: Jun 2014
Location: Poland/Gdynia
Distribution: Mageia 7, SH4, Debian
Posts: 195

Rep: Reputation: 4
FSTAB adding file as swap

I created on nanoPI (Ubuntu Xenial) swap file on attached USB SSD HDD partition (not seperate partition but already existing) using such commands:

$ dd if=/dev/zero of=/path/to/swapfile bs=1M count=1024 # For 1GB swap file
$ mkswap /path/to/swapfile
$ swapon /path/to/swapfile
And set in /etc/sysctl.conf

vm.swappiness = 10
My current /etc/fstab file looks like this:

LABEL=DYSK /home/pi/domoticz ext4 defaults,noatime,rw 1 2
/home/pi/domoticz/log /var/log none rw,bind 0 0
LABEL=4TB /home/pi/4TB ext4 defaults,noauto,noatime,rw 0 0
tmpfs /home/pi/ramdisk tmpfs nodev,nosuid,noexec,nodiratime,size=150K,uid=pi,gid=pi 0 0
tmpfs /var/LOG tmpfs nodev,nosuid,size=10M 0 0
media:/TMP /home/pi/MEDIA nfs rw,noauto,soft 0 0
Where LABEL=DYSK is related to /dev/sda1, that is 120 GB SSD HDD (connected via USB).

My question is. What is the proper syntax of entry in /etc/fstab for swap file (not partition) to be mounted automatically during boot time?
Old 03-18-2019, 03:40 AM   #2
Senior Member
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,444

Rep: Reputation: 902Reputation: 902Reputation: 902Reputation: 902Reputation: 902Reputation: 902Reputation: 902Reputation: 902

By the way, according to this page it's best not to use an SSD for file swapping. I am not sure why; I guess it must have something to do with wear and tear.
Old 03-18-2019, 04:48 AM   #3
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,127

Rep: Reputation: 2923Reputation: 2923Reputation: 2923Reputation: 2923Reputation: 2923Reputation: 2923Reputation: 2923Reputation: 2923Reputation: 2923Reputation: 2923Reputation: 2923
Maybe in days of yore - no longer a consideration with modern SSD.

However, the OP has been deliberately vague as to where the swap is located - let's guess it's under /home. Timing/race problems likely await.
Then again to my eye, the entire fstab schema is somewhat bizarre, but to each his own ... :shrug:
Old 03-18-2019, 09:03 AM   #4
Registered: Sep 2018
Distribution: Debian, CentOS, FreeBSD
Posts: 231

Rep: Reputation: Disabled
/path/to/file none            swap    sw              0       0
You might want to add a _netdev to your options to make sure that the file is available. The _netdev option means to wait until the network is available before trying to use the swap file. If it is a systemd based system, you can play around with the unit files to ensure the filesystem the swap file is on is up before it attempts to activate your swap file.
1 members found this post helpful.


fstab, swapfile, ubuntu

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
swap file vs. swap partition verndog Ubuntu 16 07-09-2012 08:49 PM
[SOLVED] Adding entries in /etc/fstab for swap in Ec2 servers call_krushna Linux - Server 6 01-19-2012 10:18 AM
swap file instead of swap disk "dd" error rezwits Linux - Newbie 5 12-16-2007 12:34 AM
Need Help Increasing Swap by creating a swap file froggo Red Hat 3 06-13-2006 08:04 AM
Adding more SWAP after adding memory marc1978 Linux - General 6 03-19-2006 07:13 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:28 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration