LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.

Notices


Reply
  Search this Thread
Old 04-12-2024, 09:05 AM   #1
NuxIT
Member
 
Registered: Jul 2003
Location: Westminser, CO
Distribution: xUbuntu
Posts: 137

Rep: Reputation: 20
How to extend a partition in Linux Virtualbox machine?


Hello, I'm running low on space and wish to add the 8GB I allocated within Virtual box to my VM in virtualbox. I see the 8GB free in gparted but I'm not sure how I can add this space to my /dev/sda1 partition? I think I need to use LVM but not sure. I'm running Oracle VirtualBox on Ubuntu and have Linux Mint VM I created in VBOX.

Code:
└─# df -H
Filesystem      Size  Used Avail Use% Mounted on
udev            3.1G     0  3.1G   0% /dev
tmpfs           623M  1.2M  622M   1% /run
/dev/sda1        29G   23G  4.4G  85% /
tmpfs           3.2G     0  3.2G   0% /dev/shm
tmpfs           5.3M     0  5.3M   0% /run/lock
tmpfs           623M  2.7M  620M   1% /run/user/1000
Code:
└─$ sudo fdisk -l                        
[sudo] password: 
Disk /dev/sda: 35.91 GiB, 38561972224 bytes, 75316352 sectors
Disk model: VBOX HARDDISK   
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd75cca19

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048 56719359 56717312   27G 83 Linux
/dev/sda2       56721406 58718207  1996802  975M  f W95 Ext'd (LBA)
/dev/sda5       56721408 58718207  1996800  975M 82 Linux swap / Solaris
Appreciate any assistance with allocating the 8GB I have free to my /dev/sda1

Here's the 8GB free in gparted I wish to allocated to /dev/sda1

https://imgur.com/a/9TZm064

Last edited by NuxIT; 04-12-2024 at 09:08 AM.
 
Old 04-12-2024, 09:27 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,722

Rep: Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916
I would boot the live gparted ISO on the guest.
1. Move the extended partition to the right to create free space after sda1
2. Extend sda1 to use the free space.
3. Apply changes.
4. Shutdown live ISO, remove ISO from CD drive, reboot VM.

Always backup anything important on the VM as necessary. If you want to experiment first you can always clone the VM assuming you have enough disk space on the host.
 
1 members found this post helpful.
Old 04-12-2024, 10:12 AM   #3
NuxIT
Member
 
Registered: Jul 2003
Location: Westminser, CO
Distribution: xUbuntu
Posts: 137

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by michaelk View Post
I would boot the live gparted ISO on the guest.
1. Move the extended partition to the right to create free space after sda1
2. Extend sda1 to use the free space.
3. Apply changes.
4. Shutdown live ISO, remove ISO from CD drive, reboot VM.

Always backup anything important on the VM as necessary. If you want to experiment first you can always clone the VM assuming you have enough disk space on the host.
Cool. I'm going to give this a shot. I took a snapshot of my VM. Appreciate this info.
 
Old 04-12-2024, 11:42 AM   #4
NuxIT
Member
 
Registered: Jul 2003
Location: Westminser, CO
Distribution: xUbuntu
Posts: 137

Original Poster
Rep: Reputation: 20
I downloaded the gparted iso. Then I mounted this iso to my VDI I wish to resize and changed the boot order to boot off of the ISO.
When I boot it up I see the sda1 partition I want to resize but I still can't. I think I need to move my swap file for the vm (dev/sda5) over to right some how. The swap file is preventing me from being able to do this.
Any ideas how I can move the swap file over to the far right so my 7.91 GB free space is next to /dev/sda1?

https://imgur.com/a/i5fVe2K

Thanks again for any input!
 
Old 04-12-2024, 12:00 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,722

Rep: Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916
Select partion -> resize/move from the menu and the with the mouse move drag the extended partition box for sda2 to the far right so the unallocated space is between sda1 and sda2.
 
1 members found this post helpful.
Old 04-12-2024, 12:37 PM   #6
NuxIT
Member
 
Registered: Jul 2003
Location: Westminser, CO
Distribution: xUbuntu
Posts: 137

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by michaelk View Post
Select partion -> resize/move from the menu and the with the mouse move drag the extended partition box for sda2 to the far right so the unallocated space is between sda1 and sda2.
Ok, I think I'm following you now. If I click on /dev/sda2 and the move that to the far right it shows the message in the screen shot below.

"Grow /dev/sda2 from 975 MiB to 8.87 GiB"

Is this what I want to do to get the unallocated space next to /dev/sda1? I want to make sure that's accurate before committing this change. Much appreciated!
Also, any ideas why the images don't work? I keep having to paste links to my images instead. Thank you!


