GM
833
0
Guides

A guide to extending Homestead storage capacity

Posted 1 year ago by GM

If you're anything like me. You have a massive database or file system for which the default 64GB isn't enough. Personally I use valet to develop, and homestead as a test environment; allowing me to keep my users away from yet to be released updates. This is a rough guide to extending Homestead's disk. As always, backup, backup, backup.

Halt the virtual machine

$ homestead halt

Locate the VirtualBox VM and the HDD attached to its SATA Controller.

$ cd ~/VirtualBox\ VMs/homestead-7
$ VBoxManage showvminfo | grep ".vdi"
     
SATA Controller (0, 0): /Volumes/LaCie/VirtualBox VMs/homestead-7/ubuntu-16.04-amd64-disk001.vdi (UUID: de5669b5-3bd8-420e-8bf3-15e992dbeb20)

you can see here that I have moved my vdi to a new volume already

Backup your VDI

$ cd /Volumes/LaCie/VirtualBox VMs/homestead-7/
$ cp ubuntu-16.04-amd64-disk001.vdi ubuntu-16.04-amd64-disk001.backup-3-Apr-18

Check the disk space already allocated

$ VBoxManage showhdinfo
UUID:           de5669b5-3bd8-420e-8bf3-15e992dbeb20
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       /Volumes/LaCie/VirtualBox VMs/homestead-7/ubuntu-16.04-amd64-disk001.vdi
Storage format: VDI
Format variant: dynamic default
Capacity:       131072 MBytes
Size on disk:   4723 MBytes
Encryption:     disabled
In use by VMs:  homestead-7 (UUID: 1cc1848e-2441-4c9d-93fb-48fd3f4e7ae9)

Resize the cloned disk to give it more space (size argument below is given in Megabytes)

$ VBoxManage modifyhd "ubuntu-16.04-amd64-disk001.vdi" --resize 1024000
$ VBoxManage showhdinfo "ubuntu-16.04-amd64-disk001.vdi" 
UUID:           de5669b5-3bd8-420e-8bf3-15e992dbeb20
Parent UUID:    base
State:          created
Type:           normal (base)
Location:       /Volumes/LaCie/VirtualBox VMs/homestead-7/ubuntu-16.04-amd64-disk001.vdi
Storage format: VDI
Format variant: dynamic default
Capacity:       1024000 MBytes
Size on disk:   4726 MBytes
Encryption:     disabled
In use by VMs:  homestead-7 (UUID: 1cc1848e-2441-4c9d-93fb-48fd3f4e7ae9)

Boot the virtual machine, open a command line and sudo to root and check the free disk space and the logical volume mapping the file-system is on

$ homestead up
Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Checking if box 'laravel/homestead' is up to date...

$ homestead ssh
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-116-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

0 packages can be updated.
0 updates are security updates.

Last login: Mon Apr  2 22:36:18 2018 from 10.0.2.2
[email protected]:~$ sudo su -
[email protected]:~# df -k
Filesystem                    1K-blocks      Used  Available Use% Mounted on
udev                            1003816         0    1003816   0% /dev
tmpfs                            204824      5628     199196   3% /run
/dev/mapper/vagrant--vg-root   62G  5.3G   54G   9% /
tmpfs                           1024100         8    1024092   1% /dev/shm
tmpfs                              5120         0       5120   0% /run/lock
tmpfs                           1024100         0    1024100   0% /sys/fs/cgroup
/dev/sda1                        482922    108271     349717  24% /boot
vagrant                       244912536 200936428   43976108  83% /vagrant
tmpfs                            204824         0     204824   0% /run/user/10001

Here you can see that /dev/mapper/vagrant--vg-root is only 62G in size. This is what we are going to extend.

Check the name of the physical volume (or device) that all the partitions are created on. This should be /dev/sda...

[email protected]:~# fdisk -l
Disk /dev/sda: 1000 GiB, 1073741824000 bytes, 2097152000 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
Disklabel type: dos
Disk identifier: 0x9b1f401f
Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048    999423    997376  487M 83 Linux
/dev/sda2       1001470 134215679 133214210 63.5G  5 Extended
/dev/sda5       1001472 134215679 133214208 63.5G 8e Linux LVM

Disk /dev/mapper/vagrant--vg-root: 62.5 GiB, 67129835520 bytes, 131112960 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 /dev/mapper/vagrant--vg-swap_1: 1 GiB, 1073741824 bytes, 2097152 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

OK we now have all of the information we need. Now we can go and create a new primary partition for use as a Linux LVM. This was the point that caused me no end of grief until I realised that the fdisk process will need to create TWO partitions. The first is padding the pre-existing partition to where the start of the second begins.

Create the padding partition: a. Press p to print the partition table to identify the number of partitions. By default there are two - sda1 and sda2.

