How to map Linux disk to vmware disk

Learn how to map Linux disk to VMware disk for virtual machines hosted on VMware. This ensures you are treating the correct disk on the virtualization layer.

How to map linux vm disk to vmware disk

It’s always a challenge to identify the correct disk physically when it’s being used in the virtualization layer. Since disk or hardware is attached to the Host physically and made visible to the guest server. Any activity related to physical attribute which is to be done on guest machine seeks perfect mapping of hardware from guest to host. In other posts, we already explained mapping iVM disks to host disks in HPUX (HPUX virtualization). In this post, we will be seeing how to map Linux disk to VMware disk (VMware virtualization).

Like HPUX, we do not have a direct command to see the mapping of disks. In HP, both hardware (server), OS software (HPUX), and virtualization technology (iVM) all three products are owned/developed by HP. This makes it possible to integrate tasks into a single command. Since VMware, Linux is not a single vendor configuration, I think it’s not yet possible to get things done with single-line command.

To map VMware disks to Linux VM, we need to check and relate the SCSI id of disks.

In vmware :

Check VM settings and identify disk SCSI id.

As highlighted  in above screenshot, identify your SCSI id. Here its 0:0

In Linux VM:

Now login to Linux VM and execute below command :

# dmesg | grep -i 'Attached SCSI disk'
Attached scsi disk sda at scsi0, channel 0, id 0, lun 0
Attached scsi disk sdb at scsi0, channel 0, id 1, lun 0

We are filtering disk messages from syslog at the boot, to get disk SCSI id identified by the kernel. This will show us disk names along with 4 numbers.  Every disk has 4 numbers displayed in the output. SCSI, channel, id, and lun. We are interested here in channel and id numbers.

For example, disk sda in the above output has numbers 0:0:0:0 whereas disk sdb has 0:0:1:0. Look at the second and third number i.e. 0:0:0:0 or 0:0:1:0. Sometimes you have to check first and third fields to match numbers.

Now match this SCSI id with the id you got from VMware console (VM settings panel).  0:0 is matching that means disk sda in Linux is what we are looking at in VMware Hard Disk 1.

Sometimes RDM disks are assigned to guests from VMware in that case above method is not sufficient to identify disks. You have another approach.

Get sg number from Linux VM :

# dmesg|grep sg |grep Attached
sr 0:0:0:0: Attached scsi generic sg0 type 5
sd 2:0:0:0: Attached scsi generic sg1 type 0
sd 2:0:1:0: Attached scsi generic sg2 type 0

This sgX number is always less than one from VMware “Hard Disk X” number.  So sgX+1=Hard Disk X. This means in Linux disk sg starts with sg0 but in VMware it starts with Hard Disk 1. In the above example, sg1 will be Hard Disk 2 in VMware.

Match numbers accordingly and you will be able to map guest disk with vmware disk!

If you have any other method to get this task done, please drop us in comments!

3 thoughts on “How to map Linux disk to vmware disk

  1. Tadls

    [quote]
    So sgX+1=Hard Disk X. This means in Linux disk sg starts with sg0 but in vmware it starts with Hard Disk 1. In above example sg1 will be Hard Disk 2 in vmware.
    [/quote]

    If X = 1 then sg1+1 = Hard Disk 1 so, sg2 = HD1.
    BUT it seems to be not correct…
    I have 15 disks, one is 2.7TB, it is /dev/sdk (guest side),
    [code]
    sd 2:0:3:0: [sdk] Attached SCSI disk
    [code]
    [code]
    sd 2:0:3:0: Attached scsi generic sg10 type 0
    [code]
    So it should be VMware Hard Disk 11 (or 9 😉
    In fact, it is Hard Disk 3 (SCSI controller 1:3).

    Reply
  2. Richard Remington

    There is also the lsscsi -g command available in CentOS7 but also installable in earlier versions.

    Reply
  3. Andre

    Linux “sg” devices start at “0” while VMWare hard disks start at “1”. So the formula would be sgX=Hard Dusk X+1.

    However, you cannot always rely on that either. On one of our Linux guests sg0 is a virtual CDROM and sg1 is HD1. So on that guest OS, the formula is sgX=Hard DiskX.

    The SCSI ID mapping descibed in the example indicates that a hard disk with SCSI 0:1 matches hardware address 0:0:1:0. This true, but “0” is the first number (not second) and “1” is the third. The first part of the SCSI ID is the SCSI controller number, which needs to be mapped to the guest OS “host number”. The way to determine this is to look at the contents of “/sys/class/scsi_host/host/unique_id”. If the SCSI ID is “2:5”, then find which “host” has unique_id equal to “2” (let’s say it is host4).

    So, the hard disk with SCSI ID “2:5” on the guest where the unique_id of host4 is “2” whihc have the hardware address “4:0:5:0”. That’s the way it works on RHEL6 at least.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.