domingo, 12 de agosto de 2012

Cita

"El pasado es experiencia que el presente aprovecha y el futuro perfecciona"

viernes, 10 de agosto de 2012

Usar imagenes ISO almacenadas en un USB en XenServer

Montar imágenes ISO desde un USB para usar en XenCenter


Estoy preparando una demo para un cliente y he necesitado poner imágenes ISO que tengo en un Pen drive para usarlas en las maquinas virtuales que tengo en un XenServer. Al principio parecía que con poner el USB en el servidor era suficiente.

Se identifica el USB pero no se ven las ISO que hay dentro.

Pasos para usar el Pen drive


1. Formatear el Pen drive en formato ext3. (/dev/sdb en mi caso)

mkfs.ext3 /dev/sdb


2. Colocamos las imágenes ISO en el pen drive.
3. Ponemos el Pen drive en el servidor.


4. Listamos los discos que ve el servidor e identificamos el disco usb.
ls -l /dev/disk/by-id 
lrwxrwxrwx 1 root root  9 Aug  8 10:15 scsi-SATA_ADATA_S596_TurbWWWWWWW-WWWW-777809B -> ../../sda
lrwxrwxrwx 1 root root 10 Aug  8 10:15 scsi-SATA_ADATA_S596_TurbWWWWWWW-WWWW-777809B-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Aug  8 10:15 scsi-SATA_ADATA_S596_TurbWWWWWWW-WWWW-777809B-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Aug  8 10:15 scsi-SATA_ADATA_S596_TurbWWWWWWW-WWWW-777809B-part3 -> ../../sda3
lrwxrwxrwx 1 root root  9 Aug  8 10:15 scsi-SATA_WDC_WD5000AAKX-_WD-WCAYUE088182 -> ../../sdb
lrwxrwxrwx 1 root root  9 Aug 10 12:15 usb-LG_USB_Drive_AA04012700013275 -> ../../sdc
5. Creamos el directorio para el montaje del Pen drive en el servidor.
mkdir /mnt/usb01
6. Montamos el Pen drive en el directorio generado.
mount /dev/sdc /mnt/usb01/
7. Generamos un uuid para identificar el disco nuevo. Nos devuelve un churro enorme.
uuidgen
401f2d85-48a1-497e-aef9-d8628c0d653b
Podemos preguntar por los argumentos que le podemos pasar al comando xe usando el formato xe help comando por ejemplo xe help pbd-create.

8. Definimos un nuevo disco duro con la etiqueta MIUSB, de tipo ISO y con este uuid que acabo de generar.
xe sr-introduce name-label=“MIUSB” content-type=iso shared=false type=iso uuid=401f2d85-48a1-497e-aef9-d8628c0d653b
responde con el uuid
401f2d85-48a1-497e-aef9-d8628c0d653b

9. Le decimos el servidor que este uuid sea auto escaneado.

xe sr-param-set other-config:auto-scan=true uuid=401f2d85-48a1-497e-aef9-d8628c0d653b
10. En el XenCenter podemos ver el nuevo Storage.


11.  Buscamos el uuid del servidor Xen.
xe host-list
uuid ( RO)    : c22e2cb1-7d16-48ca-ac3e-6ee10963a79c
name-label ( RW): XXXXXXXXX
name-description ( RW): Default install of XenServer
11. Le decimos al servidor Xen que tiene un nuevo storage y donde localizarlo.
xe pbd-create host-uuid="c22e2cb1-7d16-48ca-ac3e-6ee10963a79c" sr-uuid=401f2d85-48a1-497e-aef9-d8628c0d653b device-config:location="/mnt/usb01/" device-config:options="-o bind"
devuelve un uuid
254023d8-fdf4-f8c9-eb96-cf368da9217d
12. Usamos el uuid devuelto para que monte el disco nuevo.
xe pbd-plug uuid=254023d8-fdf4-f8c9-eb96-cf368da9217d


13. Ya podemos ver las imágenes ISO del usb.

Script:
#!/bin/bash

UUID=`uuidgen`
HOSTID=`xe host-list | grep uuid | cut -d':' -f2 | cut -d' ' -f2`
xe sr-introduce name-label=“MIUSB” content-type=iso shared=false type=iso uuid=$UUID
xe sr-param-set other-config:auto-scan=true uuid=$UUID
RESULTID=`xe pbd-create host-uuid=$HOSTID sr-uuid=$UUID device-config:location="/mnt/usb01/" device-config:options="-o bind"`
xe pbd-plug uuid=$RESULTID

jueves, 9 de agosto de 2012

How to extend a virtual hard drive - The Red Hat way

How to extend a virtual hard drive

There is no easy way to extend a hard drive on the Red Hat Virtualization platform (RHEV 3.0). Something so simple if you use VMware or XenCenter it's impossible to achieve using the Red Hat Enterprise Virtualization Manager.

Be careful...

How to
 (This is valid for a server or a desktop virtual machine)
1. Shutdown the server.

2. Export the server to the Export Domain. This will be a NFS file system.

3. Log on to the server where the Export Domain is attached.

4. You have to find the exported virtual machine. It will be better if at that moment the exported virtual machine it's the only one on the Export Domain. The virtual machine name it will be something very strange...

"/opt/exports is my NFS mount point"
cd /opt/exports/71439199-46c8-416f-a423-6db1afb68bdd
drwxr-xr-x 2 vdsm kvm 4096 jul 25 12:07 dom_md
drwxr-xr-x 3 vdsm kvm 4096 ago 9 11:51 images
drwxr-xr-x 4 vdsm kvm 4096 jul 25 12:08 master
"Here will be our virtual machine hard drive"

cd images/0d0e949a-ec31-4e15-b5da-6e1a88d1d139
-rw-rw---- 1 vdsm kvm 8589934592 ago 9 12:02 007135e1-7963-40c8-b013-0960b04a8854
-rw-r--r-- 1 vdsm kvm 325 ago 9 11:51 007135e1-7963-40c8-b013-0960b04a8854.meta

5. Extend the hard drive with qemu-img.

Change Size (15 Gb more in this example)
qemu-img resize 04286729-96d0-43a1-a7f4-dd9189f5a161 +15G
Check new size
-rw-rw---- 1 vdsm kvm 24696061952 ago 9 12:14 007135e1-7963-40c8-b013-0960b04a8854
-rw-r--r-- 1 vdsm kvm 325 ago 9 11:51 007135e1-7963-40c8-b013-0960b04a8854.meta
6. Edit the virtual machine file definition.
Change virtual machine values to the new hard drive size (fichero ovf)

cd /opt/exports/71439199-46c8-416f-a423-6db1afb68bdd
cd master/vms/42340635-92db-4395-a39e-405611839972
vi 42340635-92db-4395-a39e-405611839972.ovf

Values to change:
<?xml version='1.0' encoding='UTF-8'?><ovf:Envelope xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1/" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ovf:version="3.0.0.0"><References><File ovf:href="0d0e949a-ec31-4e15-b5da-6e1a88d1d139/007135e1-7963-40c8-b013-0960b04a8854" ovf:id="007135e1-7963-40c8-b013-0960b04a8854" ovf:size="8589934592" ovf:description="_ActiveImage_xxxxxxx_Tue May xxx xx:xx:xx WEST xxxx" /></References><Section xsi:type="ovf:NetworkSection_Type"><Info>List of networks</Info><Network ovf:name="Network 1" /></Section><Section xsi:type="ovf:DiskSection_Type"><Info>List of Virtual Disks</Info><Disk ovf:diskId="007135e1-7963-40c8-b013-0960b04a8854" ovf:size="8" ovf:actual_size="8" ovf:vm_snapshot_id="939f5e47-5391-46aa-a521-96a4
851a82d9" ovf:parentRef="" ovf:fileRef="0d0e949a-ec31-4e15-b5da-6e1a88d1d139/007135e1-7963-40c8-b013-0960b04a8854" ovf:format="http://www.vmware.com/specifications/vmdk.html#sparse" ovf:volume-format="RAW" ovf:volume-type="Preallocated" ovf:disk-interface="VirtIO" ovf:disk-type="System" ovf:boot="true" ovf:wipe-after-delete="false" /></Section><Content ovf:id="out" xsi:type="ovf:VirtualSystem_Type"><Name>cacharro</Name><TemplateId>00000000-0000-0000-0000-000000000000</TemplateId><TemplateName>Blank</TemplateName><Description>xxxxxxxxxxxx</Description><Domain></Domain><CreationDate>xxxx/xx/xx 06:38:52</CreationDate><IsInitilized>true</IsInitilized><IsAutoSuspend>false</IsAutoSuspend><
TimeZone></TimeZone><IsStateless>false</IsStateless><Origin>0</Origin><default_boot_sequence>0</default_boot_sequence><VmType>1</VmType><DefaultDisplayType>1</DefaultDisplayType><MinAllocatedMem>1024</MinAllocatedMem><Section ovf:id="4234
0635-92db-4395-a39e-405611839972" ovf:required="false" xsi:type="ovf:OperatingSystemSection_Type"><Info>Guest Operating System</Info><Description>OtherLinux</Description></Section><Section xsi:type="ovf:VirtualHardwareSection_Type"><Info>
1 CPU, 1024 Memeory</Info><System><vssd:VirtualSystemType>RHEVM 3.0.0.0</vssd:VirtualSystemType></System><Item><rasd:Caption>1 virtual cpu</rasd:Caption><rasd:Description>Number of virtual CPU</rasd:Description><rasd:InstanceId>1</rasd:In
stanceId><rasd:ResourceType>3</rasd:ResourceType><rasd:num_of_sockets>1</rasd:num_of_sockets><rasd:cpu_per_socket>1</rasd:cpu_per_socket></Item><Item><rasd:Caption>1024 MB of memory</rasd:Caption><rasd:Description>Memory Size</rasd:Description><rasd:InstanceId>2</rasd:InstanceId><rasd:ResourceType>4</rasd:ResourceType><rasd:AllocationUnits>MegaBytes</rasd:AllocationUnits><rasd:VirtualQuantity>1024</rasd:VirtualQuantity></Item><Item><rasd:Caption>Drive 1</rasd:Caption><ras
d:InstanceId>007135e1-7963-40c8-b013-0960b04a8854</rasd:InstanceId><rasd:ResourceType>17</rasd:ResourceType><rasd:HostResource>0d0e949a-ec31-4e15-b5da-6e1a88d1d139/007135e1-7963-40c8-b013-0960b04a8854</rasd:HostResource><rasd:Parent>00000
000-0000-0000-0000-000000000000</rasd:Parent><rasd:Template>00000000-0000-0000-0000-000000000000</rasd:Template><rasd:ApplicationList></rasd:ApplicationList><rasd:StorageId>f02a341d-fdce-4abe-8f86-94c26492a088</rasd:StorageId><rasd:Storag
ePoolId>48e51ec0-5ef7-11e1-9407-00505696000d</rasd:StoragePoolId><rasd:CreationDate>xxxx/xx/xx 11:08:13</rasd:CreationDate><rasd:LastModified>xxxx/xx/xx 11:08:13</rasd:LastModified><rasd:last_modified_date>xxxx/xx/xx 11:02:37</rasd:last_modified_date></Item><Item><rasd:Caption>Ethernet adapter on rhevm</rasd:Caption><rasd:InstanceId>3</rasd:InstanceId><rasd:ResourceType>10</rasd:ResourceType><rasd:ResourceSubType>3</rasd:ResourceSubType><rasd:Connection>rhevm</rasd:Connec
tion><rasd:Name>nic1</rasd:Name><rasd:MACAddress>00:1a:4a:a8:02:03</rasd:MACAddress><rasd:speed>1000</rasd:speed></Item><Item><rasd:Caption>USB Controller</rasd:Caption><rasd:InstanceId>4</rasd:InstanceId><rasd:ResourceType>23</rasd:ResourceType><rasd:UsbPolicy>Enabled</rasd:UsbPolicy></Item><Item><rasd:Caption>Graphical Controller</rasd:Caption><rasd:InstanceId>5</rasd:InstanceId><rasd:ResourceType>20</rasd:ResourceType><rasd:VirtualQuantity>1</rasd:VirtualQuantity></Item></Section></Content></ovf:Envelope>
7. You have to remove the exported virtual machine from the VMs prior to import the extended one.

8. Import the extended server.


That's all folks.