How to resize the disk of an Ubuntu-VM correctly with GParted

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I use VirtualBox on Windows 10 to run a VM using Ubuntu 16.04.1 LTS.



I got the VM from my University with a disk size of 20GB which was way to optimistic ... so I want to resize it to 50GB



so I already did



  1. (on the host) Make a BackUp ;)

  2. (on the host) VBoxManage clonehd "source.vmdk" "clone.vdi" --format vdi

  3. (on the host) VBoxManage modifyhd "clone.vdi" --resize 51200

  4. (on the host) Downloaded GParted.iso

  5. (in the VM) Booted into GParted

  6. (in the VM) Expanded The Swap from 2GB to 4GB according to the RAM of the VM I also changed

Now I see the following image
GParted
As you can see obviously the new diskspace got added at the end of the disk. But now I'm facing the problem that I cannot expand the primary partition because the swap partition is "in the way". I neither am able to move the swap-partition.



How can I expand the primary partition and/or move the swap partition to the end of the disk?



The Idea I had was:



  1. Delete /dev/sda5

  2. Delete /dev/sda2

  3. Create new Partition /dev/sda2 with file format linux-swap and the end of the disk

  4. Expand /dev/sda1 to use the rest of the disk

Is this the way to go? Will Ubuntu automatically "know" where the swap partition will be after this action?










share|improve this question





















  • If this is a new system, I would just set up logical volumes. That way you can set up partitions wherever you want and combine separate partitions to form file systems.
    – Raman Sailopal
    Oct 3 '17 at 13:32










  • Yeah but as I mentioned I got the System from the university (fully installed and with programs builded we have to use)
    – derHugo
    Oct 3 '17 at 13:33










  • Check if /dev/sda2 is in use first. If not, then you should be OK doing what you suggested,
    – Raman Sailopal
    Oct 3 '17 at 13:42










  • Ok it said used 0, so I did it now. Waiting for the boot .. how can I in general know, if Ubuntu is using my swap correctly?
    – derHugo
    Oct 3 '17 at 13:43










  • swapon -s will give you details regarding usage.
    – Raman Sailopal
    Oct 3 '17 at 13:46














up vote
0
down vote

favorite












I use VirtualBox on Windows 10 to run a VM using Ubuntu 16.04.1 LTS.



I got the VM from my University with a disk size of 20GB which was way to optimistic ... so I want to resize it to 50GB



so I already did



  1. (on the host) Make a BackUp ;)

  2. (on the host) VBoxManage clonehd "source.vmdk" "clone.vdi" --format vdi

  3. (on the host) VBoxManage modifyhd "clone.vdi" --resize 51200

  4. (on the host) Downloaded GParted.iso

  5. (in the VM) Booted into GParted

  6. (in the VM) Expanded The Swap from 2GB to 4GB according to the RAM of the VM I also changed

Now I see the following image
GParted
As you can see obviously the new diskspace got added at the end of the disk. But now I'm facing the problem that I cannot expand the primary partition because the swap partition is "in the way". I neither am able to move the swap-partition.



How can I expand the primary partition and/or move the swap partition to the end of the disk?



The Idea I had was:



  1. Delete /dev/sda5

  2. Delete /dev/sda2

  3. Create new Partition /dev/sda2 with file format linux-swap and the end of the disk

  4. Expand /dev/sda1 to use the rest of the disk

Is this the way to go? Will Ubuntu automatically "know" where the swap partition will be after this action?










share|improve this question





















  • If this is a new system, I would just set up logical volumes. That way you can set up partitions wherever you want and combine separate partitions to form file systems.
    – Raman Sailopal
    Oct 3 '17 at 13:32










  • Yeah but as I mentioned I got the System from the university (fully installed and with programs builded we have to use)
    – derHugo
    Oct 3 '17 at 13:33










  • Check if /dev/sda2 is in use first. If not, then you should be OK doing what you suggested,
    – Raman Sailopal
    Oct 3 '17 at 13:42










  • Ok it said used 0, so I did it now. Waiting for the boot .. how can I in general know, if Ubuntu is using my swap correctly?
    – derHugo
    Oct 3 '17 at 13:43










  • swapon -s will give you details regarding usage.
    – Raman Sailopal
    Oct 3 '17 at 13:46












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I use VirtualBox on Windows 10 to run a VM using Ubuntu 16.04.1 LTS.



I got the VM from my University with a disk size of 20GB which was way to optimistic ... so I want to resize it to 50GB



so I already did



  1. (on the host) Make a BackUp ;)

  2. (on the host) VBoxManage clonehd "source.vmdk" "clone.vdi" --format vdi

  3. (on the host) VBoxManage modifyhd "clone.vdi" --resize 51200

  4. (on the host) Downloaded GParted.iso

  5. (in the VM) Booted into GParted

  6. (in the VM) Expanded The Swap from 2GB to 4GB according to the RAM of the VM I also changed

Now I see the following image
GParted
As you can see obviously the new diskspace got added at the end of the disk. But now I'm facing the problem that I cannot expand the primary partition because the swap partition is "in the way". I neither am able to move the swap-partition.



How can I expand the primary partition and/or move the swap partition to the end of the disk?



The Idea I had was:



  1. Delete /dev/sda5

  2. Delete /dev/sda2

  3. Create new Partition /dev/sda2 with file format linux-swap and the end of the disk

  4. Expand /dev/sda1 to use the rest of the disk

Is this the way to go? Will Ubuntu automatically "know" where the swap partition will be after this action?










share|improve this question













I use VirtualBox on Windows 10 to run a VM using Ubuntu 16.04.1 LTS.



I got the VM from my University with a disk size of 20GB which was way to optimistic ... so I want to resize it to 50GB



so I already did



  1. (on the host) Make a BackUp ;)

  2. (on the host) VBoxManage clonehd "source.vmdk" "clone.vdi" --format vdi

  3. (on the host) VBoxManage modifyhd "clone.vdi" --resize 51200

  4. (on the host) Downloaded GParted.iso

  5. (in the VM) Booted into GParted

  6. (in the VM) Expanded The Swap from 2GB to 4GB according to the RAM of the VM I also changed

Now I see the following image
GParted
As you can see obviously the new diskspace got added at the end of the disk. But now I'm facing the problem that I cannot expand the primary partition because the swap partition is "in the way". I neither am able to move the swap-partition.



How can I expand the primary partition and/or move the swap partition to the end of the disk?



The Idea I had was:



  1. Delete /dev/sda5

  2. Delete /dev/sda2

  3. Create new Partition /dev/sda2 with file format linux-swap and the end of the disk

  4. Expand /dev/sda1 to use the rest of the disk

Is this the way to go? Will Ubuntu automatically "know" where the swap partition will be after this action?







ubuntu partition gparted move-partition






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 3 '17 at 13:15









derHugo

1125




1125











  • If this is a new system, I would just set up logical volumes. That way you can set up partitions wherever you want and combine separate partitions to form file systems.
    – Raman Sailopal
    Oct 3 '17 at 13:32










  • Yeah but as I mentioned I got the System from the university (fully installed and with programs builded we have to use)
    – derHugo
    Oct 3 '17 at 13:33










  • Check if /dev/sda2 is in use first. If not, then you should be OK doing what you suggested,
    – Raman Sailopal
    Oct 3 '17 at 13:42










  • Ok it said used 0, so I did it now. Waiting for the boot .. how can I in general know, if Ubuntu is using my swap correctly?
    – derHugo
    Oct 3 '17 at 13:43










  • swapon -s will give you details regarding usage.
    – Raman Sailopal
    Oct 3 '17 at 13:46
















  • If this is a new system, I would just set up logical volumes. That way you can set up partitions wherever you want and combine separate partitions to form file systems.
    – Raman Sailopal
    Oct 3 '17 at 13:32










  • Yeah but as I mentioned I got the System from the university (fully installed and with programs builded we have to use)
    – derHugo
    Oct 3 '17 at 13:33










  • Check if /dev/sda2 is in use first. If not, then you should be OK doing what you suggested,
    – Raman Sailopal
    Oct 3 '17 at 13:42










  • Ok it said used 0, so I did it now. Waiting for the boot .. how can I in general know, if Ubuntu is using my swap correctly?
    – derHugo
    Oct 3 '17 at 13:43










  • swapon -s will give you details regarding usage.
    – Raman Sailopal
    Oct 3 '17 at 13:46















If this is a new system, I would just set up logical volumes. That way you can set up partitions wherever you want and combine separate partitions to form file systems.
– Raman Sailopal
Oct 3 '17 at 13:32




If this is a new system, I would just set up logical volumes. That way you can set up partitions wherever you want and combine separate partitions to form file systems.
– Raman Sailopal
Oct 3 '17 at 13:32












Yeah but as I mentioned I got the System from the university (fully installed and with programs builded we have to use)
– derHugo
Oct 3 '17 at 13:33




Yeah but as I mentioned I got the System from the university (fully installed and with programs builded we have to use)
– derHugo
Oct 3 '17 at 13:33












Check if /dev/sda2 is in use first. If not, then you should be OK doing what you suggested,
– Raman Sailopal
Oct 3 '17 at 13:42




Check if /dev/sda2 is in use first. If not, then you should be OK doing what you suggested,
– Raman Sailopal
Oct 3 '17 at 13:42












Ok it said used 0, so I did it now. Waiting for the boot .. how can I in general know, if Ubuntu is using my swap correctly?
– derHugo
Oct 3 '17 at 13:43




Ok it said used 0, so I did it now. Waiting for the boot .. how can I in general know, if Ubuntu is using my swap correctly?
– derHugo
Oct 3 '17 at 13:43












swapon -s will give you details regarding usage.
– Raman Sailopal
Oct 3 '17 at 13:46




swapon -s will give you details regarding usage.
– Raman Sailopal
Oct 3 '17 at 13:46










1 Answer
1






active

oldest

votes

















up vote
0
down vote













In this particular case, you can probably disable the swap space, move the swap partition, and re-enable it (swapoff dev/sda5, move the partition, then swapon /dev/sda5). Recreating the swap partition by hand as you suggested will likely cause Ubuntu to fail to recognize it (it will have a different UUID than the original swap partition, which in turn means it won't be automatically enabled).



The more generically useful (and arguably safer) option is to instead boot into a maintenance LiveCD (System Rescue CD is what I personally use for this, but there are other options, including one that is also called GParted and is designed specifically for this type of thing), and move and resize things from there as needed.






share|improve this answer




















  • If you read my question carefully you see that I already used GParted(iso). My suggestion was doing those steps using the booted GParted. Ubuntu itself wasn't running when I made the changes so I would actually assume that also my fstab should have been applied automatically afaik?
    – derHugo
    Oct 4 '17 at 4:57











  • @derHugo Apologies, I missed that somehow. As far as /etc/fstab, Ubuntu uses UUID's for mounting filesystems, so as long as you don't wipe and re-create filesystems or the swap partition, you can move partitions around all you want and it will still work without needing updates to /etc/fstab. As far as moving the swap partition, GParted itself will complain about moving a partition, but you can safely do so here.
    – Austin Hemmelgarn
    Oct 4 '17 at 11:32










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f395835%2fhow-to-resize-the-disk-of-an-ubuntu-vm-correctly-with-gparted%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













In this particular case, you can probably disable the swap space, move the swap partition, and re-enable it (swapoff dev/sda5, move the partition, then swapon /dev/sda5). Recreating the swap partition by hand as you suggested will likely cause Ubuntu to fail to recognize it (it will have a different UUID than the original swap partition, which in turn means it won't be automatically enabled).



The more generically useful (and arguably safer) option is to instead boot into a maintenance LiveCD (System Rescue CD is what I personally use for this, but there are other options, including one that is also called GParted and is designed specifically for this type of thing), and move and resize things from there as needed.






share|improve this answer




















  • If you read my question carefully you see that I already used GParted(iso). My suggestion was doing those steps using the booted GParted. Ubuntu itself wasn't running when I made the changes so I would actually assume that also my fstab should have been applied automatically afaik?
    – derHugo
    Oct 4 '17 at 4:57











  • @derHugo Apologies, I missed that somehow. As far as /etc/fstab, Ubuntu uses UUID's for mounting filesystems, so as long as you don't wipe and re-create filesystems or the swap partition, you can move partitions around all you want and it will still work without needing updates to /etc/fstab. As far as moving the swap partition, GParted itself will complain about moving a partition, but you can safely do so here.
    – Austin Hemmelgarn
    Oct 4 '17 at 11:32














up vote
0
down vote













In this particular case, you can probably disable the swap space, move the swap partition, and re-enable it (swapoff dev/sda5, move the partition, then swapon /dev/sda5). Recreating the swap partition by hand as you suggested will likely cause Ubuntu to fail to recognize it (it will have a different UUID than the original swap partition, which in turn means it won't be automatically enabled).



The more generically useful (and arguably safer) option is to instead boot into a maintenance LiveCD (System Rescue CD is what I personally use for this, but there are other options, including one that is also called GParted and is designed specifically for this type of thing), and move and resize things from there as needed.






share|improve this answer




















  • If you read my question carefully you see that I already used GParted(iso). My suggestion was doing those steps using the booted GParted. Ubuntu itself wasn't running when I made the changes so I would actually assume that also my fstab should have been applied automatically afaik?
    – derHugo
    Oct 4 '17 at 4:57











  • @derHugo Apologies, I missed that somehow. As far as /etc/fstab, Ubuntu uses UUID's for mounting filesystems, so as long as you don't wipe and re-create filesystems or the swap partition, you can move partitions around all you want and it will still work without needing updates to /etc/fstab. As far as moving the swap partition, GParted itself will complain about moving a partition, but you can safely do so here.
    – Austin Hemmelgarn
    Oct 4 '17 at 11:32












up vote
0
down vote










up vote
0
down vote









In this particular case, you can probably disable the swap space, move the swap partition, and re-enable it (swapoff dev/sda5, move the partition, then swapon /dev/sda5). Recreating the swap partition by hand as you suggested will likely cause Ubuntu to fail to recognize it (it will have a different UUID than the original swap partition, which in turn means it won't be automatically enabled).



The more generically useful (and arguably safer) option is to instead boot into a maintenance LiveCD (System Rescue CD is what I personally use for this, but there are other options, including one that is also called GParted and is designed specifically for this type of thing), and move and resize things from there as needed.






share|improve this answer












In this particular case, you can probably disable the swap space, move the swap partition, and re-enable it (swapoff dev/sda5, move the partition, then swapon /dev/sda5). Recreating the swap partition by hand as you suggested will likely cause Ubuntu to fail to recognize it (it will have a different UUID than the original swap partition, which in turn means it won't be automatically enabled).



The more generically useful (and arguably safer) option is to instead boot into a maintenance LiveCD (System Rescue CD is what I personally use for this, but there are other options, including one that is also called GParted and is designed specifically for this type of thing), and move and resize things from there as needed.







share|improve this answer












share|improve this answer



share|improve this answer










answered Oct 3 '17 at 18:34









Austin Hemmelgarn

5,2041915




5,2041915











  • If you read my question carefully you see that I already used GParted(iso). My suggestion was doing those steps using the booted GParted. Ubuntu itself wasn't running when I made the changes so I would actually assume that also my fstab should have been applied automatically afaik?
    – derHugo
    Oct 4 '17 at 4:57











  • @derHugo Apologies, I missed that somehow. As far as /etc/fstab, Ubuntu uses UUID's for mounting filesystems, so as long as you don't wipe and re-create filesystems or the swap partition, you can move partitions around all you want and it will still work without needing updates to /etc/fstab. As far as moving the swap partition, GParted itself will complain about moving a partition, but you can safely do so here.
    – Austin Hemmelgarn
    Oct 4 '17 at 11:32
















  • If you read my question carefully you see that I already used GParted(iso). My suggestion was doing those steps using the booted GParted. Ubuntu itself wasn't running when I made the changes so I would actually assume that also my fstab should have been applied automatically afaik?
    – derHugo
    Oct 4 '17 at 4:57











  • @derHugo Apologies, I missed that somehow. As far as /etc/fstab, Ubuntu uses UUID's for mounting filesystems, so as long as you don't wipe and re-create filesystems or the swap partition, you can move partitions around all you want and it will still work without needing updates to /etc/fstab. As far as moving the swap partition, GParted itself will complain about moving a partition, but you can safely do so here.
    – Austin Hemmelgarn
    Oct 4 '17 at 11:32















If you read my question carefully you see that I already used GParted(iso). My suggestion was doing those steps using the booted GParted. Ubuntu itself wasn't running when I made the changes so I would actually assume that also my fstab should have been applied automatically afaik?
– derHugo
Oct 4 '17 at 4:57





If you read my question carefully you see that I already used GParted(iso). My suggestion was doing those steps using the booted GParted. Ubuntu itself wasn't running when I made the changes so I would actually assume that also my fstab should have been applied automatically afaik?
– derHugo
Oct 4 '17 at 4:57













@derHugo Apologies, I missed that somehow. As far as /etc/fstab, Ubuntu uses UUID's for mounting filesystems, so as long as you don't wipe and re-create filesystems or the swap partition, you can move partitions around all you want and it will still work without needing updates to /etc/fstab. As far as moving the swap partition, GParted itself will complain about moving a partition, but you can safely do so here.
– Austin Hemmelgarn
Oct 4 '17 at 11:32




@derHugo Apologies, I missed that somehow. As far as /etc/fstab, Ubuntu uses UUID's for mounting filesystems, so as long as you don't wipe and re-create filesystems or the swap partition, you can move partitions around all you want and it will still work without needing updates to /etc/fstab. As far as moving the swap partition, GParted itself will complain about moving a partition, but you can safely do so here.
– Austin Hemmelgarn
Oct 4 '17 at 11:32

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f395835%2fhow-to-resize-the-disk-of-an-ubuntu-vm-correctly-with-gparted%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay