Adding a block device online to an Oracle VM

In a previous blog posting an example has been given how to resize the root filesystem of your Oracle VM template. In a comment on this blog someone asked how to add a block device to a running Oracle VM. This block device could then be used to put the filesystem on.
Here is the answer.

My Oracle VM Server indicates there are 4 guests running (without Dom0):

[root@ovms1 ]# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 667 4 r----- 1905.1
oel-repos 1 1400 2 -b---- 62.1
openfiler1 2 256 1 -b---- 122.5
vdb11a 10 1400 1 -b---- 24.3
vsupp1 6 1500 2 -b---- 984.3

So, for the vdb11a we want to add a block device online. First we create a file which we will use as 'block device".

[root@ovms1 ]# dd if=/dev/zero of=extradisk01.img bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.194952 seconds, 538 MB/s

Then, we attach this file as a block to the VM with ID 10 (vdb11a):

[root@ovms1 ]# xm block-attach 10 file:`pwd`/extradisk01.img /dev/xvdc1 w

The 'w' indicates the disk is read/write available, but other options are available, this is the syntax:

xm block-attach domain-id be-dev fe-dev mode [bedomain-id]

Create a new virtual block device. This will trigger a hotplug event for the guest.
domain-id The domain id of the guest domain that the device will be attached to.
be-dev The device in the backend domain (usually domain 0) to be exported.
This can be specified as a physical partition (phy:sda7) or as a file
mounted as loopback (file://path/to/loop.iso).
fe-dev How the device should be presented to the guest domain. It can be specified
as either a symbolic name, such as /dev/hdc, for common devices, or by
device id, such as 0x1400 (/dev/hdc device id in hex).
mode The access mode for the device from the guest domain.
Supported modes are w (read/write) or r (read-only).
w! will make the hypervisor think the vbd attached to multiple domains to be ok.
bedomain-id The back end domain hosting the device. This defaults to domain 0.

In the syslog of the VM guest you see the disk coming in:

Jan 10 20:52:58 vdb11a kernel: Registering block device major 202

Let's double check if this is our disk, it should be about 100M

[root@vdb11a ~]# fdisk -l /dev/xvdc1

Disk /dev/xvdc1: 104 MB, 104857600 bytes
255 heads, 63 sectors/track, 12 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/xvdc1 doesn't contain a valid partition table
[root@vdb11a ~]#

There is also an option to detach the block device
Please note also to add the file to the vm.cfg because if you forget, the next time you wonder where the device is.

Rene Kundersma
Oracle Expert Services, The Netherlands


Rene, Execellent job! That is exactly what I was looking for. Thank you. regards /Peter

Posted by Peter on January 10, 2009 at 06:25 PM PST #

Hi, Tried to do the sugested above but got the next message: [root@nlmeyoraclevm01 sharedDisk]# ll total 1012G -rw-rw-rw- 1 root root 196G Jan 12 11:37 apps.img -rw-rw-rw- 1 root root 1.0G Dec 11 14:20 ccs.img -rw-rw-rw- 1 root root 196G Dec 23 11:27 db1.img -rw-rw-rw- 1 root root 150G Mar 13 13:55 dt07_dt08-db1.img -rw-rw-rw- 1 root root 25G Mar 12 10:01 dt07_dt08-tdatashared.img -rw-r--r-- 1 root root 200G Mar 13 12:01 orarel-apps.img -rw-r--r-- 1 root root 96M Jan 28 17:19 orarel-ccs.img -rw-r--r-- 1 root root 200G Mar 13 13:55 orarel-db1.img -rw-r--r-- 1 root root 25G Mar 12 17:00 orarel-tdatashared.img -rw-rw-rw- 1 root root 20G Dec 29 15:46 tdatashared.img [root@nlmeyoraclevm01 sharedDisk]# xm list Name ID Mem VCPUs State Time(s) 132_NLMEYAPT01 89 2048 1 -b---- 28117.5 134_NLMEYAPT04 90 2048 1 -b---- 21368.0 142_NLMEYDT05 91 2048 1 -b---- 44209.4 176_NLMEYDT08 95 2048 1 -b---- 1669.3 84_NLMEYAPT14 7 2048 1 -b---- 429311.7 94_NLMEYDB16 88 4096 2 -b---- 39130.1 Domain-0 0 1152 8 r----- 2520803.1 NLMEYAPT16 8 2048 1 -b---- 408358.5 [root@nlmeyoraclevm01 sharedDisk]# xm block-attach 95 file:`pwd`/dt07_dt08-tdatashared.img /dev/sda w Error: The uname "file:/OVS/sharedDisk/dt07_dt08-tdatashared.img" is already defined Usage: xm block-attach [BackDomain] Create a new virtual block device. [root@nlmeyoraclevm01 sharedDisk]# And the shared disk is not visable from the host.

Posted by Philo Sluijsmans on March 12, 2009 at 10:23 PM PDT #

Philo, Can you verify the file want to attach is not in use already ? use the losetup -a command for that. In case it is in use you have to share it with the "w!" option on all vms Rene

Posted by Rene on March 12, 2009 at 10:54 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

Blog of Rene Kundersma, Consulting Member of Technical Staff at Oracle Development USA. I am designing and evaluating solutions and best practices around database MAA focused on Exadata. This involves HA, backup/recovery, migration and database consolidation and upgrades on Exadata. Opinions are my own and not necessarily those of Oracle Corporation. See


« July 2016