Find the answer to your Linux question:
Results 1 to 6 of 6
Hi, is it possible to use a swap file instead of a swap partition? How can I do it with Ubuntu? thanks in advance...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2007
    Posts
    47

    Swap file


    Hi,
    is it possible to use a swap file instead of a swap partition? How can I do it with Ubuntu?
    thanks in advance

  2. #2
    oz
    oz is offline
    forum.guy
    Join Date
    May 2004
    Location
    arch linux
    Posts
    18,733
    I don't think so, but maybe someone else knows differently. Of course, if you have enough RAM, you don't need any SWAP at all.
    oz

  3. #3
    Linux Guru bigtomrodney's Avatar
    Join Date
    Nov 2004
    Location
    Ireland
    Posts
    6,133
    It's a long time since Linux used a swapfile rather than a partition. It was once possible but I don't think it is anymore with the current kernels.

    The real question is - Why? The partition will perform better than a file on top of a filesystem and the swap file would take up just as much space.

  4. #4
    Just Joined!
    Join Date
    Apr 2007
    Posts
    47
    Quote Originally Posted by bigtomrodney View Post
    It's a long time since Linux used a swapfile rather than a partition. It was once possible but I don't think it is anymore with the current kernels.

    The real question is - Why? The partition will perform better than a file on top of a filesystem and the swap file would take up just as much space.
    I would like to use the swap partition for /tmp. I have four primary partitions:

    /, /home, swap and a partition for testing distros. My problem is that I hate logical partitions.
    Since Freespire did it (the swap file is in the /boot) is technically feasible.

    Of course the easy solution is to buy more ram.

  5. #5
    Linux Engineer rcgreen's Avatar
    Join Date
    May 2006
    Location
    the hills
    Posts
    1,134
    Assuming you want to put it in “/”, Create an empty 500MB file
    $ sudo dd if=/dev/zero of=/swap.img bs=1024k count=512

    Format it as a swap file
    $ sudo mkswap /swap.img

    Add it to your running Linux system
    $ sudo swapon /swap.img

    Optionally you can add /swap.img to fstab for automatic swap activation.

    $ sudo gedit /etc/fstab

    Add this line at the end of the file
    /swap.img none swap sw 0 0

    Run “free -m” command to verify that you’ve added the newly created swap to your Linux based operating system.

    Hope that helps!
    How to add Linux Swap file if you don’t have Swap Partition : mypapit gnu/linux blog

  6. #6
    Just Joined!
    Join Date
    Apr 2007
    Posts
    47
    That's a great hint, thank you. Just done it and works well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •