Suspend to disk

750 views
Skip to first unread message

Mexus

unread,
Jun 5, 2016, 3:11:53 PM6/5/16
to Android-x86
Hello,

i am searching for solution how to suspend android to disk. 

According to documentation this should be available using

echo disk > /sys/power/state

and then booting with kernel parameter

resume=<path to swap file>

but looks like this option is depended on /sys/power/disk file which is missing in 4.4-r5

I tried to create swap

mkswap <filename>
swapon <filename>

which worked ok. But from there i am kinda lost. 

Do i have to compile android with this option? Which would not be a problem to compile if i have a clue how to enable it in first place. 

Thanks for any hint. 

Mexus

unread,
Jun 8, 2016, 2:08:44 PM6/8/16
to Android-x86
So i was able to suspend to disk by enabling this feature in kernel config

kernel/arch/x86/configs/android-x86_defconfig > CONFIG_HIBERNATION=y

then enabling swap partition

busybox mkswap /dev/block/sda2
busybox swapon /dev/block/sda2

adding resume partition as kernel parameter in menu.lst

resume=/dev/sda2 (without the "block")

and finally putting system to suspend

echo disk > /sys/power/state

All seems to work fine except the resume is weird. The system will resume ok but goes into sleep right after. When i wake it up using any keyboard key all is ok. 

From what i read this could be caused by /sys/power/autosleep, which should hold the value "mem" which is causing the system to go to sleep right after resume. But i am not sure about it because i can't read the value because all happen so fast. 

Anyways i will keep experimenting :)

Thisara Kasun

unread,
Jun 8, 2016, 9:22:30 PM6/8/16
to Android-x86
Good finiding!

I wish this was in the default build. Did you manage to set the swap file permanently? any changes to fstab?

Mexus

unread,
Jun 9, 2016, 7:35:36 AM6/9/16
to Android-x86
yeah i was able to make it permanent by adding the swap commands to /etc/init.sh before the last "return 0" line

busybox mkswap /dev/block/sda2
busybox swapon /dev/block/sda2

if you omit the "busybox" command system will use mkswap and swapon commands from /system/bin (not /system/xbin) and mentioned commands from this directory are working with swapping to a file and not to a block device. 
you can of course also use a file as a swap place but i would not recommend it because this file needs to be contiguous on disk (maybe not an issue after all ) and also the commands require you to first create an empty file with desired size (using dd or similar tool) and only after that you may use the mkswap and swapon commands. 

also you may use /etc/fstab to specify swap device. (if there is no such file simply create it) and add an entry

/dev/block/sda2       swap         swap      defaults

This way you only need to issue command

busybox swapon -a

and it will look into your fstab and mount the swap device. 
but for me it was simpler to use the method without involving fstab. 

also what i found interesting is if you hibernate your device and somehow you perform a cold boot (not with resume=... kernel parameter) the system won't allow you to use swap device anymore unless you format it again using mkswap command. 
Thats why i put both command mkswap and swapon to the init.sh. Just to make sure it will always mount. 

Mexus

unread,
Jun 9, 2016, 4:57:45 PM6/9/16
to Android-x86
Still not sure whats causing the immediate sleep after resume. It is not the autosleep value as i thought. This value stays off all the time. Looking at logs there is nothing about the trigger. It just log the message "preparing to sleep" right after the resume and that's all. 

I was able to disable the sleep function in kernel as a workaround. (sleep is not important for what i need so i can scratch that out)
But still not quite there because even the system won't go to sleep it will put display to sleep instead :D
So i have to move with mouse or press any key to wake it up. And so far i was not able to disable this display sleep function :/ 
From logs it seems like an ACPI display sleep function but even when i disabled this in kernel it still works. Somehow... 
Reply all
Reply to author
Forward
0 new messages