2

I'm attempting to increase the amount of swap on a xen guest machine. At first I thought it'd be similar to increasing the hard drive space, which I do like this:

cd /srv/xen/domains/$host/
xm shutdown $host
cp disk.img disk.img.backup
dd if=/dev/zero of=ZeroContentFile bs=1024 count=$numberofextrabytes
cat ZeroContentFile >> disk.img
rm ZeroContentFile
resize2fs -f disk.img
fsck.ext3 disk.img
xm create $host.cfg

I've tried doing the same thing, but replacing disk.img with swap.img. This works fine up until the point I do the resizefs -f swap.img, I get:

resize2fs 1.42.5 (29-Jul-2012)
resize2fs: Bad magic number in super-block while trying to open swap.img
Couldn't find valid filesystem superblock.

To be honest, I never expected this command to work exactly the same for swap as it did for ext3. However, if I leave it out, then the guest just ends up with the same amount of swap as it had before. What's the equivalent command I need to run to get the whole of swap.img recognised as swap space?

lucas
  • 200
  • 3
  • 10

1 Answers1

3

You can't use the EXT tools because swap is not an EXT file-system. Resize the disk image from the host and then three simple steps in the guest typically:

swapoff
mkswap /dev/[swapdevice]
swapon

Which unloads the swap partition, formats it and then activates it again. [swapdevice] can be determined from /etc/fstab.

HBruijn
  • 72,524
  • 21
  • 127
  • 192
  • How do I know what [swapdevice] is meant to be? I also don't understand why I can increase the size of the ext3 partition fully on the host, but for the swap partition I need to log into the guest. Seems a bit inconsistent. Is there some fundamental difference between ext3 and swap which I don't understand? – lucas Dec 19 '14 at 21:40
  • For the record, this does work and the default [swapdevice] seems to be `xvda1` (atleast for my setup). I still don't understand why such a difference between ext3 and swap, but atleast it works. – lucas Dec 25 '15 at 00:12
  • Updated my answer – HBruijn Dec 25 '15 at 08:37