16

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?

3
  • 1
    You may not even need a swap when running Ubuntu in virtual box.
    – Takkat
    Oct 23, 2011 at 16:49
  • 1
    what are the disadvantages of having swap on a file like albercuba said? Oct 23, 2011 at 17:29
  • 2
    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).
    – Takkat
    Oct 23, 2011 at 17:53

2 Answers 2

11

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.

3
  • 1
    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 Oct 23, 2011 at 19:00
  • 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? Aug 24, 2015 at 3:36
  • @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.
    – Brett G
    Aug 15, 2016 at 15:34
8

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
1
  • 1
    How can I direct the swap file to be on a specific storage device?
    – Matt
    Jun 30, 2015 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.