Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO Hibernation with custom initrd, luks and swapfile
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
klz
n00b
n00b


Joined: 07 Jun 2011
Posts: 24

PostPosted: Sat Jun 01, 2013 1:38 pm    Post subject: HOWTO Hibernation with custom initrd, luks and swapfile Reply with quote

Hello,

It took me a while to figure out how to succesfully thaw (hibernate) from a swapfile on an encrypted root partition with a custom initramfs; i couldnt find a complete set of instructions anywhere.

The hard part was finding the instructions how to change the init file for the initramfs (i dont use genkernel).
This website was the key for me.

We need to get the Major:Minor of the blockdevice the swapfile resides on, and then echo this to /sys/power/resume

Here is the relevant part of my /usr/src/initramfs/init
Code:
#msg 'Getting the resume partition from kernel commandline options..'
for x in `cat /proc/cmdline`
    do
       case ${x} in
            resume=*) RESUMEDEV=${x#resume=} ;;
            *) continue ;;
       esac
    done
# Getting "dm-0" (the file the resumeparition links to, for me this is /dev/dm-0, and then stripping it of /dev/)
RESUMEDEV=$(readlink -f ${RESUMEDEV} | awk -F '/' '{ print $3 }')
#msg 'Getting Major/Minor number of resume device'
RESMAJMIN=$(cat /sys/class/block/${RESUMEDEV}/dev)


And then just before switchting root:
Code:
msg "Echo-ing $RESMAJMIN to /sys/power/resume (so we can thaw-hibernate)"
echo $RESMAJMIN > /sys/power/resume


My kernel line in grub:
Code:
kernel /boot/kernel-3.9.4-rev3 cryptdevice=/dev/sda5:root resume=/dev/mapper/root resume_offset=3115008

To get the resume_offset look at the link i posted above.

Hopefully this helps somebody ;)


Last edited by klz on Mon Jun 03, 2013 4:33 pm; edited 1 time in total
Back to top
View user's profile Send private message
SlashBeast
Moderator
Moderator


Joined: 23 May 2006
Posts: 2820

PostPosted: Sun Jun 02, 2013 7:34 am    Post subject: Reply with quote

Isn't the resume offset used only by kernel? I am pretty sure you don't have to parse it in script at all. I am almost 100% sure that I used swapfile and didn't needed to echo it.

also nice way to get the major:minor, I use stat %T %t and printf to convert it to decimal and not sure if I had reason to do it as-is.

anyway, why you parse the offset, you do echo it somewhere? I used tuxonice, uswsusp and swsusp for a long time, always with encrypted devices and quite often with swap files with no problems.
_________________
BitBucket -- better-initramfs to address many usecases and linux's limitations.
Back to top
View user's profile Send private message
klz
n00b
n00b


Joined: 07 Jun 2011
Posts: 24

PostPosted: Mon Jun 03, 2013 4:32 pm    Post subject: Reply with quote

Hehe yeah resume offset is indeed not needed in initrd, thats why the lines are commented out...
maybe i shouldve just deleted those lines (?)
actually i will delete this
Code:
# We dont seem to need to resume offset in ramfs/initrd having it on the kernel-cmdline is enough
#            resume_offset=*) RESOFFSET=${x#resume_offset=} ;; 

from the first post
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks 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