Tag Archives: Red Hat

Resize swap partitions on Red Hat Linux

First of all a little disclaimer - although I've done this a few times and never had any problems, one should never consider resizing partitions a completely foolproof exercise. Things can go wrong. With regards to swap though, don't worry if your swap partition is destroyed as this will not harm your system - most healthy systems will not ever need swap and unlike Windows, Linux only starts using swap when it needs it and can quite easily survive without it. You can trash it and format it as many times as you like as long as it's not in use. And of course take backups of any important data first!

Resize swap partition in Red Hat Linux

  • Is your swap on a logical volume (LVM)? If so then skip below to the LVM section. If not then read on:
  • Download gparted (Gnome Partition Manager), burn the iso and then boot into it.
  • Gparted will identify the filesystems on each partition so your target will be clearly labelled as swap.
  • Reize your partitions as required. Try to minimise the overall number of resize and move operations as this can take several hours to complete.

When you reboot swap not be enabled - if you check using top (or htop) or free -m, you will see 0 mb of swap available. The reason for this is the UUID of the partition changed when it was resized by GParted, and this confuses the system when it tries to mount the volumes in /etc/fstab. The solution is to relabel your swap partition, by reformatting it as swap and specifying the correct label.

fdisk -l | grep swap

Note down the device name of your swap partition. e.g:

/dev/cciss/c0d0p3 1926 3837 15358140 82 Linux swap

Make a note of the label for the swap partition from fstab:

cat /etc/fstab | grep swap

e.g.

LABEL=SW-cciss/c0d0p3 swap

Now format your partition as swap, specifiying the label exactly as shown in the fstab.

mkswap /dev/cciss/c0d0p3 -L SW-cciss/c0d0p3

You can then enable the swap space straight away by using swapon devicename, or just reboot and check with free -m again, and all should be ok.

Resizing swap on LVM
If your swap partition is on a logical volume it can be resized without rebooting your system. However you will need free space to extend into, if you do not have free space you will need to shrink another volume or add another physical disk into your volume group (see this post which explains how to do this).

cat /etc/fstab | grep swap
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0

lvdisplay will show you the size of your logical volume:

lvdisplay /dev/VolGroup00/LogVol01

--- Logical volume ---
LV Name                /dev/VolGroup00/LogVol01
VG Name                VolGroup00
LV UUID                RVIFz3-B8kp-z9KV-JYtG-N997-JOQ6-ETaJaJ
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                512.00 MB
Current LE             24
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           253:1

To resize an LVM you need to unmount it, or in this case swapoff.

swapoff /dev/VolGroup00/LogVol01

Resizing the volume to 768Mb (assuming you have the space to extend into)

lvresize /dev/VolGroup00/LogVol01 -L 768M
Extending logical volume LogVol01 to 768.00 MB
Logical volume LogVol01 successfully resized

swapon /dev/VolGroup00/LogVol01
free -m
total       used       free     shared    buffers     cached
Mem:           375        343         32          0         48        120
-/+ buffers/cache:        174        201
Swap:          767          0        767

Red Hat Summit 2008 – closing post

In short - it's been good, a valuable use of my time. The presentation throughout the summit was of a very high standard, and this included the catering too.

If I had to summarise the summit I would do so using the following 5 buzzwords:

1. Virtualisation. Guess what ...? Red Hat has their own virtualisation product. It looks very promising but if I am brutally honest (and Red Hat would kill me for saying this), they are pretty much in the same boat as Microsoft. By that I mean they are leagues behind what VMWare are offering right now. But it wasn't just Red Hat banging on about virtualisation. All the vendors in the exhibition hall were touting their products with the big V in mind.

2. Green/Energy saving. Everyone is working towards making their products consume less energy, while giving the user much more back. Red Hat and intel are working towards more closely unifying hardware and software, so that their OS can have much greater control of how much power a device on the system should consume.

3. Cloud computing. Everyone was talking about this. Offload your computing power to other computers in the cloud when you have extreme amounts of processing to do. It's a bit like clustering except you only dip into the cloud when you need to, and the computers in the cloud don't have to be on your network.

4. Red Hat Satellite. A lot of the speakers talked about how they use Satellite to administer their Red Hat servers. And of course there was the big announcement about Spacewalk.

5. Open Source. Red Hat love talking about it and they are very proud about being open source. They even talked about the importance of CentOS and Ubuntu, which surprised me! Moreover, I was astonished that CentOS will be a supported product by Spacewalk. When questioned about Ubuntu, the reply was Ubuntu is not a rival of Red Hat ... as it's going to take more than one player to topple Microsoft!

I'm off home now, but first I'm due a visit to the duty free shop for an extremely large bottle of whisky. Thank you very much HP (but sorry, I'm not keeping the t-shirt) :)