Forked from christopher-hopper/vm-resize-hard-disk.md
Last active
April 24, 2021 06:21
-
-
Save miraleung/5fe18f7d68994024862a to your computer and use it in GitHub Desktop.
Revisions
-
miraleung revised this gist
Jun 25, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -126,7 +126,7 @@ Steps to resize the hard disk # fdisk /dev/sda 1.Press `t` to change the system's partition ID 1. Press `3` (or the number of the last partition in the above table) to select the newly created partition 1. Type `8e` to change the Hex Code of the partition for `Linux LVM` 1. Press `w` to write the changes to the partition table. -
miraleung revised this gist
Jun 25, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -78,8 +78,8 @@ Steps to resize the hard disk 3. Install `gparted` if needed # apt-get update # apt-get install gparted 3. Create a new primary partition for use as a Linux LVM -
miraleung revised this gist
Jun 24, 2015 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -94,8 +94,8 @@ Steps to resize the hard disk 1. Type `print` to check that the appropriate changes have been made. 1. Type `quit` to exit gparted. You should see something like this: ``` GNU Parted 2.3 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. @@ -119,7 +119,7 @@ Steps to resize the hard disk 2 257MB 8589MB 8332MB extended 5 257MB 8589MB 8332MB logical lvm 3 8589MB 20.0GB 11.4GB primary ``` 3. Create a new primary partition for use as a Linux LVM -
miraleung revised this gist
Jun 24, 2015 . 1 changed file with 23 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -96,29 +96,29 @@ Steps to resize the hard disk You should see something like this: ``` GNU Parted 2.3 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mkpart Partition type? primary/logical? p File system type? [ext2]? ext3 Start? 4295 End? 20GB Warning: You requested a partition from 4295MB to 20.0GB. The closest location we can manage is 8589MB to 20.0GB. Is this still acceptable to you? Yes/No? Yes (parted) print Model: ATA VBOX HARDDISK (scsi) Disk /dev/sda: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 256MB 255MB primary ext2 boot 2 257MB 8589MB 8332MB extended 5 257MB 8589MB 8332MB logical lvm 3 8589MB 20.0GB 11.4GB primary ``` 3. Create a new primary partition for use as a Linux LVM -
miraleung revised this gist
Jun 24, 2015 . 1 changed file with 51 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ Added gparted instructions to extend the virtual disk to fork from christopher-hopper/vm-resize-hard-disk.md. Resize a Hard Disk for a Virtual Machine ======================================== @@ -42,9 +44,9 @@ Steps to resize the hard disk # VboxManage showhdinfo "clone-disk1.vdi" 3. Resize the cloned disk to give it more space. The size argument below is given in Megabytes (1024 Bytes = 1 Megabyte). Because this disk was created using _dynamic allocation_ I'm going to resize it to 20 GB. # VBoxManage modifyhd "clone-disk1.vdi" --resize 20480 _NOTE: If the disk was created using_ dynamic allocation _(see previous step) then the_ physical size _of the disk will not need to match its_ logical size _- meaning you can create a very large logical disk that will increase in physical size only as space is used._ @@ -54,7 +56,7 @@ Steps to resize the hard disk 3. Attach the newly resized disk to the SATA Controller of the Virtual Machine. # VBoxManage storageattach mybox_default_1382400620 --storagectl "SATA" --port 0 --device 0 --type hdd --medium clone-disk1.vdi 3. Reboot the Virtual Machine using Vagrant. @@ -74,21 +76,60 @@ Steps to resize the hard disk # fdisk -l 3. Install `gparted` if needed # sudo apt-get update # sudo apt-get install gparted 3. Create a new primary partition for use as a Linux LVM # parted 1. `mkpart` 1. Press `p` for primary. 1. Type `ext3` for the file system type. 1. Type 4295 (or some arbitrary low number) for the starting block. Gparted will select the next closest block and ask for confirmation. 1. Type `20GB` as the ending block (or the max size the virtual disk was resized to earlier). 1. Type `Yes` to confirm the start and end block selection. 1. Type `print` to check that the appropriate changes have been made. 1. Type `quit` to exit gparted. You should see something like this: ``` GNU Parted 2.3 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mkpart Partition type? primary/logical? p File system type? [ext2]? ext3 Start? 4295 End? 20GB Warning: You requested a partition from 4295MB to 20.0GB. The closest location we can manage is 8589MB to 20.0GB. Is this still acceptable to you? Yes/No? Yes (parted) print Model: ATA VBOX HARDDISK (scsi) Disk /dev/sda: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 256MB 255MB primary ext2 boot 2 257MB 8589MB 8332MB extended 5 257MB 8589MB 8332MB logical lvm 3 8589MB 20.0GB 11.4GB primary ``` 3. Create a new primary partition for use as a Linux LVM # fdisk /dev/sda 1.Press `t` to change the system's partition ID 1. Press `3` to select the newly creation partition 1. Type `8e` to change the Hex Code of the partition for `Linux LVM` 1. Press `w` to write the changes to the partition table. 3. Reboot the machine, then ssh back in when it is up again and switch to the root user once more. # reboot -
christopher-hopper revised this gist
Apr 7, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -127,5 +127,5 @@ Steps to resize the hard disk # exit # exit # vagrant reload --provision -
christopher-hopper revised this gist
Apr 7, 2014 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -123,8 +123,9 @@ Steps to resize the hard disk # df -h 3. A restart of the VM using vagrant may be a good idea here, to ensure that all services are running correctly now that there is more space available. Exit the root user, exit the vagrant user and ssh session, then tell vagrant to restart the machine. # exit # exit # vagrant reload -
christopher-hopper revised this gist
Apr 7, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -89,10 +89,11 @@ Steps to resize the hard disk 1. Press `w` to write the changes to the partition table. 3. Reboot the machine, then ssh back in when it is up again and switch to the root user once more. # reboot # vagrant ssh # sudo su - 3. Create a new physical volume using the new primary partition just created. -
christopher-hopper revised this gist
Apr 7, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -82,7 +82,7 @@ Steps to resize the hard disk 1. Press `n` to create a new primary partition. 1. Press `p` for primary. 1. Press `3` for the partition number, depending the output of the partition table print. 1. Press Enter two times to accept the default First and Last cylinder. 1. Press `t` to change the system's partition ID 1. Press `3` to select the newly creation partition 1. Type `8e` to change the Hex Code of the partition for `Linux LVM` -
christopher-hopper revised this gist
Apr 7, 2014 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,16 @@ Steps to resize the hard disk # cd provisioning/boxes/mybox # vagrant halt 2. Locate the VirtuaBox VM and the HDD attached to its SATA Controller. In this instance we're assuming the VM is located in the default location and is named `mybox_default_1382400620`. # cd ~/VirtualBox\ VMs/mybox_default_1382400620 # VBoxManage showvminfo mybox_default_1382400620 | grep ".vmdk" The `showvminfo` command should show you the location on the file-system of the HDD of type VMDK along with the name of the Controller it is attached to - it will look something like this: SATA Controller (0, 0): C:\Users\user.name\VirtualBox VMs\mybox_default_1382400620\box-disk1.vmdk (UUID: 2f79610e-6c06-46d5-becb-448386ea40ec) 3. clone the VMDK type disk to a VDI type disk so it can be resized. # cd ~/VirtualBox\ VMs/mybox_default_1382400620 # VBoxManage clonehd "box-disk1.vmdk" "clone-disk1.vdi" --format vdi -
christopher-hopper revised this gist
Apr 7, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,6 +11,7 @@ The following steps assume you've got a set-up like mine, where: - you use a Cygwin or Linux command-line terminal on your host machine - the VirtualBox install path is in your Windows (and therefore Cygwin bash) PATH environment variable - the vagrant boxes live at the path `provisioning/boxes/mybox` - your Cygwin `HOME` path is the same as your Windows `%USERPROFILE%` (see [How do I change my Cygwin HOME folder after installation](http://stackoverflow.com/questions/1494658/how-can-i-change-my-cygwin-home-folder-after-installation/11182877#11182877)) - VirtualBox creates new Virtual Machines in the default location `~/VirtualBox\ VMs/` Steps to resize the hard disk -
christopher-hopper created this gist
Mar 25, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,119 @@ Resize a Hard Disk for a Virtual Machine ======================================== Our Virtual Machines are provisioned using Vagrant from a Linux base box to run using VirutalBox. If the Hard Disk space runs out and you cannot remove files to free-up space, you can resize the Hard Disk using some VirtualBox and Linux commands. Some assumptions ---------------- The following steps assume you've got a set-up like mine, where: - you use a Cygwin or Linux command-line terminal on your host machine - the VirtualBox install path is in your Windows (and therefore Cygwin bash) PATH environment variable - the vagrant boxes live at the path `provisioning/boxes/mybox` - VirtualBox creates new Virtual Machines in the default location `~/VirtualBox\ VMs/` Steps to resize the hard disk ----------------------------- 1. Stop the virtual machine using Vagrant. # cd provisioning/boxes/mybox # vagrant halt 2. Locate the VirtuaBox VM and clone the VMDK type disk to a VDI type disk so it can be resized. # cd ~/VirtualBox\ VMs/mybox_default_1382400620 # VBoxManage clonehd "box-disk1.vmdk" "clone-disk1.vdi" --format vdi _NOTE: We do this because VMDK type disks cannot be resized by VirtualBox. It has the added benefit of allowing us to keep our original disk backed-up during the resize operation._ 3. Find out how big the disk is currently, to determine how large to make it when resized. The information will show the current size and the Format variant. If Dynamic Allocation was used to create the disk, the Format variant will be "dynamic default". # VboxManage showhdinfo "clone-disk1.vdi" 3. Resize the cloned disk to give it more space. The size argument below is given in Megabytes (1024 Bytes = 1 Megabyte). Because this disk was created using _dynamic allocation_ I'm going to resize it to 1 Terabyte. # VBoxManage modifyhd "clone-disk1.vdi" --resize 1048576 _NOTE: If the disk was created using_ dynamic allocation _(see previous step) then the_ physical size _of the disk will not need to match its_ logical size _- meaning you can create a very large logical disk that will increase in physical size only as space is used._ 3. Find out the name of the SATA Storage Controller to attach the newly resized disk to. # VBoxManage showvminfo mybox_default_1382400620 | grep "Storage" 3. Attach the newly resized disk to the SATA Controller of the Virtual Machine. # VBoxManage storageattach mybox_default_1382400620 --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium clone-disk1.vdi 3. Reboot the Virtual Machine using Vagrant. # cd provisioning/boxes/mybox # vagrant up 3. Open a command-line shell as root on the Virtual Machine via ssh. # vagrant ssh # sudo su - 3. Find the name of the logical volume mapping the file-system is on (ie. `/dev/mapper/VolGroupOS-lv_root`). # df 4. Find the name of the physical volume (or device) that all the partitions are created on (ie. `/dev/sda`). # fdisk -l 3. Create a new primary partition for use as a Linux LVM # fdisk /dev/sda 1. Press `p` to print the partition table to identify the number of partitions. By default there are two - `sda1` and `sda2`. 1. Press `n` to create a new primary partition. 1. Press `p` for primary. 1. Press `3` for the partition number, depending the output of the partition table print. 1. Press Enter two times. 1. Press `t` to change the system's partition ID 1. Press `3` to select the newly creation partition 1. Type `8e` to change the Hex Code of the partition for `Linux LVM` 1. Press `w` to write the changes to the partition table. 3. Reboot the machine and ssh back in when it is up again. # reboot # vagrant ssh 3. Create a new physical volume using the new primary partition just created. # pvcreate /dev/sda3 3. Find out the name of the Volume Group that the Logical Volume mapping belongs to (ie. `VolGroupOS`). # vgdisplay 3. Extend the Volume Group to use the newly created physical volume. # vgextend VolGroupOS /dev/sda3 3. Extend the logical volume to use more of the Volume Group size now available to it. You can either tell it to use all the space available on the Volume Group: # lvextend -l +100%FREE /dev/mapper/VolGroupOS-lv_root Or, if you want to control the growth of the Disk, extend it to add a set amount of space in Megabytes, Gigabytes or Terabytes: # lvextend -L+20G /dev/mapper/VolGroupOS-lv_root 3. Resize the file-system to use up the space made available in the Logical Volume # resize2fs /dev/mapper/VolGroupOS-lv_root 3. Verfiy that there is now more space available # df -h 3. A restart of the VM using vagrant may be a good idea here, to ensure that all services are running correctly now that there is more space available. # exit # vagrant halt # vagrant up