5

I created a new Ubunutu 18.04.1 LTS virtual machines using Hyper-V's 'Quick Create' option however the virtual machine only had 20gb allocated and I had to use a bunch of linux partition tools to increase it to 40gb.

Is there any way to specify disk size on creation?

2 Answers2

7

This worked for me, didn't need to disable checkpoints. Thanks to Anton Karl Ingason for his blog-post

Note that this doesn't solve the exact presented problem "on creation" but this might be even better - as this can be done at any point after the installation while other "regular non HyperV" methods didn't work for me.

These steps fix the problem:

  1. Turn off the VM.
  2. Use Hyper-V Manager to select the Settings of the Virtual Machine, select the Hard Drive option and Edit under Virtual hard disk. (If this option is disabled, you need to go back and delete any checkpoints for the VM in the Hyper-V Manager; just select the VM and right click the checkpoint in the checkpoint field below.)
  3. Use the GUI to expand the drive to something reasonable, like 128 GB. Ubuntu now has space to expand into.
  4. Start the VM again. Install Guest Utils: sudo apt install cloud-guest-utils
  5. Expand the sda1 partition into the free space: sudo growpart /dev/sda 1 (Note the space between sda and 1!)
  6. Finally run resize2fs: sudo resize2fs /dev/sda1 (No space between sda and 1 here!)
  7. Now your Ubuntu drive is 128 GB.

Illustration

Willy
  • 81
  • 1
    Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change. – DavidPostill Nov 01 '20 at 08:24
5

There's no option to specify disk size; however, before OS installation, there's a way to configure that by following steps:

  1. Perform quick create normally until it prompts you for "Connect" / "Edit Settings"
  2. Click on "Edit Settings"
  3. Go to Hard drive (on left pane)
  4. Click "Edit" (on right pane)
  5. Click expand and provide desired size.
  • Hyper-V Quick Create downloads a complete VM with preinstalled OS. What you’re suggesting unfortunately does not apply. – Daniel B May 17 '19 at 12:29
  • 2
    Once disk is expanded, you will have to either resize the partition /dev/sda1 by using the free space available in disk or create new partition using the free space. Either Ubuntu's disk utility or gparted utility can help updating the partition. – Nilay Shah May 18 '19 at 10:17