piątek, 25 października 2013

Xen add new virtual disc

Once I need to attach new disk on my VM machine. To do this I need make steps below :

1) Get storage UUID:

[root@xenserver1 ~]# xe sr-list 
uuid ( RO)                : 4e98e18e-1215-4fdb-baec-924bbef2a67e
          name-label ( RW): Remote ISO Library on: /mnt/iso_import
    name-description ( RW): 
                host ( RO): xenserver1
                type ( RO): iso
        content-type ( RO): iso


uuid ( RO)                : f30a1ead-37f2-0e3c-9583-073c176fc111
          name-label ( RW): Removable storage
    name-description ( RW): 
                host ( RO): xenserver1
                type ( RO): udev
        content-type ( RO): disk


uuid ( RO)                : 419c98d3-1d98-3049-c579-439c31b33fd4
          name-label ( RW): XenServer Tools
    name-description ( RW): XenServer Tools ISOs
                host ( RO): xenserver1
                type ( RO): iso
        content-type ( RO): iso


uuid ( RO)                : a9329bfa-e13e-2edd-8414-5920f03f27e5
          name-label ( RW): ISOS
    name-description ( RW): 
                host ( RO): xenserver1
                type ( RO): iso
        content-type ( RO): iso


uuid ( RO)                : cb128245-3dcb-9de6-319d-681cede9553f
          name-label ( RW): DVD drives
    name-description ( RW): Physical DVD drives
                host ( RO): xenserver1
                type ( RO): udev
        content-type ( RO): iso


uuid ( RO)                : f6375e1e-0ab7-b11c-e9dd-677da4436e15
          name-label ( RW): Local storage
    name-description ( RW): 
                host ( RO): xenserver1
                type ( RO): lvm
        content-type ( RO): user
2) Create virtual disc:
[root@xenserver1 ~]# xe vdi-create name-label="zfs1" sr-uuid=f6375e1e-0ab7-b11c-e9dd-677da4436e15 type=user sm-config:type=raw virtual-size=10GiB
34a899b3-b3dd-4531-aee9-1fafb57517ca
[root@xenserver1 ~]# xe vdi-create name-label="zfs2" sr-uuid=f6375e1e-0ab7-b11c-e9dd-677da4436e15 type=user sm-config:type=raw virtual-size=10GiB
20c384f6-0504-4c7f-a3cf-08d28c6c0dc6
[root@xenserver1 ~]# xe vdi-list name-label=zfs1
uuid ( RO)                : 34a899b3-b3dd-4531-aee9-1fafb57517ca
          name-label ( RW): zfs1
    name-description ( RW): 
             sr-uuid ( RO): f6375e1e-0ab7-b11c-e9dd-677da4436e15
        virtual-size ( RO): 10737418240
            sharable ( RO): false
           read-only ( RO): false


[root@xenserver1 ~]# xe vdi-list name-label=zfs2
uuid ( RO)                : 20c384f6-0504-4c7f-a3cf-08d28c6c0dc6
          name-label ( RW): zfs2
    name-description ( RW): 
             sr-uuid ( RO): f6375e1e-0ab7-b11c-e9dd-677da4436e15
        virtual-size ( RO): 10737418240
            sharable ( RO): false
           read-only ( RO): false
3) Check virtual machine UUID for whom virtual disc should be attched:
[root@xenserver1 ~]# xe vm-list 
uuid ( RO)           : 68ce65a4-01ec-4a23-9016-011aa20e59cf
     name-label ( RW): Control domain on host: xenserver1
    power-state ( RO): running


uuid ( RO)           : 66a6fcc2-b5b9-1eb9-cd26-c26d8df1e204
     name-label ( RW): Hadoop-master
    power-state ( RO): running


uuid ( RO)           : a79bc6f8-54d7-a562-ba14-4f50db2efc9b
     name-label ( RW): FreeBSD 9.2
    power-state ( RO): running


uuid ( RO)           : 8ac1c052-8448-6d9b-0a55-6e91e5be406c
     name-label ( RW): FreeBSD10
    power-state ( RO): halted


uuid ( RO)           : 03070e1e-2b04-5e4b-87f9-5db7d69131bb
     name-label ( RW): Hadoop-slave2
    power-state ( RO): running


uuid ( RO)           : d122b3bf-e914-83b0-5761-1430f205fa9c
     name-label ( RW): Hadoop-slave1
    power-state ( RO): running
In my case it was FreeBSD 9.2 (uuid=a79bc6f8-54d7-a562-ba14-4f50db2efc9b)

4) Get allowed numbers for VBD devices:

[root@xenserver1 ~]# xe vm-param-get uuid=a79bc6f8-54d7-a562-ba14-4f50db2efc9b param-name=allowed-VBD-devices 
1; 2
5) Create virtual disc attached to VM:
[root@xenserver1 ~]# xe vbd-create device=1 vm-uuid=a79bc6f8-54d7-a562-ba14-4f50db2efc9b vdi-uuid=34a899b3-b3dd-4531-aee9-1fafb57517ca bootable=false mode=RW type=Disk
f43711c3-be1e-a869-8888-408d94a70656
[root@xenserver1 ~]# xe vbd-create device=2 vm-uuid=a79bc6f8-54d7-a562-ba14-4f50db2efc9b vdi-uuid=20c384f6-0504-4c7f-a3cf-08d28c6c0dc6 bootable=false mode=RW type=Disk
5dcf7ad9-f4ec-b3e3-ea0c-8edd0d35d53d
6) Optionally if you have Xen tools on board you can plug virtual disc live.
[root@xenserver1 ~]# xe vbd-plug uuid=f43711c3-be1e-a869-8888-408d94a70656
If everything goes right you should have new discs attached and working on virtual machine. On system:
shamrock@tanatos:~ % dmesg | grep xbd
xbd0: 30720MB  at device/vbd/768 on xenbusb_front0
xbd0: attaching as ada0
xbd1: 10240MB  at device/vbd/5632 on xenbusb_front0
xbd1: attaching as ada2
xbd2: 10240MB  at device/vbd/832 on xenbusb_front0
xbd2: attaching as ada1
On Xen:
[root@xenserver1 ~]# xe vbd-list vm-name-label=FreeBSD\ 9.2
uuid ( RO)             : 5dcf7ad9-f4ec-b3e3-ea0c-8edd0d35d53d
          vm-uuid ( RO): a79bc6f8-54d7-a562-ba14-4f50db2efc9b
    vm-name-label ( RO): FreeBSD 9.2
         vdi-uuid ( RO): 20c384f6-0504-4c7f-a3cf-08d28c6c0dc6
            empty ( RO): false
           device ( RO): hdc


uuid ( RO)             : f43711c3-be1e-a869-8888-408d94a70656
          vm-uuid ( RO): a79bc6f8-54d7-a562-ba14-4f50db2efc9b
    vm-name-label ( RO): FreeBSD 9.2
         vdi-uuid ( RO): 34a899b3-b3dd-4531-aee9-1fafb57517ca
            empty ( RO): false
           device ( RO): hdb


uuid ( RO)             : 17d014d8-0d28-76e9-b6dc-f8944a0c0244
          vm-uuid ( RO): a79bc6f8-54d7-a562-ba14-4f50db2efc9b
    vm-name-label ( RO): FreeBSD 9.2
         vdi-uuid ( RO): a74f372f-2fcd-4121-a241-bd1e960a069c
            empty ( RO): false
           device ( RO): hda