install kvm to /home

Latest response

As the default install tends to give a rather large /home and a small /, which doesn't separate /var, again by default, how would I create KVMs in /home rather than /var?

Simple way or just start over with better partition planning?

Thanks,

Alex

Responses

Hi Alex - first Warning: as soon as you are able to boot in to Windows again - please make sure you use whatever utility your system came with to create "restore media" from Windows.

First quick question, did you actually install using partitions, or volumes?

I am assuming that you are actually using Volumes, which is good.

If you have:
/ 51200
/home 1024000

you can shrink your /home volume. Now... WARNING... WARNING... I said it twice... you ABSOLUTELY need to do this in the right order, or you will lose data on your /home volume.
https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Logical_Volume_Manager_Administration/LV_reduce.html
https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Storage_Administration_Guide/ext4grow.html

So - basically (you will need to figure out the actual /dev/mapper/vg_myhost-home value from df)

backup your data (specifically /home)
login as root
umount /home
e2fsck -f /dev/mapper/vg_myhost-home
vgchange -an /dev/mapper/vg_myhost-home
resize2fs -p /dev/mapper/vg_myhost-home 20G
lvreduce -L 20G /dev/mapper/vg_myhost-home
e2fsck -f /dev/mapper/vg_myhost-home
mount /home

Some people use a "90% method" where they resize the FS to be 90% of the final value, then resize the Volume to 100%.. then resize the FS again to fill in the blank space. I, personally, have never had to do such a thing... but, I don't shrink Volumes very often.

Once you have reduced your /home Volume, you will now see that your VG has free space

vgs
pvdisplay 

From the pvdisplay command you will see a "Free PE" value (let's say it's 43990)

service libvirtd stop
lvcreate -l43990 -nlv_libvirt vg_myhost
mkfs /dev/mapper/vg_mhost-lv_libvirt

mv /var/lib/libvirt /var/lib/libvirt.orig
mkdir /var/lib/libvirt
echo "/dev/mapper/vg_mhost-lv_libvirt /var/lib/libvirt ext4 defaults 1 2" >> /etc/fstab
mount -a
rsync -urpolvv /var/lib/libvirt.orig/ /var/lib/libvirt/
restorecon -RFvv /var/lib/libvirt
service libvirtd start

Hi Alex,

You can go to the kvm gui and set up a storage pool and place your disk images in other locations, or just cite a different location (browse to a new location with the gui) during the kvm system build. The kvm gui is not the most polished thing in the world.

I typically place my disk images on a separate drive that is not on the operating system drive to reduce disk IO for the operating system drive..

I believe if you open the storage pool settings in the virt-manager graphical interface, select the host physical machine from the main window, then open the Edit menu and select Connection Details, then click on the Storage tab of the Connection Details window, you can cite other locations or storage pools.

Additionally, you can create a system's disk storage in a different location using the gui during a new install of a kvm system, and remove storage from an existing kvm system and add storage to a different location and partition or other available disk.

Kind Regards,
Remmele

HA - I got so wrapped up in resizing a Volume, I forgot what the original topic was ;-) (I went back and finished the post)

Rem - do you know if KVM/QEMU/libvirt manages the SElinux contexts (automatically) if you use the alternate location?

updated again
James, good call. Alex, see James' notes for additional good info

I now remember that I had to change the selinux context on the new location. I have a kvm system where I have my test victim systems and I have a separate drive that I mount. I had to redo the selinux context for that directory!

I suspect this is the proper method in the code block below if (for example) /virtstorage were a new mounted location
(the example in that link only makes (it seems) a 5G LVM. That's crazy if that's what's going on. I typically take a reasonably sized and 7200 or faster separate drive, format it as ext4 (for rhel6), mount it and then do the selinux context change and present it as storage and shut off and delete the old default storage located in /var through the gui.)

# semanage fcontext -a -t virt_image_t "/virtstorage(/.*)?"
# restorecon -R -v /virtstorage

I'd have to verify later (not near the system I typically run this on).

Thanks Everyone. I'll attack this over the weekend.

Great, let us know how it goes!

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.