Friday, June 22, 2012

Getting WinXP (or Win 7, Server etc) to see all cores as a KVM guest

I'd installed a Win XP Pro x86_64 guest on a Fedora 13 x86_64 KVM host. The host had 8 hyperthreaded CPUs (16 virtual cores in total). I had assigned all 16 vcpus to the WinXP guest, but it only showed 2 in the task manager, though in the device manager, it showed 16. The problem had to do with licensing: XP Pro is limited to 2 physical CPUs (even though it can see 16 cpus in the device manager). It can support (at least) 4 cores per cpu however. So the solution is to specify this in the config, which I found (via googling) can be done by modifying the xml defining the guest. To find the layout of the host:

virsh capabilities | grep topology

<topology sockets='2' cores='4' threads='2'/>

Using 'virsh edit <domain>', find where the vcpus are set:

<vcpu>16</vcpu>

Then add the following below:


  <cpu>
    <topology sockets='2' cores='4' threads='2'/>
  </cpu>

Save it, and restart the guest. It now sees all vcpus.

I notice that from looking at the xml, libvirt reorders it slightly:


  <vcpu>16</vcpu>
  <os>
    <type arch='x86_64' machine='pc-0.13'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <cpu>
    <topology sockets='2' cores='4' threads='2'/>
  </cpu>


Tuesday, February 14, 2012

editfiles cfengine v2

I had the task of disabling swap on a class of machines managed by cfengine2

The swap entry could have started with 'UUID=', or possibly '/dev/sda3'


One way of doing it:


editfiles:
    { /etc/fstab

            CommentLinesMatching ".*swap(\s+)swap(\s+).*"
     }

another, more complicated way:


editfiles:
    { /etc/fstab
        ReplaceAll "swap(\s+)swap(\s+)defaults(\s+)0(\s+)0$" With "swap                    swap    noauto,defaults        0 0"
}

Normally, with editfiles, you must match the whole line (hence the .* at the beginning and end of the first way using 'CommentLines'), but when matching a quoted regex (as with 'ReplaceAll'), you can just match (and replace) that part of the line


Wednesday, January 25, 2012

Unpack and edit initramfs (for blacklisting modules, but can be used for other reasons)

I did this originally to blacklist the loading a kernel module, which may have been loaded by initramfs (adding rdblacklist to the kernel command line didn't work). However, the module still got loaded and what I should have done in the first instance was check modules.dep, as it was a dependency for another module that I wanted anyway. You also must make sure any other processes in init don't cause it to get loaded. Anyway, it was a useful exercise in how to modify initramfs!

How to unpack and modify a initramfs image

(tested with fedora 13)

Make a directory to unpack it in
Make a backup of the original initramfs image
cd to your unpack dir and unpack with: 'gzip -dc initramfs-2.6.34.9-69.fc13.x86_64.img | cpio -id'

The 'i' flag is for taking input, and the 'd' makes dirs

Modify the files as required

Recreate the image (I like to do it in 2 separate steps cos I'm superstitous):


find . | cpio -H newc -o > /some/dir/initramfs-2.6.34.9-69.fc13.x86_64.cpio

'-H' - format
newc - is the newc format type

'-o' - output

cat /tmp/initramfs-2.6.34.9-69.fc13.x86_64.cpio | gzip -9 > /tmp/initramfs-2.6.34.9-69.fc13.x86_64.img

Maximum compression is selected as that is what it is used in the original

Then copy it back

I haven't yet tried dracut