I have been on the quest over the last 6 months to create a completely scalable Centos VM template for deployments.. This is not only to save my precious after hours and weekend time but to provide better uptime to my customers… Today I have finally accomplished this and would like to share how you could make your own scalable VM… In this post I am only going to focus on / because I feel the rest of the volumes are fairly easy to handle with DD and can be done on the fly as it is. If you are just building a template.. I know there is going to be a bunch of LVM fan boy’s out there asking me “why not just use LVM?”… Well simple answer… LVM had its purpose on hardware … In the virtual world you can add disk space to the disk directly instead of adding a disk to a vol group; It was just the partitions holding us back from doing stuff on the fly and the linux installers never gave an option to place the OS on a raw disk. Any way here is how I accomplished this.
1. Add a small disk to the virtual machine (between 512mb/1gb) Make it SCSI(0:1)
2. Reboot the machine
3. Your new drive should now be /dev/sdb. Use the following commands to make it bootable and turn the old /boot off
4. Create a filesystem and make it bootable
5. Make a copy of your fstab and add the new disk to fstab use the UUID you get from the last command run here to replace what you have next to /boot
6. Mount your new /boot disk and copy existing /boot directory over
7. Unmount /boot and remount your new boot disk
8. Update grub to give the grub the correct UUIDS
9. Shut down the VM and make your new boot disk SCSI 0:0 and the old root disk SCSI 0:1
10. Start the machine up and verify it boots properly. Use df to make sure you are booted on the appropriate disk. should be /boot on /dev/sda1
11. Power down the VM and add an additional hard disk to the machine for root(10-15gb should do).
12. Power the machine on
13. Create a file system on the raw device
14. Take note of your device names old root should be /dev/sdb your new root disk should be /dev/sdf at this point (its ok if its not like this at this point we will change it)
15. Go download a rescue disk and or live distro for the following. I used this Rescue CD
16. Mount the disk to the cd drive on the VM and reboot. Interrupt boot and boot from the disk.
17. Open terminal and mount our disks /dev/sdb1 and /dev/sdf and copy over the data
18. Modify the fstab on the new /root disk (/dev/sdf in my case) the below will append the UUID to the fstab file just take the new uuid and replace the old / UUID with the new one.
19. Now that we have our new / disk copied and in fstab we once more need to update the grub2 config files to use the new UUIDS so we will need to mount our /dev/sda1 disk to get access to this information… There really isnt a pretty way to do this through the console so here is what I did …
20. inside Vi use the following
21. Power down the machine and make sure your new /boot disk (the small one) is SCSI (0:0) and your new / disk is SCSI (0:1) and then power the VM back on. to verify functionality.
22. Make a clone of the machine at this point if it boots and leave it off just incase.. Remove the old root disk from the machine and hit ok… Then attempt to reboot.. If your machine goes FUBAR delete this machine and power on your clone and find the correct root disk to remove.