[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
howtos:slackware_admin:swapfile_hibernation [2012/12/01 13:31 (UTC)] – [Sources] fl0howtos:slackware_admin:swapfile_hibernation [2012/12/01 20:32 (UTC)] (current) – Syntax cleanup sycamorex
Line 2: Line 2:
 ====== Hibernation with LVM, LUKS and a Swapfile  ====== ====== Hibernation with LVM, LUKS and a Swapfile  ======
  
-With this How To you can use a swapfile instead a swap partition as described here: +With this How To you can use a swap file instead a swap partition as described [[http://slackware.osuosl.org/slackware-14.0/README_CRYPT.TXT|here]].
-[[http://slackware.osuosl.org/slackware-14.0/README_CRYPT.TXT]]+
  
-First create a swapfile: (you can choose another name and / or size if you want)+First create a swap file (you can choose another name and / or size if you want):
  
   dd if=/dev/zero of=/swapfile bs=1M count=4096   dd if=/dev/zero of=/swapfile bs=1M count=4096
   mkswap /swapfile    mkswap /swapfile 
  
-Activate the Swap:+Activate the swap:
   swapon /swapfile   swapon /swapfile
  
-Check if the Swapfile is recognized by the system:+Check if the swap file is recognized by the system:
   cat /proc/swaps    cat /proc/swaps 
   Filename                                Type            Size    Used    Priority   Filename                                Type            Size    Used    Priority
Line 22: Line 21:
  
  
-For suspend/resume you need to append 2 kernel Parameter in /etc/lilo.conf resume and resume_offset.+For suspend/resume you need to append 2 kernel parameter in /etc/lilo.conf resume and resume_offset.
  
-resume is the partition where the swapfile is located (e.g /dev/sda, /dev/cryptslack/root) +''resume'' is the partition where the swap file is located (e.g /dev/sda, /dev/cryptslack/root) 
-resume_offset is the beginning of the swapfile on the resume partition, you can get the offset with+''resume_offset'' is the beginning of the swap file on the resume partition, you can get the offset with:
   sudo /sbin/filefrag -v /swapfile | head -n -3 | tail -n 1 | awk ' {print $3 }'   sudo /sbin/filefrag -v /swapfile | head -n -3 | tail -n 1 | awk ' {print $3 }'
  
-your lilo entry should look like this:+Your ''lilo'' entry should look like this:
   # Append any additional kernel parameters:   # Append any additional kernel parameters:
    append="vt.default_utf8=1 resume=/dev/cryptslack/root resume_offset=1134591"    append="vt.default_utf8=1 resume=/dev/cryptslack/root resume_offset=1134591"
  
-    
 You need to patch the initrd to recognize the resume_offset parameter You need to patch the initrd to recognize the resume_offset parameter
 +<file patch init-swapfile.patch>
 +--- init.orig   2012-12-01 14:03:39.344538490 +0100                                                                                                            
 ++++ init        2012-12-01 14:01:12.526373970 +0100                                                                                                            
 +@@ -69,6 +69,7 @@                                                                                                                                              
 + LUKSDEV=$(cat /luksdev)                                                                                                                                       
 + LUKSKEY=$(cat /lukskey)                                                                                                                                       
 + RESUMEDEV=$(cat /resumedev)                                                                                                                                   
 ++RESOFFSET=$(cat /resoffset)                                                                                                                                   
 + WAIT=$(cat /wait-for-root)                                                                                                                                    
 + KEYMAP=$(cat /keymap)                                                                                                                                         
 + INIT=/sbin/init                                                                                                                                               
 +@@ -269,18 +270,35 @@
 +     umount -l /mountkey
 +     rmdir /mountkey 2>/dev/null
 +   fi
 +-  
 +-  # Resume state from swap
 +-  if [ "$RESUMEDEV" != "" ]; then
 +-    if ls -l $RESUMEDEV | grep -q "^l" ; then
 +-      #RESUMEDEV=$(ls -l $RESUMEDEV | awk '{ print $NF }')
 +-      RESUMEDEV=$(readlink -f $RESUMEDEV)
 +-    fi
 +-    echo "Trying to resume from $RESUMEDEV"
 +-    RESMAJMIN=$(ls -l $RESUMEDEV | tr , : | awk '{ print $5$6 }')
 +-    echo $RESMAJMIN > /sys/power/resume
 +-  fi
 +-
 +
 ++if [ "$RESUMEDEV" != "" ]; then
 ++       # be lvm aware
 ++        RESUMEDEV=$(readlink -f ${RESUMEDEV} | awk -F '/' '{ print $3 }')
 ++       if [ -r "/sys/class/block/${RESUMEDEV}/dev" ] ; then
 ++       # try sysfs 
 ++               read RESMAJMIN < "/sys/class/block/${RESUMEDEV}/dev"
 ++       elif [ -r "/proc/partitions" ] ; then
 ++       # otherwise run through /proc/partitions
 ++               while read m n b d jnk ; do
 ++                       if [ "$d" = "${RESUMEDEV}" ] ; then
 ++                               RESMAJMIN="$m:$n"
 ++                               break
 ++                       fi
 ++               done < "/proc/partitions"
 ++               fi
 ++       if [ -z "${RESMAJMIN}" ] ; then
 ++               # Device does not exist (not found in /proc/partitions)
 ++               exit 99
 ++       fi
 ++
 ++       if [ -n "${RESOFFSET}" ]; then
 ++                echo "Try resume from ${RESMAJMIN}:${RESOFFSET}"
 ++               echo "${RESMAJMIN}:${RESOFFSET}" > /sys/power/resume
 ++       else
 ++               echo "${RESMAJMIN}" > /sys/power/resume
 ++       fi
 ++fi
 +
 +</file>
  
   mkdir patched_initrd   mkdir patched_initrd
Line 41: Line 96:
   patch < init-swapfile.patch   patch < init-swapfile.patch
  
-after successfull patching ,pack the initrd to /boot/initrd-swapfile.gz +After successful patching, pack the initrd to ''/boot/initrd-swapfile.gz'':
  
   find . -print0 | cpio -ov -0 --format=newc | gzip -9 > /boot/initrd-swapfile.gz   find . -print0 | cpio -ov -0 --format=newc | gzip -9 > /boot/initrd-swapfile.gz
  
-<note>recommend you to test this initrd first with another bootentry</note>+<note>recommend to test this initrd first with another boot entry</note>
   image = /boot/vmlinuz   image = /boot/vmlinuz
   initrd = /boot/initrd-swapfile.gz   initrd = /boot/initrd-swapfile.gz
Line 53: Line 108:
  
  
-then you need to run lilo to save the changes+Then you need to run lilo to save the changes
   lilo   lilo
  
-after a reboot you can suspend to your swapfile as with your swap partition  +After a reboot you can suspend to your swap file as with your swap partition  
-<note>you need the reboot, suspend also uses resume_offset to find the swapfile</note>+<note>You need the reboot, suspend also uses resume_offset to find the swap file</note>
    
 ====== Sources ====== ====== Sources ======
-Arch Linux Wiki: [[https://wiki.archlinux.org/index.php/Swap]]+  * [[https://wiki.archlinux.org/index.php/Swap]]
  
-* Originally written by [[wiki:user:fl0]]+  * [[https://answers.launchpad.net/ubuntu/+source/initramfs-tools/+question/193862]] 
 + 
 + 
 +  * Originally written by [[wiki:user:fl0]]
  
 <!-- If you are copying information from another source, then specify that source --> <!-- If you are copying information from another source, then specify that source -->
 howtos:slackware_admin:swapfile_hibernation ()