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>..." |
|||
Line 159: | Line 159: | ||
lvdisplay | lvdisplay | ||
lvextend -i amount (100%PVG for example) /path/to/dev, | 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 | |||
== Modifying Primary and Extended Partitions == | == Modifying Primary and Extended Partitions == |
Revision as of 01:12, 27 November 2015
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 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
$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 existance 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.
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
Modifying Primary and Extended Partitions
Linux has access to a fantastic utility for managing storage volumes, parted. There is also a graphical interface, gparted. If possible, let's use that. Open up a terminal and check if it's installed.
NOTE: For some Red-Hat based distros, gparted is availble from the EPEL repository. Be careful when enabling new repositories. Some (like EPEL and RPMforge) are mutually exclusive. Do your research before enabling one.
sudo gparted, you should now see the unallocated space.
To add space to a partition THAT ISN'T MOUNTED AS ROOT '/', unmount the partition (make sure everything that is using that partition is closed/offline) and right click it's entry. Select 'resize/move' and follow the dialogs.
Unfortunately, we know that the encrypted partition /dev/vda3 is our root device, and it is certainly mounted (even if you see a warning sign implying it's encrypted). We can't modify mounted filesystems, so we'll have to get our VM to boot without touching /. The easiest way to do this is to boot using a LiveCD. Were this a bare metal machine, and not a virtual one, that would be as simple as inserting a CD and rebooting. In our case, we'll need to get our VM to locate an .iso file on the Anvil! to boot from. Two methods of doing so are the preferred route of accessing your Striker! dashboard and having it 'insert' the ISO, or by having your Anvil! administrator intervene.
= Using your Striker! to insert an ISO image
TODO
Administrator Intervention to insert an ISO image
In lieu of a physical DVD to insert into a drive, we can edit a Virtual Machine's definition file to tell it to boot off it's "cdrom" drive, and list a location of the iso that it will find there. To ensure their accessibility, we put definition files for VMs on Anvil! machines in /shared/definitions. Likewise, the boot media we'll be using will be at /shared/files. Any LiveCD with access to gparted will suffice, but the gparted project itself offers a LiveCD specifically for this use at http://gparted.org/download.php. Download it, and make it accessible in /shared/files before continuing.
Once we have access to the iso, we have to edit the definition XML file found at /shared/definitions/path-to-your-vm-definition.xml. We will have to add a boot clause to tell the VM to choose the cdrom drive to boot from first, and then add a source to the cdrom itself to point it towards our ISO.
vim /shared/definitions/your-vm-definition.xml <domain type='kvm' id='4'> <name>vm01-centos6_6</name> <uuid>be60c0d9-eb9d-31b3-db5c-e90f00335f33</uuid> <memory unit='KiB'>2097152</memory> <currentMemory unit='KiB'>2097152</currentMemory> <vcpu placement='static'>2</vcpu> <os> <type arch='x86_64' machine='rhel6.6.0'>hvm</type> <boot dev='cdrom'/> ### Let's add the 'cdrom' device here, above our hard drive entry so it is looked at first <boot dev='hd'/>
-SNIPPED-
<disk type='block' device='cdrom'> <driver nayme='qemu' type='raw'/> <target dev='hdc' bus='ide'/> <source dev='/shared/files/path-to-iso.iso'/> ### And add our source iso. <readonly/> <alias name='ide0-1-0'/> <address type='drive' controller='0' bus='1' target='0' unit='0'/> </disk>
Done. Shut the VM down, and bring it up again. When you log into the VM, it should have booted from the LiveCD.
NOTE: Remember to remove these two lines after you are done with the LiveCD, else the VM will continue to boot into the ISO and not it's own drive!
Resizing non-LVM partitions using gparted:
Hard drive partitions, even those on virtual hardware, operate similar to a book. There is a first page, a second, and so on until the end. Each page, or 'block', holds a number of words (bytes, in this case). Primary partitions on a hard drive can be thought of as chapters of a book. If you wanted to add pages to chapter 1 of your book, you couldn't just tack the extra pages to the end of the book, they would need to be inserted with the chapter they were meant for. Given that we have essentially just tacked on extra pages with our lvextend command, we'll now have to shuffle the partition around so it makes sense to the VM.
To do this, we'll have to unmount any partitions that we will be manipulating, and then shuffle the free space next to the partition we want to incorporate it. We will do this with an application called gparted.
Expanding an encrypted, non-LVM volume
If you wish to resize an /encrypted/ volume, the process becomes a little more convoluted, but follows the same principles. As before, if the partition you'd like to resize is your root partition, you'll need to reboot into a livecd. If the target partition isn't root, ensure it's unmounted. Once your partition is unmounted, or your VM rebooted into a LiveCD environment, we'll need to make sure the linux kernel has the appropriate module loaded to handle encrypted disks.
modprobe dm-crypt
Next we'll need to unlock the drive, and create an object in /dev/mapper/ which we can then manipulate like a filesystem. Afterwards, we tell Linux to rescan volume groups, and apply any changes to ensure that /dev/mapper/crypt1 is accessible.
sudo cryptsetup luksOpen /dev/yourdevice crypt1 Enter encryption password sudo vgscan --mknodes sudo vgchange -ay
Unfortunately, gparted won't help us deal with encrypted volumes. We're going to have to use fdisk, a more base-level utility to do so. The method of growing a partition in fdisk is less elegant than in parted. We need to delete the partition, and then recreate it beginning at the same block as before, and including the newly added space.
First, launch fdisk.
$ fdisk
fdisk presents itself as a shell in which you can input commands. 'm' prints a list of possible actions to choose from. For our purpose, let's print the current partition table, with 'p'. It should print something similar to this:
Disk /dev/vda: 63.2 GB, 63166218240 bytes 16 heads, 63 sectors/track, 122392 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000980e3 Device Boot Start End Blocks Id System /dev/vda1 * 3 1043 524288 83 Linux Partition 1 does not end on cylinder boundary. /dev/vda2 1043 9365 4194304 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/vda3 9365 122393 56966144 83 Linux Partition 3 does not end on cylinder boundary.
We can see that we have three partitions. We know that our encrypted partition is on /dev/vda3, which is the third entry. Let's keep that in mind, as fdisk requests entry numbers for it's operations, not the device name or path.
It is also important to note that /dev/vda3 is at the end of the partition table. This makes things easy for us. We simply have to delete the partition, then recreate it using all the available size, and don't have to worry about shuffling space between partitions.
Next, we'll delete partition 3, with 'd', and '3' when requested. 'n' and '3' will begin a new partition. Fdisk will ask for input on beginning and end blocks. Hit enter when requested for a beginning block - you want it to start the partition exactly where it did last time (or else data will be lost!). If you don't wish to add all the new volume space to /dev/sda3, input the end block you'd like (ensure it's larger than it's initial size, or again, you'll lose data), or else just hit enter again to select the default - all the remaining blocks. After you've created the new partition, write the changes to disk with 'w', which will also exit fdisk, and reboot your LiveCD.
Now that we've created a larger partition, we'll need to grow the encrypted layer surrounded your partition. Again booting into the LiveCD, we'll need to repeat some of the steps to make the encrypted partition accessible.
sudo cryptsetup luksOpen /dev/yourdevice crypt1 Enter encryption password sudo vgscan --mknodes sudo vgchange -ay
We'll use the regular tools available to expand the partition. Assuming an EXT3/4 partition, we'll use the following. First, we must check the filesystem, then we will resize the fs to the size of the volume.
sudo e2fsck /dev/mapper/crypt1 sudo resize2fs -p /dev/mapper/crypt1
The filesystem should now be ready to go. If you had modified your VM's xml file in /shared/definitions/ to allow it to boot from a LiveCD, remove the two lines added now, and restart the VM service.
Expanding an encrypted, LVM volume
If the encrypted volume contained an LVM with further partitions, we would have to instead enlarge the physical volume within the VM, then the logical volume, and then resize the filesystem within.
--TESTING--
sudo cryptsetup luksOpen /dev/yourdevice crypt1 Enter encryption password sudo vgscan --mknodes sudo vgchange -ay sudo pvresize /dev/mapper/crypt1 sudo pvchange -x y /dev/mapper/crypt1 lvresize -L100%PVG /dev/path????? sudo pvchange -x n /dev/mapper/crypt1 sudo e2fsck -f /dev/mapper/??? sudo resize2fs -p /dev/mapper/sameasabove???
Resizing Partitions in a Windows environment
TODO