Talk:Expanding Partitions

From Alteeve Wiki
Jump to navigation Jump to search

The following is a drafting board for future additions.



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