Showing posts with label swap. Show all posts
Showing posts with label swap. Show all posts

Friday, May 23, 2008

Enabling Hibernate on Linux

Yesterday, I was thinking to enable hibernate on
my HP-Compaq nc-6400 laptop.
Some prerequisites for enabling hibernate on Linux:

(i). ACPI should be enabled in Linux kernel.
I have compiled kernel 2.6.22.6

(ii) Go to KDE Control Center > Power Control
> Laptop Battery. Then select 'ACPI Config',
click 'Setup Helper Application'. If ACPI
is supported on your PC, you can see that
check boxes are enabled.

(iii) kpowersaved daemon should be installed.

(iv) You should have swap partition >= RAM on your
PC.

I did not have the swap partition. :( Then I thought
to create it. Because swap file cannot act as resume
device. i.e. At the boot time kernel should know the
resume device before file system.

How did I create swap partition? Following are the
steps:

(a) I created 1 GB partition /dev/sda3 from /dev/sda2
using gparted.

(b) I formatted it and made swap.

# mkswap /dev/sda3

(c) To mount it (as swap) automatically at boot time,
it created following entry in /etc/fstab.

/dev/sda3 swap swap defaults 0 0

(d) I then modified /boot/grub/menu.lst , to make /dev/sda3
as resume device.

I changed booting kernel line from
kernel /boot/vmlinuz-2.6.22.6 root=/dev/sda1 ro
to
kernel /boot/vmlinuz-2.6.22.6 root=/dev/sda1 ro resume=/dev/sda3

(e) Then I rebooted the kernel with resume device. Now I
can hibernate (Suspend to disk) my laptop, using kpowersave
available in KDE tray.

Monday, March 31, 2008

Dynamic Swap on File

1. Create a 500MB swap file.

$ dd if=/dev/zero of=/mnt/WinD/Swap500M bs=1024 count=500000
$ mkswap /mnt/WinD/Swap500M



2. Change variables according to your configuration (or liking) in
the following Shell script (my_swapon.sh).

#!/bin/sh

## Turns on swap ##

SWAP_PARTITION="/mnt/WinD"
SWAP_DEV="$SWAP_PARTITION/Swap500M"
if [[ -e $SWAP_DEV ]]
then
echo "$SWAP_DEV is already mounted."
else
mount $SWAP_PARTITION
fi

IS_ON=`grep -c $SWAP_DEV /proc/swaps`

if [ $IS_ON -eq 1 ]
then
echo "$SWAP_DEV is already turned on."
else
swapon $SWAP_DEV
fi


3. Run this script as root user whenever you want to
use extra swap space. (Above steps 1 and 2, need
to be done only once).

$ sudo ./my_swapon.sh