Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved] Prevent restore of hibernation image
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
paddlaren
Tux's lil' helper
Tux's lil' helper


Joined: 23 Nov 2005
Posts: 125
Location: Hörby, Sweden

PostPosted: Tue Jan 30, 2024 12:26 pm    Post subject: [Solved] Prevent restore of hibernation image Reply with quote

I just messed up a production SSD because Linux restored an old and obsolete hibernation image from swap. I hibernate to swap, not to a file.

The scenario is this; I have a laptop running Gentoo on BTRFS in a LUKS container. I put it into hibernation as usual with no plans to remove the disks. Later the disk is anyway removed and mounted from another Linux where changes are made. The hibernated information is now out of date both on LUKS and BTRFS levels. When I put the disk back into the device it loads the hibernation image and things go south very fast.

I need to find a way to prevent this in the future. With OpenRC I can just remove the "resume=" option and possibly the swap drive reference. It should no longer restore the hibernation image.

With later systemd (>=255 according to ArchLinux wiki) the reference to the hibernation image is stored into volatile ram and the "resume=" kernel option is ignored. For this scenario I need a kernel option or so to just ignore any existing hibernation images and references to them. Anyone know of a kernel option or any other means to ignore the hibernation image?

Thanks,
Erik


Last edited by paddlaren on Wed Jan 31, 2024 10:24 am; edited 1 time in total
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3345
Location: Rasi, Finland

PostPosted: Tue Jan 30, 2024 12:50 pm    Post subject: Re: Prevent restore of hibernation image Reply with quote

paddlaren wrote:
With later systemd (>=255 according to ArchLinux wiki) the reference to the hibernation image is stored into volatile ram and the "resume=" kernel option is ignored. For this scenario I need a kernel option or so to just ignore any existing hibernation images and references to them. Anyone know of a kernel option or any other means to ignore the hibernation image?
This sounds like systemd/dracut handles the hibernation restore. That means it happens in user-space, in iniramfs. If you use dracut, you can then remove the 'resume' module from dracut's configuration.
I don't use systemd or dracut on my machines at the moment, so I cannot guarantee this working.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
paddlaren
Tux's lil' helper
Tux's lil' helper


Joined: 23 Nov 2005
Posts: 125
Location: Hörby, Sweden

PostPosted: Tue Jan 30, 2024 7:06 pm    Post subject: Reply with quote

Quote:
If you use dracut, you can then remove the 'resume' module from dracut's configuration.


Problem is that I need to be able to do a one time special operation before booting the computer - if it boots it will resume from hibernation and mess up things. That why I seek a kernel/system option or similar.

I can boot from an USB and recreate the swap as well but then the UUIDs will change and I need to change fstab etc. This is also not a one time simple operation.


Most likely I will abandon my systemd efforts here and stick with OpenRC Gentoo instead and things will work out as they always do or I can make them. Systemd is quite automagic and that never seems to works for me.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21635

PostPosted: Tue Jan 30, 2024 7:47 pm    Post subject: Reply with quote

Is the swap device inside a LUKS container or directly on the drive? Generally, if you care about encrypting anything on the drive, you should also encrypt the hibernation storage. If the hibernation storage is encrypted, then you can avert this problem by refusing to provide the proper LUKS password when the system requests it as a prerequisite to resuming.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3137

PostPosted: Tue Jan 30, 2024 8:49 pm    Post subject: Reply with quote

Quote:
I put it into hibernation as usual with no plans to remove the disks. Later the disk is anyway removed and mounted from another Linux where changes are made.
The missing step is: clear hibernation image with mkswap.

Since you hibernate and then modify disk image, I assume those 2 steps are separated in time, because otherwise you'd just shutdown instead of hibernating. Which makes it likely that the next boot will be delayed as well.
If you disable hibernation during that delayed boot, you're likely to forget you were meant to do that.

TBH I don't understand why are you even using hibernation on a production machine, this thing exists to make workstation users' lives easier, so I'd suggest you just ditch this feature completely (I think you can disable support for suspend2disk in kernel config), but if you really want to use it, destroy the resume image at the same time you're making it useless.
Bear in mind that a swap partition hosting a hibernation image is no longer tagged as swap. The marker is restored after resume.
_________________
Make Computing Fun Again
Back to top
View user's profile Send private message
sublogic
Apprentice
Apprentice


Joined: 21 Mar 2022
Posts: 222
Location: Pennsylvania, USA

PostPosted: Tue Jan 30, 2024 10:32 pm    Post subject: Re: Prevent restore of hibernation image Reply with quote

paddlaren wrote:
With later systemd (>=255 according to ArchLinux wiki) the reference to the hibernation image is stored into volatile ram and the "resume=" kernel option is ignored. For this scenario I need a kernel option or so to just ignore any existing hibernation images and references to them. Anyone know of a kernel option or any other means to ignore the hibernation image?

There is also a noresume kernel option. Does that take precedence over the systemd mechanism ?
Back to top
View user's profile Send private message
sublogic
Apprentice
Apprentice


Joined: 21 Mar 2022
Posts: 222
Location: Pennsylvania, USA

PostPosted: Tue Jan 30, 2024 10:44 pm    Post subject: Reply with quote

szatox wrote:
TBH I don't understand why are you even using hibernation on a production machine, this thing exists to make workstation users' lives easier, so I'd suggest you just ditch this feature completely

Yes, but see the first FAQ in the kernel documentation, https://docs.kernel.org/power/swsusp.html?highlight=Frequently%20Asked%20Questions (scroll down).
Just saying.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3137

PostPosted: Wed Jan 31, 2024 12:05 am    Post subject: Reply with quote

sublogic wrote:

Yes, but see the first FAQ in the kernel documentation, https://docs.kernel.org/power/swsusp.html?highlight=Frequently%20Asked%20Questions (scroll down).
Just saying.
Sure.
Quote:
You bought new UPS for your server. How do you install it without bringing machine down? Suspend to disk, rearrange power cables, resume.

Suspend to disk also brings the machine down, so whatever. If it's a critical piece of equipment, have it's twin take over, and if it's not critical, just schedule maintenance window and shut it down.
Quote:
You have your server on UPS. Power died, and UPS is indicating 30 seconds to failure. What do you do? Suspend to disk.

Like above, failover to its tween or service goes down either way.
I suggest getting a properly sized UPS, then I suggest removing non-critical equipment from UPS, and I close the incident with nothing done because accountants are stingy and managers afraid. Also, this meeting could have been an email.
What's your point?

Servers and workstations are used in different ways and should be handled in different ways. If the OP does actually have a valid reason to use hibernation, I have neither way nor intention to stop him.
However, there's a good chance that things are the way they are because they have always been this way, and getting rid of a self-destruct hair-trigger is the easiest way to not accidentally triggering self-destruction.
_________________
Make Computing Fun Again
Back to top
View user's profile Send private message
paddlaren
Tux's lil' helper
Tux's lil' helper


Joined: 23 Nov 2005
Posts: 125
Location: Hörby, Sweden

PostPosted: Wed Jan 31, 2024 10:24 am    Post subject: Reply with quote

sublogic wrote:
There is also a noresume kernel option. Does that take precedence over the systemd mechanism ?

This is the option I was seeking for. Thanks. Did not mange to find it documented anywhere.

szatox wrote:
TBH I don't understand why are you even using hibernation on a production machine

Simple. This is my working laptop. Since a few years the sleep to ram seems to save no more power than just blank the screen and battery goes out after a few hours. Thus I need to put the device in hibernation or it will ran out of batteries during sleep.

I am not using sleep or hibernation on my server. I am however using sleep to RAM on my desktop machine that is also a working computer.

sublogic wrote:
Yes, but see the first FAQ in the kernel documentation, https://docs.kernel.org/power/swsusp.html?highlight=Frequently%20Asked%20Questions

This is exactly what happened. Actually I was amazed that I was able to restore from hibernation. Then I made a snapshot of root and started upgrade gentoo and things went south very fast....

Lucky thing I already had a copy of all important information, just missing the working gentoo installation.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo 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