Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
swapfile not on / not mouted at start
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
Frautoincnam
Guru
Guru


Joined: 19 May 2017
Posts: 324

PostPosted: Wed Jul 14, 2021 2:19 pm    Post subject: swapfile not on / not mouted at start Reply with quote

Hi,

I have a swap partition, and I want to add a swap file.
If this swap file is on root partition, all works fine, it is mounted at start with fstab :
Code:
/dev/sdb1               /               ext3            noatime,user_xattr      0 1
/swapfile               none            swap            sw                      0 0

But, if I put it on another disk/partition :
Code:
/dev/sda5               /other          ext3            acl,noatime,user_xattr  1 2
/other/swapfile         none            swap            sw                      0 0

It isn't mounted at start.
but swapon -a works.
Does mounting that swap file should "wait" for this partition (/dev/sda5) being mounted ? and how ?
Back to top
View user's profile Send private message
figueroa
Advocate
Advocate


Joined: 14 Aug 2005
Posts: 3005
Location: Edge of marsh USA

PostPosted: Thu Jul 15, 2021 5:20 am    Post subject: Reply with quote

Yes, the partition with the swapfile has to be mounted first.

Probably the wrong way to solve this, but a way, would be to swapon your swapfile in /etc/local.d, with a delay if necessary, assuming your running openrc.

What's your use case for wanting a swapfile? If you need more swap, why not increase the size of your existing swap partition, or add another? Do you really use a lot of swap? Do you monitor it?
_________________
Andy Figueroa
hp pavilion hpe h8-1260t/2AB5; spinning rust x3
i7-2600 @ 3.40GHz; 16 gb; Radeon HD 7570
amd64/23.0/split-usr/desktop (stable), OpenRC, -systemd -pulseaudio -uefi
Back to top
View user's profile Send private message
Frautoincnam
Guru
Guru


Joined: 19 May 2017
Posts: 324

PostPosted: Thu Jul 15, 2021 6:37 pm    Post subject: Reply with quote

figueroa wrote:
What's your use case for wanting a swapfile?

I need swap for 1) hibernate 2) compile because I can't have more RAM (gcc, mysql)

Code:
If you need more swap, why not increase the size of your existing swap partition,

Not enough space. It's a small SSD (116GB).

Code:
or add another?

that's finaly what I did. I resized my /dev/sd5, to create a swap partition. But it's less flexible than a swapfile, so I add to create a bigger one than the swap file.

Quote:
Do you really use a lot of swap?

Rarely, but sometimes. Of course, in that case I can mount it manualy, except if I forget to do it before starting emerge. And in that case, I spend a lot of time for nothing. I have to add swap, than restart emerge.
I wanted to automaticaly create that swapfile when emerging certain packages but never found a simple solution with portage. So I prefer to mount it at start.
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 22648

PostPosted: Fri Jul 16, 2021 2:09 am    Post subject: Reply with quote

As a tip, you should state under what init system you are operating. I had to chase down your old posts to see this is likely not a systemd system, and is therefore probably (but not necessarily) an openrc system.

Under openrc, /etc/init.d/swap is before localmount, so you cannot normally enable a swap file on a filesystem that is mounted by localmount, because it will not be available. You must override this ordering if you want to mount a swap file from such a filesystem. I think most people who use swap files put them on the root, so the init script does not handle this case.

As an aside, why are your filesystems ext3?
Back to top
View user's profile Send private message
Frautoincnam
Guru
Guru


Joined: 19 May 2017
Posts: 324

PostPosted: Fri Jul 16, 2021 2:41 am    Post subject: Reply with quote

Hu wrote:
As a tip, you should state under what init system you are operating. I had to chase down your old posts to see this is likely not a systemd system, and is therefore probably (but not necessarily) an openrc system.


You're right, sorry.

Quote:
Under openrc, /etc/init.d/swap is before localmount, so you cannot normally enable a swap file on a filesystem that is mounted by localmount, because it will not be available. You must override this ordering if you want to mount a swap file from such a filesystem.

It makes sense, I should have thought about it.

Quote:
As an aside, why are your filesystems ext3?

For the HD, it is just because that's a very old disk and at the time, I didn't dare to use ext4.
On the other hand, indeed I see that my root is in ext3 in fstab, whereas it is mounted in ext4.
Code:
$ grep sdb1 /etc/fstab
/dev/sdb1               /               ext3            noatime,user_xattr      0 1
$ mount | grep sdb1
/dev/sdb1 on / type ext4 (rw,noatime)

probably an error (corrected) on my part in fstab. As it is formatted in ext4, it is therefore correctly mounted, regardless of the fstab option.
Back to top
View user's profile Send private message
netsplit
n00b
n00b


Joined: 10 Jun 2024
Posts: 6

PostPosted: Thu Aug 01, 2024 4:39 pm    Post subject: Reply with quote

Had the same issue. This thread gave me the insight to fix it for myself. Documenting in case it helps someone else who finds this thread.

In my case:

the swapfile is a on a partition mounted at /home:

Code:
sudo rc-update add swap default
sudo rc-update del swap boot


This fixed the issue, as stated above the swap partition wasn't mounted, so moving the swap service to a later in boot runlevel worked. Deleting swap from boot is required because it won't start the service twice.

Note: I speak with the confidence only someone on the wrong side of the Dunning-Krueger affect could have. Specifically the swap service being on the boot runlevel is probably for a very good reason that I'm not privy to. So this fix could case problems. I don't know.
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1918

PostPosted: Thu Aug 01, 2024 4:43 pm    Post subject: Reply with quote

netsplit wrote:
the swapfile is a on a partition mounted at /home:

Code:
sudo rc-update add swap default
sudo rc-update del swap boot

A better solution is to edit /etc/conf.d/swap and remove the comments to what applies to you:
Code:
# If you are only using local swap partitions, you should not change
# this file. Otherwise, you need to uncomment the below rc_before line
# followed by the appropriate rc_need line.
#rc_before="!localmount"
#
# If you are using swap files stored on local file systems, uncomment
# this line.
#rc_need="localmount"
#
# If you are using swap files stored on network file systems or swap
# partitions stored on network block devices such as iSCSI, uncomment
# this line.
#rc_need="netmount"
In the example quoted in this post, it would be the rc_before and the first rc_need
Back to top
View user's profile Send private message
netsplit
n00b
n00b


Joined: 10 Jun 2024
Posts: 6

PostPosted: Fri Aug 02, 2024 9:17 pm    Post subject: Reply with quote

grknight wrote:
netsplit wrote:
the swapfile is a on a partition mounted at /home:

Code:
sudo rc-update add swap default
sudo rc-update del swap boot

A better solution is to edit /etc/conf.d/swap and remove the comments to what applies to you:
Code:
# If you are only using local swap partitions, you should not change
# this file. Otherwise, you need to uncomment the below rc_before line
# followed by the appropriate rc_need line.
#rc_before="!localmount"
#
# If you are using swap files stored on local file systems, uncomment
# this line.
#rc_need="localmount"
#
# If you are using swap files stored on network file systems or swap
# partitions stored on network block devices such as iSCSI, uncomment
# this line.
#rc_need="netmount"
In the example quoted in this post, it would be the rc_before and the first rc_need


Thanks! Was doing a long build but it finished, I tried that change and it works great!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum