Expanding Partitions: Difference between revisions
(Created page with "Expanding an EXT3\4 logical partition on an ANVIL! = For Anvil! Administrators = Expanding a VM's storage allocation from the commandline is a simple process. It <i>will</i>...") |
|||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The goal of this document is to walk the user through expanding a partition on an Anvil! device in the field, including expanding the filesystem within the VM once space has been allocated. | |||
'''NOTE: Whenever you modify partitions, always always ALWAYS make sure you have current backups of the data. Mistakes happen, the power goes out, coffees are spilled. Back that data up.''' | |||
= For Anvil! Administrators = | = For Anvil! Administrators = | ||
Line 5: | Line 8: | ||
Expanding a VM's storage allocation from the commandline is a simple process. It <i>will</i> require the VM to be restarted, please ensure the service user understands that there will be a short stop in service. | Expanding a VM's storage allocation from the commandline is a simple process. It <i>will</i> require the VM to be restarted, please ensure the service user understands that there will be a short stop in service. | ||
The first step is to ensure there is enough space available in the physical volume group | The first step is to ensure there is enough space available in the physical volume group on the Anvil itself. This is critical as, of course, if there is no space available to be allocated to a VM, we can't expand it! | ||
<span class="code"> | <span class="code"> | ||
Line 143: | Line 147: | ||
</span> | </span> | ||
The VM should now see that there are 10GB of free space at the end of the volume. To partition that space and make it usable, the client may request additional intervention, depending on the | The VM should now see that there are 10GB of free space at the end of the volume. To partition that space and make it usable, the client may request additional intervention, depending on the existence and access to a Striker! dashboard. | ||
= For Anvil! VM Users = | = For Anvil! VM Users = | ||
Line 151: | Line 155: | ||
== Linux-based VMs == | == Linux-based VMs == | ||
What method of expanding your Linux partition you use depends on the set up of your machine. Generally speaking, either the space available to your VM will be partitioned using Logical Volume Management (LVM), or it will be devided into a series of Primary and Extended partitions. The benefits and drawbacks of each method are beyond the scope of this document. | What method of expanding your Linux partition you use depends on the set up of your machine. Generally speaking, either the space available to your VM will be partitioned using Logical Volume Management (LVM), or it will be devided into a series of Primary and Extended partitions. The benefits and drawbacks of each method are beyond the scope of this document. In either case, we'll be stuck rebuilding a Primary partition at least once, as LVM resides atop a partition. | ||
== Modifying Primary and Extended Partitions == | == Modifying Primary and Extended Partitions == | ||
Linux has access to a fantastic utility for managing storage volumes, parted | Linux has access to a fantastic utility for managing storage volumes, parted. Open up a terminal and check if it's installed. | ||
NOTE: For some Red-Hat based distros, | NOTE: For some Red-Hat based distros, parted is available from the EPEL repository. Be careful when enabling new repositories. Some (like EPEL and RPMforge) are mutually exclusive. Do your research before enabling one. | ||
Non-LVM based partitions require contiguous disk space to function. For example, they do not allow for data at the end of a drive to be added to the first partition if there is a second partition existing between it. To allocate our new space, we will need to shuffle any existing partitions around to make space for the desired size of each partition. | |||
Most default linux installs have a root, "/" partition, and space allocated to a swap file. In cases such as this, your job is fairly straightforward. | |||
Before any modification of the root filesystem can be done, it must be available in an unmounted state. To achieve that, we must boot the system from CD, USB key, etc. In an Anvil! environment, that can be achieved by accessing the Striker dashboard, selecting your Anvil, then VM, and changing it's boot device to a virtual CD-ROM. The image used as the 'disk' can also be selected from the VM management screen. Any LiveCD will work, though we recommend a Fedora LiveCD, which is available at https://getfedora.org/en_GB/workstation/download/. | |||
Once booted into the LiveCD environment, open a terminal and and enter <span="code">parted</span>. Remove the swap partition (located using the command <span="code"> print all </span>) via <span="code"> rm </code> and the partition's ID. | |||
As there is no way to "expand" a partition once created, we will have to delete the partition we wish to expand, then recreate it. The new partition <b>MUST</b> start at the same 'block' of the drive, or your data will be lost. This sounds frightening, but in practice it is relatively straightforward. | |||
<span | Begin by noting the 'Start' block of the device, as seen from the parted command <span="code"> print all </span>, then delete the partition by using <span="code> rm $yourpartition </span>. Once that is done, figure out what the end block will be by adding the Start block to your desired size, and create a new partition using the <span="code">mkpart $startblock $endblock</span> command. | ||
For example, if your drive layout was: | |||
* One 80 GB drive divided into: | |||
** A 512 MB /boot partition | |||
** a 30 GB / partition | |||
** and a 2048mb /swap partition | |||
And you wished to make / 50GB, you would need to delete the /swap partition, then delete the / partition, and recreate it with the start block as "512M" and the end block as "51712M" (as 50 gigabytes + 512 megabytes = 51712M). Then you would need to recreate your /swap partition. | |||
Once that is complete, <span="code">quit</span> parted, and reboot into your original OS. If you've created your root partition properly, it should boot as normal. | |||
== Modifying LVM partitions == | |||
The method used to extend an LVM partition in your VM is the same as the method used on the Anvil! itself, 'lvextend'. | |||
lvdisplay | |||
lvextend -i amount (100%PVG for example) /path/to/dev. | |||
Once the logical volume has been extended, the filesystem needs to be told about the extra space. Instructions to do so can be found [https://alteeve.ca/w/Expanding_Partitions#Extending_the_filesystem here]. | |||
== | == Extending the filesystem == | ||
Once your OS has booted, enter a shell and use the command appropriate to the filesystem to extend the filesystem over the new space. For EXT2/3/4, <span="code">extend2fs /dev/yourpartition</span> is the way to go. For XFS filesystems, <span="code">xfs_growfs</span> is correct. Your filesystem should now be the correct, new size. Job's done! |
Latest revision as of 19:06, 6 June 2016
The goal of this document is to walk the user through expanding a partition on an Anvil! device in the field, including expanding the filesystem within the VM once space has been allocated.
NOTE: Whenever you modify partitions, always always ALWAYS make sure you have current backups of the data. Mistakes happen, the power goes out, coffees are spilled. Back that data up.
For Anvil! Administrators
Expanding a VM's storage allocation from the commandline is a simple process. It will require the VM to be restarted, please ensure the service user understands that there will be a short stop in service.
The first step is to ensure there is enough space available in the physical volume group on the Anvil itself. This is critical as, of course, if there is no space available to be allocated to a VM, we can't expand it!
$pvdisplay
--- Physical volume --- PV Name /dev/drbd1 VG Name an-a05n02_vg0 PV Size 287.13 GiB / not usable 1.99 MiB Allocatable yes PE Size 4.00 MiB Total PE 73506 Free PE 73506 Allocated PE 0 PV UUID x4bkWj-UQup-W3Xb-egha-VB9X-bG93-e4wzGU --- Physical volume --- PV Name /dev/drbd0 VG Name an-a05n01_vg0 PV Size 504.96 GiB / not usable 2.18 MiB Allocatable yes PE Size 4.00 MiB Tolocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/an-a05n01_vg0/vm01-centos6_6 LV Name vm01-centos6_6 VG Name an-a05n01_vg0 LV UUID 1olier-t7TM-afvr-hOJU-7Nbo-MYzd-19g5mK LV Write Access read/write LV Creation host, time an-a05n01.alteeve.ca, 2015-08-06 15:04:53 -0400 LV Status available # open 1 LV Size 48.83 GiB Current LE 12500 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Path /dev/an-a05n01_vg0/vm02-win8_0 LV Name vm02-win8_0 VG Name an-a05n02_vg0 LV UUID tDYtcd-NAdJ-Q5Mk-PSCj-qL4q-ZJRT-3b6hWD LV Write Access read/write LV Creation host, time an-a05n01.alteeve.ca, 2015-08-10 11:36:03 -0400 LV Status available # open 0 LV Size 48.83 GiB Current LE 12500 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2
We can see that we have a /shared/ device and a centos 6.6 LV on one physical volume, and a Windows 8 VM on the other.
Let's extend our Centos partition, /dev/an-a05n01_vg0/vm01-centos6_6. DBRD offers us a very simple tool to do so, 'lvextend'. Using lvextend, we can either expand a partition by an amount, "-L +10G" to add ten gigabytes to a volume, or to a total size "-L 60G" to make the total size of the volume sixty gigabytes. Let's just add 10 gigs.
lvextend -L+1G /dev/an-a05n01_vg0/vm01-centos6_6 Size of logical volume an-a05n01_vg0/vm01-centos6_6 changed from 48.83 GiB (12500 extents) to 58.83 GiB (15060 extents). Logical volume vm01-centos6_6 successfully resized
And let's check the new size of the volume
$ lvdisplay
--- Logical volume --- LV Path /dev/an-a05n01_vg0/shared LV Name shared VG Name an-a05n01_vg0 LV UUID 66OdHC-7YDH-96yt-7CWk-wO2L-PHMy-4p6CZv LV Write Access read/write LV Creation host, time an-a05n01.alteeve.ca, 2015-08-06 12:34:12 -0400 LV Status available # open 1 LV Size 40.00 GiB Current LE 10240 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/an-a05n01_vg0/vm01-centos6_6 LV Name vm01-centos6_6 VG Name an-a05n01_vg0 LV UUID 1olier-t7TM-afvr-hOJU-7Nbo-MYzd-19g5mK LV Write Access read/write LV Creation host, time an-a05n01.alteeve.ca, 2015-08-06 15:04:53 -0400 LV Status available # open 0 LV Size 58.83 GiB Current LE 15060 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Path /dev/an-a05n01_vg0/vm02-win8_0 LV Name vm02-win8_0 VG Name an-a05n01_vg0 LV UUID tDYtcd-NAdJ-Q5Mk-PSCj-qL4q-ZJRT-3b6hWD LV Write Access read/write LV Creation host, time an-a05n01.alteeve.ca, 2015-08-10 11:36:03 -0400 LV Status available # open 1 LV Size 48.83 GiB Current LE 12500 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2
Yep, we're golden.
To get the VM to recognize the additional size, we'll need to shut the service down entirely, and then bring it back up. Take whatever steps needed to make sure no data is lost on the client VM before shutting it down.
$ clusvcadm -d vm:vm01-centos6_6 <OUTPUT> $ clusvcadm -e vm:vm01-centos6_6
The VM should now see that there are 10GB of free space at the end of the volume. To partition that space and make it usable, the client may request additional intervention, depending on the existence and access to a Striker! dashboard.
For Anvil! VM Users
Once additional space has been added to your VM, it must be partitioned to be usable. To do so, log in to your vm using virt-manager, or another suitable application. The specific method of partitioning space depends on your VM's operating system.
Linux-based VMs
What method of expanding your Linux partition you use depends on the set up of your machine. Generally speaking, either the space available to your VM will be partitioned using Logical Volume Management (LVM), or it will be devided into a series of Primary and Extended partitions. The benefits and drawbacks of each method are beyond the scope of this document. In either case, we'll be stuck rebuilding a Primary partition at least once, as LVM resides atop a partition.
Modifying Primary and Extended Partitions
Linux has access to a fantastic utility for managing storage volumes, parted. Open up a terminal and check if it's installed.
NOTE: For some Red-Hat based distros, parted is available from the EPEL repository. Be careful when enabling new repositories. Some (like EPEL and RPMforge) are mutually exclusive. Do your research before enabling one.
Non-LVM based partitions require contiguous disk space to function. For example, they do not allow for data at the end of a drive to be added to the first partition if there is a second partition existing between it. To allocate our new space, we will need to shuffle any existing partitions around to make space for the desired size of each partition.
Most default linux installs have a root, "/" partition, and space allocated to a swap file. In cases such as this, your job is fairly straightforward.
Before any modification of the root filesystem can be done, it must be available in an unmounted state. To achieve that, we must boot the system from CD, USB key, etc. In an Anvil! environment, that can be achieved by accessing the Striker dashboard, selecting your Anvil, then VM, and changing it's boot device to a virtual CD-ROM. The image used as the 'disk' can also be selected from the VM management screen. Any LiveCD will work, though we recommend a Fedora LiveCD, which is available at https://getfedora.org/en_GB/workstation/download/.
Once booted into the LiveCD environment, open a terminal and and enter <span="code">parted. Remove the swap partition (located using the command <span="code"> print all ) via <span="code"> rm and the partition's ID.
As there is no way to "expand" a partition once created, we will have to delete the partition we wish to expand, then recreate it. The new partition MUST start at the same 'block' of the drive, or your data will be lost. This sounds frightening, but in practice it is relatively straightforward.
Begin by noting the 'Start' block of the device, as seen from the parted command <span="code"> print all , then delete the partition by using <span="code> rm $yourpartition . Once that is done, figure out what the end block will be by adding the Start block to your desired size, and create a new partition using the <span="code">mkpart $startblock $endblock command.
For example, if your drive layout was:
- One 80 GB drive divided into:
- A 512 MB /boot partition
- a 30 GB / partition
- and a 2048mb /swap partition
And you wished to make / 50GB, you would need to delete the /swap partition, then delete the / partition, and recreate it with the start block as "512M" and the end block as "51712M" (as 50 gigabytes + 512 megabytes = 51712M). Then you would need to recreate your /swap partition.
Once that is complete, <span="code">quit parted, and reboot into your original OS. If you've created your root partition properly, it should boot as normal.
Modifying LVM partitions
The method used to extend an LVM partition in your VM is the same as the method used on the Anvil! itself, 'lvextend'.
lvdisplay
lvextend -i amount (100%PVG for example) /path/to/dev.
Once the logical volume has been extended, the filesystem needs to be told about the extra space. Instructions to do so can be found here.
Extending the filesystem
Once your OS has booted, enter a shell and use the command appropriate to the filesystem to extend the filesystem over the new space. For EXT2/3/4, <span="code">extend2fs /dev/yourpartition is the way to go. For XFS filesystems, <span="code">xfs_growfs is correct. Your filesystem should now be the correct, new size. Job's done!