https://imgur.com/aPiyF3b


https://imgur.com/1RAQTmL
 
Old 04-12-2024, 12:51 PM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,722

Rep: Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916
No, you want to move not resize. Yes the unallocated space needs to follow sda1
 
Old 04-12-2024, 01:09 PM   #8
NuxIT
Member
 
Registered: Jul 2003
Location: Westminser, CO
Distribution: xUbuntu
Posts: 137

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by michaelk View Post
No, you want to move not resize. Yes the unallocated space needs to follow sda1
Ok, that's the problem, if I click on /dev/sdc2 the yellow box with the blue outline will not let me move that 975MB swap file to the right. All I can do is grab the arrow and extend it. Any ideas way? Thanks
 
Old 04-12-2024, 01:28 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,722

Rep: Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916
If you enter the 8GB or so into the box for preceding space it will move the partition to the right.
 
Old 04-12-2024, 03:28 PM   #10
NuxIT
Member
 
Registered: Jul 2003
Location: Westminser, CO
Distribution: xUbuntu
Posts: 137

Original Poster
Rep: Reputation: 20
Question

Quote:
Originally Posted by michaelk View Post
If you enter the 8GB or so into the box for preceding space it will move the partition to the right.
Yeah, if I reverse /dev/sda2 space from

DEFAULT:
Freespace preeeding (MiB): 0
MiB listed in the Free space following in (MiB) 8105

And if I flip those values around it ends up showing Grow /dev/sda2 from 975 Mib to 8.87 GiB

Is that going to grow my swap file on /dev/sds5 from 975 to 8.87GB?
I hope not. Otherwise I might have to look into deleting my current swap file. I should be able to join the free space left over by the swap file to the 7.91GB I have unallocated correct? I might need to edit that out in /etc/fstab in my guest OS before I attempt that and make sure my snapshot in Oracle is good. I hope the snapshot retains the current partition setup in case of issues. Here's the pictures illustrating what I was trying. Thanks again for anymore help!

Default settings:
https://imgur.com/aPiyF3b

Change to Opposite:
https://imgur.com/N1xKoRu

Changes it will make:
https://imgur.com/51zXH2l

Last edited by NuxIT; 04-14-2024 at 09:33 AM.
 
Old 04-12-2024, 04:13 PM   #11
NuxIT
Member
 
Registered: Jul 2003
Location: Westminser, CO
Distribution: xUbuntu
Posts: 137

Original Poster
Rep: Reputation: 20
Question Unable to extend /dev/sda2 to use unallocated space

Ok, I just found out that I had to first queue up the change above and then after that it allowed me to grab the swap file on /dev/sda5 and move it all the way to the right.
This is the operation that went through with these two actions.

2 Actions completed

https://imgur.com/XBykOHL
https://imgur.com/aPiyF3b
Result: Unallocated 7.91GB is now next to /dev/sda1 I wish to expand.

Unable to extend /dev/sda2 to use the 8.9G unallocated on /dev/sda2 in Gparted Live ISO boot

Unable to extend it if I'm in the OS either.
https://imgur.com/wVWeBdU

But I still cannot extend the /dev/sda1 through gparted event with the unallocated space listed in my screen shot. From what I recall I should be able to click Resize/Move on my /dev/sda1 and then drag a bar to utilize the 7.91 GB I have unallocated? Am I missing something here or do I have to edit something in the file system? I'm having an off day and kind of tired.

Also, seems odd that DH -H shows the 8.9G on /dev/sda2 I want to allocate to /dev/sda1 shows it as W95 Ext'd (LBA)
Might that be the issue?
Code:
sudo fdisk -l
Disk /dev/sda: 35.91 GiB, 38561972224 bytes, 75316352 sectors
Disk model: VBOX HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd75cca19

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048 56719359 56717312   27G 83 Linux
/dev/sda2       56721406 75315199 18593794  8.9G  f W95 Ext'd (LBA)
/dev/sda5       73318400 75315199  1996800  975M 82 Linux swap / Solaris
Appreciate any other ideas while I also look into this more!
 
Old 04-12-2024, 04:38 PM   #12
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,722

Rep: Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916
I can not tell but it looks like you do not have sda1 selected.
 
Old 04-12-2024, 04:53 PM   #13
NuxIT
Member
 
Registered: Jul 2003
Location: Westminser, CO
Distribution: xUbuntu
Posts: 137

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by michaelk View Post
I can not tell but it looks like you do not have sda1 selected.
I just booted back into gparted live. Per this screen shot this is what it does if I click on /dev/sda1 and Choose Move/Resize.
Unable to expand:
https://imgur.com/i1xK2zv

