View previous topic :: View next topic |
Author |
Message |
Frautoincnam Guru
Joined: 19 May 2017 Posts: 324
|
Posted: Wed Jul 14, 2021 2:19 pm Post subject: swapfile not on / not mouted at start |
|
|
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 |
|
|
figueroa Advocate
Joined: 14 Aug 2005 Posts: 3005 Location: Edge of marsh USA
|
Posted: Thu Jul 15, 2021 5:20 am Post subject: |
|
|
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 |
|
|
Frautoincnam Guru
Joined: 19 May 2017 Posts: 324
|
Posted: Thu Jul 15, 2021 6:37 pm Post subject: |
|
|
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).
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 |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 22618
|
Posted: Fri Jul 16, 2021 2:09 am Post subject: |
|
|
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 |
|
|
Frautoincnam Guru
Joined: 19 May 2017 Posts: 324
|
Posted: Fri Jul 16, 2021 2:41 am Post subject: |
|
|
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 |
|
|
netsplit n00b
Joined: 10 Jun 2024 Posts: 6
|
Posted: Thu Aug 01, 2024 4:39 pm Post subject: |
|
|
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 |
|
|
grknight Retired Dev
Joined: 20 Feb 2015 Posts: 1909
|
Posted: Thu Aug 01, 2024 4:43 pm Post subject: |
|
|
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 |
|
|
netsplit n00b
Joined: 10 Jun 2024 Posts: 6
|
Posted: Fri Aug 02, 2024 9:17 pm Post subject: |
|
|
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 |
|
|
|
|
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
|
|