Solved

Expanding the disk size on a ubuntu linux hyper-V guest

Posted on 2013-05-16
11
2,711 Views
Last Modified: 2014-11-12
Hello,

Please assist me with expanding the size of the physical disk shown in the attachment (which is the output of cfdisk.)  

The server is Ubuntu 11.04.  I have gone through the basic steps for adding hyper-v to the server (hv_vmbus, hv_storvsc, hv_blkvsc, hv_netvsc)  The virtual network is working good.  The only problem is the server not using the full size of my virtual disk, as shown in the attachment.

Any sort of assistance is greatly appreciated.

output of cfdisk on the hyper-v guest
0
Comment
Question by:stephenmiller
  • 8
  • 3
11 Comments
 
LVL 3

Expert Comment

by:GhostInTheMacheen
Comment Utility
An output from fdisk -l /dev/hda would be more useful in this situation.

This is one of those questions I think we all hate to answer, because the answer scares people (and reasonably so).

Unless your running LVM, a partition is a linear block of cylinders on the disk. To "extend" it you have to first clear any blocking partitions from the end of it, delete the partition entry, and create a new partition of larger size starting on the same cylinder.

In your case you're fairly lucky in that it doesn't look like you have an data partitions on /dev/hda except the one you want to extend. Blowing away the swap partition and recreating it is fine.

If you can use a Gparted LiveCD I highly recommend it, as it will make the process a lot easier, but assuming you can't you can go the old fdisk way.

Because your dealing with ext3, technically it is possible to do this live, with the partition mounted, but I would recommend against it if you have any LiveCD alternative.

If you really care about your data, back it up before you begin.

If you're doing this live you'll need to unmount your swap partition before continuing (do all of this as root):
# swapoff /dev/hda5
# umount /dev/hda5

Open in new window


Now get the cylinder information:
# fdisk -l /dev/hda

Open in new window


Note which cylinder /dev/hda1 starts on, you'll need it when recreating the partition. Since you have a bit of free space before it it almost certainly won't be the firs cylinder. You will also want to note how many cylinders the swap partition uses. It looks like you have about 2GB of swap space, but the number of cylinders will be determined by your installation's cylinder unit size.

Now, fire up fdisk -- start by using command 'm' to get further command info. I'm not in front of a computer right now, so I can give you the actual output. You will want t use 'd' to delete the existing partitions. It will ask you to give a number corresponding to the partition to be deleted. Delete both of them.

Now create a new partition starting on the same cylinder as your original /dev/hda1 by using the commands 'n' (new partition), 'p' (primary), '1' (first partition), <the starting cylinder you noted at the beginning>, <the last cylinder to use for the partition>

Remember to leave enough space for the swap partition when you're deciding on that last cylinder. It should be the total number of cylinders minus the swap swap size.

Now, create the swap partition in the same way at the end of the disk. It's also a primary partition -- don't worry, you'll flag it as swap in the next step.

Once both partitions have been created (use the 'p' command to print the table for display) you can set their flags.

To flag the first partition as bootable, use the commands 'a' and '1'.

To flag the  swap partition use 't', '2', '82'. Note that the second option might be a number greater than 2 if you assigned a higher partition number. The '82' represents swap, but I believe you can use the 'L' command at that step if you want a full type code list.

A this point you need to do a final check ('p' command one more time) and if you are satisfied, write the table to disk with 'w'.

If you did this live you'll likely get a warning telling you that the partition table can't be re-read on a live partition, so you'll have to restart before continuing. If you are dong it from a LiveCD then you're ready to continue.

If all has gone well up to this point, the only thing left to do is resize the filesystem to match the partition size. This is the easiest step.
# resize2fs /dev/hda1

Open in new window


Now, it's possible that your swap partition has changed partition number. If so, update /etc/fstab to reflect this -- for example /dev/hda5 may have become /dev/hda2 (use fdisk -l to check). You can also manually reenable swap without restarting using (as root) swapon /dev/hda2.

That's pretty much it ;)
0
 
LVL 3

Expert Comment

by:GhostInTheMacheen
Comment Utility
As an additional note, some people would recommend you fsck /dev/hda1, drop the journal (man tune2fs for further details), and e2fsck /dev/hda1 before (and after) performing the resize2fs call, and then rejournal it after the resize is completed.

That's fine advice if you don't have to do it to a live disk, but you can't safely fsck a live partition.

If you have a LiveCD option and can take the partition offline, I highly recommend doing so. If not, schedule a filesystem check for the next reboot.
0
 
LVL 3

Expert Comment

by:GhostInTheMacheen
Comment Utility
Reading back over my first response, I realize I had a few typos in there. Again, I'm not in front of a computer at the moment -- and mobile devices tend to apply "auto-correct" both selectively and painfully, heh.

I do apologize about the apparent grammatical errors, but the commands themselves look good.
0
 

Author Comment

by:stephenmiller
Comment Utility
Hi, thanks for the replies.  The server is new and not yet in production, so there is no concern about loss of data.  I can use a Gparted live CD if necessary.  I didn't get very far with the procedure because the first command throws an error.

I also included the output of fdisk -l /dev/hda for your reference.

See the attached file, the free space I'm trying to utilize doesn't show up in that output.
fdisk.png
0
 
LVL 3

Expert Comment

by:GhostInTheMacheen
Comment Utility
Sorry about that, lately I've been using image files for swap, which do need to be passed as arguments to swapon/swapoff.

Since you only have one swap partition, just go with this to disable "all":
# swapoff -a

Open in new window

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 3

Expert Comment

by:GhostInTheMacheen
Comment Utility
From the image you posted it looks like /dev/hda1 does start at the first cylinder, so that makes things simple. You'll just pass '1' as your starting cylinder argument when creating the new partition.

Looks like you'll need to delete /dev/hda2 as well, which appears to be an extended partition being used as swap.

Your last cylinder for /dev/hda1 should probably be '123752' (as you have 124014 cylinders total -- subtracting 262 cylinders for the swap).

Then, when you go to create the swap, just use the remaining space on the disk.
0
 
LVL 3

Expert Comment

by:GhostInTheMacheen
Comment Utility
By the way, kinda odd to see a VM with 1TB of storage space but only 2GB of RAM allocated to it ;)

I'm used to seeing hefty web server allocations (like 32GB of RAM and up).
0
 
LVL 3

Expert Comment

by:GhostInTheMacheen
Comment Utility
As you mentioned you can use a Gparted LiveCD, it's probably the easiest way to go, as you can point and click your way through moving the partitions around.

You can even tell it to create the swap as 2GB at the end of the disk before resizing hda1. And with it's "Resize" right click option you can bypass the manual deletion and setting of cylinders.

If you have the time to learn, doing it "the hard way" can be a good learning experience, but if you're in an office setting, just pop in Gparted, spend the 5 minutes making the changes, and move on with your day =)
0
 

Author Comment

by:stephenmiller
Comment Utility
Hi, thanks again for the replies.  In GParted when I select to resize /dev/sda1 it states that it is already at the maximum size.  I'm not able to increase it's size from the unallocated space.
0
 
LVL 3

Accepted Solution

by:
GhostInTheMacheen earned 500 total points
Comment Utility
Did you move/delete the trailing partitions before attempting the resize? Remember that the partition must be one continuous block.

Based on your cfdisk output I've been assuming an ext3 filesystem which supports at least a 2TB partition size, even if you are only using a 1K block size. Assuming the more standard 4K block size, you ought to be able to resize up to 16TB (if you had the disk space). If it were ext4 you could go higher still.

Based on the cylinder size it looks like you're only using about 125GB for the partition so far.
0
 

Author Comment

by:stephenmiller
Comment Utility
I decided to make a new partition to use as a data store, then encountered issues with the network connectivity completely stopping.  I decided the better option was to uninstall Hyper-V and use VirtualBox, which allowed for the full use of the partition during the ubuntu install.
0

Featured Post

NetScaler Deployment Guides and Resources

Citrix NetScaler is certified to support many of the most commonly deployed enterprise applications. Deployment guides provide in-depth recommendations on configuring NetScaler to meet specific application requirements.

Join & Write a Comment

Exchange server is not supported in any cloud-hosted platform (other than Azure with Azure Premium Storage).
Will try to explain how to use the VMware feature TAGs in the VMs and create Veeam Backup Jobs using TAGs. Since this article is too long, I will create second article for the Veeam tasks.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to install and configure Citrix XenApp 6.5 - Part 1. In this video tutorial we have explained step by step installation of Citrix XenApp 6.5 Server on Windows Server 2008 R2 is explained in this video. We have explained the difference between…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now