Need to move my swap partition to let my root partition grow. How?

26,930

Solution 1

The resizing operations won't cause any issues with the filesystem, but you may need to update your /etc/fstab to point at the new partition ID.

  1. use GParted as you've described.

  2. Find the updated UUID of the swap partition from the output of:

    sudo blkid

  3. edit /etc/fstab in the guest OS to have the new UUID in the line with a 'type' of 'swap'

That should do it.

Solution 2

Just delete the swap partition and use a swap file. To do this type: This example is for a 1GB swap file

dd if=/dev/zero of=/swapfile bs=1024 count=1048576
chmod 0600 /swapfile
mkswap /swapfile
swapon /swapfile

Be sure to tell the OS to stop using the swap partition before you delete it, like this.

swapoff /dev/nameOfCurrentSwap

And remove or comment out the line in fstab that points to it.

Then you have to enable the swap space at boot time, add this line in fstab:

/swapfile none swap sw 0 0
Share:
26,930

Related videos on Youtube

apelliciari
Author by

apelliciari

Updated on September 18, 2022

Comments

  • apelliciari
    apelliciari almost 2 years

    I have a Virtual Box Ubuntu guest and i need to have more space on my disk (actually it's 8 gb). I have already increased the space allocated for the VDI to 16 gb.

    Now with GParted Live i'm trying to expand my partition, but the swap blocks the expansion, as is in this image

    the situation now

    I'm going to do some move/resize to get the unallocated space near the /dev/sda1.

    The operations are these:

    future

    Now, if i do this, surely i will have problems with the next boot. What i have to do to fix that?

    • Admin
      Admin over 12 years
      You may not even need a swap when running Ubuntu in virtual box.
    • Admin
      Admin over 12 years
      what are the disadvantages of having swap on a file like albercuba said?
    • Admin
      Admin over 12 years
      None, swap on file is fine but you don't really need a swap that would enable you to suspend your RAM to disk - however you don't do that in virtual box. Try without (you can always assign a swap on file later if you feel like you need it).
  • apelliciari
    apelliciari over 12 years
    this worked, even without the edit to /etc/fstab; there was no line of type 'swap' in there and system booted successfully after the gparted operations
  • Matt
    Matt almost 9 years
    How can I direct the swap file to be on a specific storage device?
  • cardiff space man
    cardiff space man almost 9 years
    Interestingly, using this strategy I forgot to edit fstab and when I checked it later, the swap mount's UUID was already the same as what blkid showed. So I guess it's good to have the UUID's match, but depending on which OS you use it might track itself or depending on which Gparted version you use it might be kept in line by Gparted ?rising-tone-like-a-question?
  • Brett G
    Brett G almost 8 years
    @cardiffspaceman Actually I just did the same operation as OP... I checked my UUID before and after. Turns out that the UUID just didn't change.