TechBlog
leaflet
#js1k entry finally complete - AsciiBrot1K:http://urlm.in/flii - from T-SQL to JavaScript and then down to just 1KB of hand-compressed code

Xen swap issues

Posted on 12 June, 2009 by maximinus in
Note: This is mostly for my own future reference, but I thought I'd post it here in case somebody else might find it useful.

The Problem
This website (and a few others I run, such as ShrinkThisLink, the free link shrinker) runs on a /Debian VPS, running on Xen.  It had a swap partition configured, but was not using it, and didn't seem to want to.  I found that different methods of getting partition information seemed to be returning conflicting information:
  • the VPS control panel stated that /dev/sda1 was a 1GB swap partition, and that /dev/sda2 was a 5GB ext3 partition
  • `fdisk -l` seemed to agree with the VPS control panel, but added that each drive "doesn't contain a valid partition table"
  • parted also seemed to agree with the VPS control panel
  • `df -h` listed /etc/sda1 as mounted on / and being 5GB
  • /etc/fstab listed /dev/sda1 as a 5GB ext3 partition to mount on /
  • `swapon -a`was returning "swapon: /dev/sda2: Invalid argument" - which seemed to state that /dev/sda2 was the swap partition
So, of those I tried, three methods suggested that sda1 was swap; three methods suggested that sda2 was swap.  With it being a dead heat, I wasn't willing to try anything such as running mkswap on either partition (not that I'd have tried it with any inconsistency at all).

The solution
It struck me that if I could determine the actual swap partition's UUID, I might be able to do something of use with it.  Running `blkid` provides a convenient list of partitions, their types and their UUIDs - so I looked for the partition listed as having TYPE="swap" (which was listed as /dev/sda1).

Armed with the swap partition's UUID, I modified the line of /etc/fstab relating to the swap partition - changing "/dev/sda2" to "UUID=" followed by the swap partition's UUID.  Once this change was saved, `swapon -a` returned with no errors, having successfully enabled the partition as swap.
No comments have been posted on this entry.
Post a comment:
Sorry, comments have been disabled.