[email protected]:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p
Disk /dev/sda: 1000 GiB, 1073741824000 bytes, 2097152000 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
Disklabel type: dos
Disk identifier: 0x9b1f401f

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048    999423    997376  487M 83 Linux
/dev/sda2       1001470 134215679 133214210 63.5G  5 Extended
/dev/sda5       1001472 134215679 133214208 63.5G 8e Linux LVM
b. Press n to create a new primary partition.
c. Press p for primary.
Command (m for help): n
Partition type
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): p
d. Press 3 for the partition number. Press Enter two times to accept the default First and Last cylinder.
Partition number (3,4, default 3): 
First sector (999424-2097151999, default 999424): 
Last sector, +sectors or +size{K,M,G,T,P} (999424-1001469, default 1001469): 

Created a new partition 3 of type 'Linux' and of size 1023 KiB.

That's the padding partition done.

Create the new extension partition: Rinse and repeat step 8 and you'll get a new much larger partition.

Command (m for help): p
Disk /dev/sda: 1000 GiB, 1073741824000 bytes, 2097152000 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
Disklabel type: dos
Disk identifier: 0x9b1f401f

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048    999423    997376  487M 83 Linux
/dev/sda2       1001470 134215679 133214210 63.5G  5 Extended
/dev/sda3        999424   1001469      2046 1023K 83 Linux
/dev/sda5       1001472 134215679 133214208 63.5G 8e Linux LVM

Partition table entries are not in disk order.

Command (m for help): n
Partition type
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): p

Selected partition 4
First sector (134215680-2097151999, default 134215680): 
Last sector, +sectors or +size{K,M,G,T,P} (134215680-2097151999, default 2097151999): 

Created a new partition 4 of type 'Linux' and of size 936 GiB.

Command (m for help): p
Disk /dev/sda: 1000 GiB, 1073741824000 bytes, 2097152000 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
Disklabel type: dos
Disk identifier: 0x9b1f401f

Device     Boot     Start        End    Sectors  Size Id Type
/dev/sda1  *         2048     999423     997376  487M 83 Linux
/dev/sda2         1001470  134215679  133214210 63.5G  5 Extended
/dev/sda3          999424    1001469       2046 1023K 83 Linux
/dev/sda4       134215680 2097151999 1962936320  936G 83 Linux
/dev/sda5         1001472  134215679  133214208 63.5G 8e Linux LVM

Partition table entries are not in disk order.

At this stage, you can go ahead and remove the padding partition if you want

Command (m for help): d
Partition number (1-5, default 5): 3

Partition 3 has been deleted.

Now we need to change the type of partition. Press t to change the system's partition ID. Press 4 to select the newly created extension partition and type 8e to change the Hex Code of the partition for Linux LVM

Command (m for help): t
Partition number (1,2,4,5, default 5): 4
Partition type (type L to list all types): 8e

Changed type of partition 'Empty' to 'Linux LVM'.

Press w to write the changes to the partition table.

The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 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(8) or kpartx(8).

Now we need to reboot and re-login and re-open the root shell.

[email protected]:~#  reboot
Connection to 127.0.0.1 closed by remote host.
Connection to 127.0.0.1 closed.
$ homestead ssh
[email protected]:~$ sudo su -

Create a new physical volume using the new primary partition just created

[email protected]:~# pvcreate /dev/sda
    Physical volume "/dev/sda4" successfully created

Extend the Volume Group to use the newly created physical volume.

[email protected]:~# vgextend vagrant-vg /dev/sda4
    Volume group "vagrant-vg" successfully extended

Extend the Logical Volume to use all of the available Volume Group storage we just extended

[email protected]:~# lvextend -l +100%FREE /dev/mapper/vagrant--vg-root
  Size of logical volume vagrant-vg/root changed from 62.52 GiB (16005 extents) to 998.52 GiB (255621 extents).
  Logical volume root successfully resized.

Resize the file system to use up the space made available in the Logical Volume

[email protected]:~# resize2fs /dev/mapper/vagrant--vg-root
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mapper/vagrant--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 63
The filesystem on /dev/mapper/vagrant--vg-root is now 261755904 (4k) blocks long.

Verify that the additional space is now available.

[email protected]:~# df -h
Filesystem                    Size  Used Avail Use% Mounted on
udev                          981M     0  981M   0% /dev
tmpfs                         201M  5.5M  195M   3% /run
/dev/mapper/vagrant--vg-root  983G  5.3G  937G   1% /
tmpfs                        1001M  8.0K 1001M   1% /dev/shm
tmpfs                         5.0M     0  5.0M   0% /run/lock
tmpfs                        1001M     0 1001M   0% /sys/fs/cgroup
/dev/sda1                     472M  106M  342M  24% /boot
tmpfs                         201M     0  201M   0% /run/user/1000

Looks good! Now is probably a good time to reboot and backup your VM again.

Please sign in or create an account to participate in this conversation.