Cloning .vdi was Successful However Disk Space Did Not Increase

JockVSJockJockVSJock Posts: 1,118Member
I'm running VirtualBox 4.3 and have Ubuntu 12.04.2 x64 guest, which has run out of disk space. I need to install VirtualBox Guest Additions and I have gone thru and deleted large files along with old kernels to free up more space.

I found this step-by-step tutorial here to increase disk space:

Hajuria's Blog: How to increase Virtualbox disk size in 9 easy steps

From Windows 7 MS DOS ran this successfully
C:\Program Files\Oracle\VirtualBox>VBoxManage modifyhd --resize 12920 "C:\Users\
cmmiller\VirtualBox VMs\Ubuntu 12.04.2 x64 Clone 001\Ubuntu 12.04.2 x64 Clone 00
1.vdi"
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

When I log into the Ubuntu VM and run df -h, it shows the following:
$ df -h
Filesystem                  Size     Used     Avail       Used%    Mounted On 
/dev/sda1                   6.0G    5.3G     401M      94%       /

I'm not understanding how VBoxManage says it ran successfully along with no issues of cloning the original .vdi file, however once logging into the Linux VM, it shows decrease of HD Space from 8 GB to 6 GB.
***Freedom of Speech, Just Watch What You Say*** Example, Beware of CompTIA Certs (Deleted From Google Cached)

"Its easier to deceive the masses then to convince the masses that they have been deceived."
-unknown

Comments

  • alan2308alan2308 CISSP, MCSA 2008, MCSA 2012, CCNA R&S, CCNA Security Ann Arbor, MIPosts: 1,854Member ■■■■■■■■□□
    Expanding the disk is not going to change the size of the partition. Note how in your link the additional space showed up as unallocated space. My guess would be your 8GB disk had 2GB allocated to swap, and /dev/sda1 has always been 6GB. If you want more space for /dev/sda1, you'll also have to extend the partition as well.
  • ccnxjrccnxjr Posts: 304Member
    Expanding on Alan's post,
    Most likely the additional space isn't allocated and you'll need to resize the partitions or create a new one from the free space.

    Just to verify that you do have the space run the following:
    [email protected]:~$ sudo fdisk -l
    Disk /dev/sda: 10.7 GB, 10737418240 bytes
    255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00010d1e
    
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048    14680063     7339008   83  Linux
    /dev/sda2        14682110    16775167     1046529    5  Extended
    /dev/sda5        14682112    16775167     1046528   82  Linux swap / Solaris
    
    

    The first line of output should have the total capacity of the attached device:
    Disk /dev/sda: 10.7 GB, 10737418240 bytes
    


    [email protected]:~$ sudo df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda1       6.8G  3.0G  3.5G  47% /
    udev            492M   12K  492M   1% /dev
    tmpfs           101M  756K  100M   1% /run
    none            5.0M     0  5.0M   0% /run/lock
    none            501M  144K  501M   1% /run/shm
    

    won't be a good indicator as the unallocated space isn't yet part of your file system.
  • JockVSJockJockVSJock Posts: 1,118Member
    Here is my listing from fdisk
                     
    [LIST=1]
    [*][email protected]:~# fdisk -l
     
    Disk /dev/sda: 13.5 GB, 13547601920 bytes
    255 heads, 63 sectors/track, 1647 cylinders, total 26460160 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0005a181
     
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048    12582911     6290432   83  Linux
    /dev/sda2        12584958    16775167     2095105    5  Extended
    /dev/sda5        12584960    16775167     2095104   82  Linux swap / Solaris 
    [/LIST]
    
             
    
    

    To me /dev/sda5/ is the new space that I created.

    From what I understand reading various threads I must use gparted to convert that space over to ext4 and then the .vdi file will see the newly created space.

    The only issue I'm having now is that my disk space is full and I won't be able to install gparted from apt-get.

    I have downloaded System Rescue however I'm not sure what to do next, looking online for solutions are confusing. To me, it looks like I will have to mount this .iso, however it is an .iso that lives on the Host, not the Guest. The reason I'm trying to add more space is because I'm trying to install Guest Additions.

    Can anyone advise how to do this or if there is a better way to go about this.
    ***Freedom of Speech, Just Watch What You Say*** Example, Beware of CompTIA Certs (Deleted From Google Cached)

    "Its easier to deceive the masses then to convince the masses that they have been deceived."
    -unknown
  • ccnxjrccnxjr Posts: 304Member
    ***Disclaimer: there is certainly the potential for data loss when working with partitions***

    First, make a backup of this VM somewhere.

    Second, This blog post should certainly help, give it a read:
    Live resizing of an ext4 filesytem on linux | The silence of the code

    One additional note, make sure nothing else is writing to disk , run a quick " ps aux"
    One more additional note, if you loose track of the UUIDs you can run this to get that info back :
    [email protected]:~$ sudo blkid
    [sudo] password for dave:
    /dev/sr0: LABEL="VBOXADDITIONS_4.3.12_93733" TYPE="iso9660"
    /dev/sda1: UUID="ab2614d0-de7a-4dd9-bd85-1a76110afc70" TYPE="ext4"
    /dev/sda5: UUID="a2e3f9cb-0dc0-488a-85de-820fd378fa00" TYPE="swap"
    
    
    

    Though, I highly recommend you log your terminal session or give yourself some mad scroll back buffer before even starting, just in case you need to back track.

    Third, make sure your backup VM works.

    Fourth, re-read then attempt !
  • ccnxjrccnxjr Posts: 304Member
    Because Imma karma whore :P

    Here's the annotated version :

    Basically:
    -Remove the partitions
    -Add the resized partitions
    -Save the partition information
    -Reboot
    -Run resize2fs, because it does some magic
    -Take care of the updated swap partition information in various places




    So do this:
    login as: dave
    [email protected]:~$
    [email protected]:~$ sudo fdisk -l
    [sudo] password for dave:
    
    
    Disk /dev/sda: 13.5 GB, 13547601920 bytes
    255 heads, 63 sectors/track, 1647 cylinders, total 26460160 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00010d1e
    
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1            2048    16779263     8388608   83  Linux
    /dev/sda2        16779264    20971519     2096128    5  Extended
    /dev/sda5        16781312    20971519     2095104   82  Linux swap / Solaris
    [email protected]:~$ sudo df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda1       7.8G  3.0G  4.4G  41% /
    udev            492M  4.0K  492M   1% /dev
    tmpfs           101M  756K  100M   1% /run
    none            5.0M     0  5.0M   0% /run/lock
    none            501M  144K  501M   1% /run/shm
    

    Well , login as you, not 'dave' (unless your login is dave, it's your system!)

    This is kinda where we are, 12 GB disk (13.5, whatevs)


    Now it's time to get our hands dirty!


    Let's take a look at the big picture.
    Type 'sudo fdisk /dev/sda' to enter the fdisk subshell.
    Type 'p' to take a look at things.
    [email protected]:~$ sudo fdisk /dev/sda
    
    
    Command (m for help): p
    
    
    Disk /dev/sda: 13.5 GB, 13547601920 bytes
    255 heads, 63 sectors/track, 1647 cylinders, total 26460160 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00010d1e
    
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1            2048    16779263     8388608   83  Linux
    /dev/sda2        16779264    20971519     2096128    5  Extended
    /dev/sda5        16781312    20971519     2095104   82  Linux swap / Solaris
    



    Delete the partitions /dev/sda1 and /dev/sda2 .
    Type 'd' to delete a partition.
    Type '1' to delete partition '1'.
    Type 'd' to delete another partition.
    Type '2' to delete partition '2'




    Command (m for help): d
    Partition number (1-5): 1
    
    
    Command (m for help): d
    Partition number (1-5): 2
    





    Voila! All gone, partition '5' as well!!
    And our system is still intact!
    Type 'p' to verify.
    Command (m for help): p
    
    
    Disk /dev/sda: 13.5 GB, 13547601920 bytes
    255 heads, 63 sectors/track, 1647 cylinders, total 26460160 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00010d1e
    
    
       Device Boot      Start         End      Blocks   Id  System
    
    
    



    Now created a new partition of approximately 11 G
    Type 'n' for new partition.
    Type 'p' to make it a primary parition.
    Type '1' to make it partition number '1'.
    Press 'Enter' to accept the default value for the first sector.
    Type '+11G' to specify that this partition will be about 11 GB large.


    When the prompt re-appears press 'p' to take a good look at what you've done.
    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p
    Partition number (1-4, default 1): 1
    First sector (2048-26460159, default 204[IMG]https://us.v-cdn.net/6030959/uploads/images/smilies/icon_cool.gif[/IMG]:
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-26460159, default 26460159): +11G
    
    
    Command (m for help): p
    
    
    Disk /dev/sda: 13.5 GB, 13547601920 bytes
    255 heads, 63 sectors/track, 1647 cylinders, total 26460160 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00010d1e
    
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1            2048    23070719    11534336   83  Linux
    

    Now for the swap partition, it'll take a few more steps.
    Type 'n' to create a new partition.
    Type 'e' to make it an extended partition.
    Press 'Enter' to accept the default for the first sector.
    Press 'Enter' to also accept the default for the last sector.
    Type 'p' to take a look at your hard work (but we're not done yet!).
    Command (m for help): n
    Partition type:
       p   primary (1 primary, 0 extended, 3 free)
       e   extended
    Select (default p): e
    Partition number (1-4, default 2): 2
    First sector (23070720-26460159, default 23070720):
    Using default value 23070720
    Last sector, +sectors or +size{K,M,G} (23070720-26460159, default 26460159):
    Using default value 26460159
    
    
    Command (m for help): p
    
    
    Disk /dev/sda: 13.5 GB, 13547601920 bytes
    255 heads, 63 sectors/track, 1647 cylinders, total 26460160 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00010d1e
    
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1            2048    23070719    11534336   83  Linux
    /dev/sda2        23070720    26460159     1694720    5  Extended
    

    Type 'n' again to create a new partition.
    But wait, didn't we use the rest of the disk in the last section?
    We'll we're making a logical partition on top of the extended one.
    So, Type 'l' to make it a logical partition.
    Press 'Enter' to accept the default starting location.
    You'll notice it's slightly further ahead than the starting sector for the extended partition
    Press 'Enter' again to accept the default last sector.
    Press 'p' to admire your handicraft!
    Command (m for help): n
    Partition type:
       p   primary (1 primary, 1 extended, 2 free)
       l   logical (numbered from 5)
    Select (default p): l
    Adding logical partition 5
    First sector (23072768-26460159, default 2307276[IMG]https://us.v-cdn.net/6030959/uploads/images/smilies/icon_cool.gif[/IMG]:
    Using default value 23072768
    Last sector, +sectors or +size{K,M,G} (23072768-26460159, default 26460159):
    Using default value 26460159
    
    
    Command (m for help): p
    
    
    Disk /dev/sda: 13.5 GB, 13547601920 bytes
    255 heads, 63 sectors/track, 1647 cylinders, total 26460160 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00010d1e
    
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1            2048    23070719    11534336   83  Linux
    /dev/sda2        23070720    26460159     1694720    5  Extended
    /dev/sda5        23072768    26460159     1693696   83  Linux
    

    Still not done with the swap partition however.
    Type 't' to change the partitions system id.
    Type '5' to selection the partition we'd like to change
    Type '82' to set that partition to be of type 'Linux swap / Solaris'
    Type 'p' to just make sure it's what you wanted.
    Command (m for help): t
    Partition number (1-5): 5
    Hex code (type L to list codes): 82
    Changed system type of partition 5 to 82 (Linux swap / Solaris)
    
    
    Command (m for help): p
    
    
    Disk /dev/sda: 13.5 GB, 13547601920 bytes
    255 heads, 63 sectors/track, 1647 cylinders, total 26460160 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00010d1e
    
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1            2048    23070719    11534336   83  Linux
    /dev/sda2        23070720    26460159     1694720    5  Extended
    /dev/sda5        23072768    26460159     1693696   82  Linux swap / Solaris
    



    Great! Now from the output looks like we're ready to apply these settings!
    Type 'w' to write these changes to disk!
    You should be dropped back into the system shell and from there reboot, there's still more work to get done!


    Command (m for help): w
    The partition table has been altered!
    
    
    Calling ioctl() to re-read partition table.
    
    
    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe([IMG]https://us.v-cdn.net/6030959/uploads/images/smilies/icon_cool.gif[/IMG] or kpartx([IMG]https://us.v-cdn.net/6030959/uploads/images/smilies/icon_cool.gif[/IMG]
    Syncing disks.
    [email protected]:~$ sudo reboot
    [email protected]:~$
    Broadcast message from [email protected]
            (/dev/pts/0) at 23:37 ...
    
    
    The system is going down for reboot NOW!
    



    K,
    System has restarted, we've logged in , lets see the damage:
    [email protected]:~$ sudo df -h
    [sudo] password for dave:
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda1       7.8G  3.0G  4.4G  41% /
    udev            492M   12K  492M   1% /dev
    tmpfs           101M  756K  100M   1% /run
    none            5.0M     0  5.0M   0% /run/lock
    none            501M  144K  501M   1% /run/shm
    [email protected]:~$ sudo fdisk -l
    
    
    Disk /dev/sda: 13.5 GB, 13547601920 bytes
    255 heads, 63 sectors/track, 1647 cylinders, total 26460160 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00010d1e
    
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1            2048    23070719    11534336   83  Linux
    /dev/sda2        23070720    26460159     1694720    5  Extended
    /dev/sda5        23072768    26460159     1693696   82  Linux swap / Solaris
    

    WTF!
    looks about the same, where's the space?
    K, don't loose it yet!
    Notice that /dev/sda2 is starts much further away from the end of /dev/sda1.
    Something has changed.


    We need to resize /dev/sda1
    Type 'sudo resize2fs /dev/sda1' to resize sda1 , should work while the system is live.


    [email protected]:~$ sudo resize2fs /dev/sda1
    resize2fs 1.42 (29-Nov-2011)
    Filesystem at /dev/sda1 is mounted on /; on-line resizing required
    old_desc_blocks = 1, new_desc_blocks = 1
    The filesystem on /dev/sda1 is now 2883584 blocks long.
    

    K, something happened, let's see....:


    [email protected]:~$ sudo df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda1        11G  3.0G  7.2G  30% /
    udev            492M   12K  492M   1% /dev
    tmpfs           101M  756K  100M   1% /run
    none            5.0M     0  5.0M   0% /run/lock
    none            501M  144K  501M   1% /run/shm
    

    K, looks good!
    Don't break open the Miller High Life yet!
    Still need to fix the swap file
    Type 'sudo mkswap /dev/sda5' , just do it, it's late and I need sleep ;)

    [email protected]:~$ sudo mkswap /dev/sda5
    Setting up swapspace version 1, size = 1693692 KiB
    no label, UUID=5c8e8382-c577-4759-816f-b09b7fd0723e
    

    Take note of the UUID, we'll need it to edit '/etc/fstab '
    CAREFULLY!
    You'll want to update the UUID of the swap file in there.
    See the screen shot at the bottom.
    Please update '/etc/fstab' with the new UUID of your swap partition before moving on to the next step.
    (I have no clue what will happen if you don't , but I don't expect it to be pleasant)
    I'll wait.
    .
    ..
    ...
    ....
    .....


    Allrighty then!

    Last, but not LEAST!
    Type 'sudo swapon --all --verbose' , that's it yer done!
    [email protected]:~$ sudo swapon --all --verbose
    swapon on /dev/sda5
    swapon: /dev/sda5: found swap signature: version 1, page-size 4, same byte order
    swapon: /dev/sda5: pagesize=4096, swapsize=1734344704, devsize=1734344704
    


    As promised, screen shot for editing /etc/fstab

  • JockVSJockJockVSJock Posts: 1,118Member
    Great write up!

    Thanks to that I have resolved the issue. Been awhile since I've used Fdisk (maybe since 2002/2003), anyways it worked.

    thanks
    ***Freedom of Speech, Just Watch What You Say*** Example, Beware of CompTIA Certs (Deleted From Google Cached)

    "Its easier to deceive the masses then to convince the masses that they have been deceived."
    -unknown
Sign In or Register to comment.