It does not show what should be 8GB free to the right to drag the arrow. I'm thinking I *might* have to run this command I found on stack exchange to delete /dev/sdc2 that shows up as W95 Ext'd (LBA) in fdisk -l output above?

Then I might be able to use the unallocated but I'm pretty sure that will blow away the /dev/sda5 975 MB swap file I'm using. I don't want to render it unbootable if do that.

The command was sudo /fdisk /dev/sda2 and then choose d for delete. Then I might be able to join the 27.04 GB on /dev/sda1 to the unallocated space?

Command I'm thinking about running.
/fdisk /dev/sda2 delete the 8.87 GB "Extended" /dev/sda2 which will likely wipeout /dev/sda5?
https://imgur.com/944F0OP


Current partitioning and file systems:
https://imgur.com/3TtQ0d7

Hoping to get this addressed and you've been very helpful!
 
Old 04-12-2024, 05:05 PM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,722

Rep: Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916Reputation: 5916
You made the extended partition larger and moved sda5 to the end of the extended partition. The unallocated space is in the wrong spot which is why you can not resize sda1. You could just delete swap but as posted that might leave your VM unable to boot.

Move sda5 back to the beginning of sda2.
Shrink sda2 back to its original size.
Move sda2 to the end of the drive.
Resize sda1.
 
Old 04-12-2024, 08:15 PM   #15
NuxIT
Member
 
Registered: Jul 2003
Location: Westminser, CO
Distribution: xUbuntu
Posts: 137

Original Poster
Rep: Reputation: 20
Quote:
Move sda5 back to the beginning of sda2.
Is this what you mean? If I click on Resize/Move sda5 swap and move it all the way to the left it will still leave 1MB in that field. I manually enter 0 for Free space preceding MB and it is not allowed. So, not matter what I end up with a 1 MB volume that I apparently couldn't delete if I run this operation since it shows grey for undelete if I click on the 1 MB. I'm assuming that would move the sda5 back to the beginning off sda2 per my original screen shots? It appears that would leave a 1MB unallocated space and put my swap file between the two unallocated.

Here's these steps I was mentioning where I end up with that 1 MB unallocated no matter what I tried.

HOW it Is NOW:
https://imgur.com/FayOZRd

And if I move it to the far Left it forces leaving 1 MB unallocated file. Even if I enter 0 in the preceding field. Also, I tried entering the 8104 for free Space following but then it switches the New Size where the swap is to 974 instead of the 975.
https://imgur.com/dZUHLqj

Quote:
Shrink sda2 back to its original size.
I never changed the size of the sda5 and I'm not sure why the original unallocated 7.91 GB fell under the submenu of /dev/sda2 and merged the unallocated with the swap. The swap has been 975MB the whole time. Also, I'm not sure why sda2 went from 975 to 8.87GB. Essentially dragging the sda5 over to the right caused the unallocated to join sda2 and expand adding the 7.91GB + 975MB totaling the 8.87 /dev/sda5 now consist of.

Leaves 1 MB of unallocated.
https://imgur.com/dZUHLqj
Unable to zero out free space preceding to 0. Forces the swap/sda5 to change from 975 MB to 974MB
https://imgur.com/dZUHLqj

Results of doing this do not look good and leave a 1 MB file even though the swap/sda5 says it will stay at 975MB even though i can't enter that value because it's not possible.
https://imgur.com/cgyjeje

Basically I'm not sure at this time how I can get /dev/sda2 back to the original 975MB that matched the 975MB swap file how it was originally. And I have no idea why the unallocated 7.91 merged with the sda2 disk.

Here's a before and after.

Before & After today's changes brief picutre: Original intention was to get sda1 next to the 9.71 MB unallocated so I could extend the /dev/sda2 my VM's vdi resides on. The sda5 975 swap when the original sda2 size was also 975MB
https://imgur.com/UYp2jFj


Thanks again for any ideas. I don't recall having so many issues with using gparted and allocating free space to extended existing partitions!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cannot extend c:\win on dualboot as no unallocated space nextdoor partition, extend is greyed out on disk mgt, cyno77 Linux - Newbie 68 05-15-2021 09:11 PM
[SOLVED] virtualbox is installed along with virtualbox-dkms and virtualbox-ext-pack and linux-headers-generic, but error for no /dev/vboxdrv Astral Axiom Linux - Software 2 03-04-2019 08:09 PM
Extend Linux Partition (Extend LVM) osama.mansoor Linux - Newbie 5 11-27-2015 01:09 AM
[SOLVED] Extend partition in Virtualbox machine lee_can Linux - Newbie 6 01-13-2014 04:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud

All times are GMT -5. The time now is 12:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration