How To: Remove or resize the swap partition in Linux

Discussion in 'Linux' started by mulras, Feb 27, 2009.

  1. mulras

    mulras

    Joined:
    Feb 17, 2009
    Messages:
    3
    Likes Received:
    0
    Hi,

    I know there have been loads of posts about the swap partition, but I thought I would write the procedure that I used down in an easy to follow format. I'm not saying this is the right way to do it, i'm no Linux expert, but it worked for me! :)

    Bear in mind that this is a potentially damaging operation. I recommend backing up first!

    Firstly, I used a Fedora 10 Live USB stick as I had one to hand. If you don't have one, you can get the Fedora liveusb-creator utility here https://fedorahosted.org/liveusb-creator/

    When you make a Fedora USB stick, be sure to add a small amount of persistent storage. Now that the USB stick is ready, we can start the procedure;

    Firstly, disable swap partition currently active. From a terminal (Alt + F2, xfterm4) type the following command;

    Code:
    sudo swapoff -a
    The swap partition is now deactivated, but will reappear on reboot. To disable it on reboot you need to edit the file /etc/fstab as follows;

    Code:
    sudo mousepad /etc/fstab
    The last line in the file should read as follows;

    /dev/sda2 swap swap defaults 0 0

    Place a # at the start of the line and save the file. You can now reboot and test that all is ok. If you hit Ctrl + Alt + Del, the resources tab on the system monitor should show that the swap file is "0 bytes of 0 bytes".

    Boot the machine using the Fedora USB stick (F12) and log into Fedora. It should automatically see your wireless card, so connect it up as we will need to add a package to the USB stick. Open a command line and install "gparted" as follows;

    Code:
    su
    yum install gparted
    You need to use the su command to become root as the sudo file is empty on the USB stick.
    This should now install gparted and you should have an icon for it on the system menu. Start it up and you should see the following;

    [​IMG]

    Select the second partition (yours will be swap rather than unallocated) and delete it. Then select the remaining partition and hit the "Resize/Move" button;

    [​IMG]

    Change the partition size so that it uses all avaliable space as follows;

    [​IMG]

    No changes have been made yet, so if you think it is wrong, don't panic just quit out and start again. If everything looks good, click "Edit" and "Apply All Operations";

    [​IMG]

    You will be asked if you are sure, click "Apply" to commit the actions. This then resizes the disk and may take a little while... Once done, you should see the following;

    [​IMG]

    Now reboot and you are done! Check your free space, it should reflect the extra saving from the swap partition.

    If you are a little worried about the lack of swap, I created a swap file rather than a partition. This way it's easy to change on the fly and I can remove it when my memory upgrade arrives :D

    You can do this using the following procedure;

    Decide the size of your new swap file in megabytes and multiply the number by 1024 to determine the number of blocks required to create the file. For example, the block size of a 64 MB swap file is 65536. My swap is going to be 256MB so I will be setting the block size to 262144.

    In a terminal, type the following command with the count value being equal to the desired block size; (takes a little while to finish)

    Code:
    sudo dd if=/dev/zero of=/swapfile bs=1024 count=262144
    You can check it's there by typing the following in the terminal;

    Code:
    ls / -alh
    You should be able to see "swapfile" with a size of 256MB

    Setup the file as a system swap file with the command;

    Code:
    sudo mkswap /swapfile
    To enable the swap file immediately but not automatically at boot time type the following;

    Code:
    sudo swapon /swapfile
    To enable it at boot time, edit /etc/fstab again and replace "#/dev/sda2" with "/swapfile"

    All done. :)
     
    mulras, Feb 27, 2009
    #1
  2. mulras

    Darryl

    Joined:
    Sep 1, 2008
    Messages:
    308
    Likes Received:
    0
    You absolute beauty!
    My A1 is now complete. Worked like a dream 1st time :D :D :D :D :D :D :D :D :D :D :D :D
    Thank you
    D
     
    Darryl, Feb 28, 2009
    #2
  3. mulras

    Guest Guest

    Worked well ;)
     
    Guest, Mar 4, 2009
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.