Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I use Ubuntu and CentOS, I see /dev/sda and /dev/vda. So I can't understand what is the different between above two?

share|improve this question
    
Is one of these in a VM? –  goldilocks Jul 18 at 17:31
    
Yes. I'm using VM ..:) –  Supun Rathnayake Jul 18 at 17:32

5 Answers 5

They're different devices.

/dev/sda is the first disk that's either SCSI or (more likely) providing the SCSI drive API to user land. This includes SATA drives and IDE drives using libata. This can also be an IDE/SATA/SCSI/etc. drive emulated by the hypervisor.

/dev/vda is the first disk using the virtualization-aware disk driver. The performance should be much better, as the hypervisor doesn't have to emulate some hardware interface.

If the disk has been exposed to your VM under both interfaces, you should prefer /dev/vda as it'll almost certainly be faster.

share|improve this answer

/dev/sdx and /dev/hdx are physical (hard) disk drives or emulated physical (hard) disk drives. When the kernel or some program I/O's to these, it does all sorts of things like bringing the disk to the right spot and doing all sorts of physical-specific "stuff."

/dev/vdx is for virtual (hard) disk drives. All the kernel does when it is I/O'd to is tell the virtualization software that bits need to be read/written and it's done. In general, vdx is faster because the kernel doesn't need to tell the hard drive to do a whole bunch of random junk that really shouldn't be needed because it just needs to tell the VM hypervisor to do stuff.

I apologize for the word "stuff," I couldn't think of a better word :D

share|improve this answer
    
The word is was plenty expressive - thanks for your answer. –  mikeserv Jul 19 at 6:43
    
Stuff? You couldn't think of "something" or "the requested IO operation". Apology not accepted. ;) –  Johan Jul 23 at 11:53

In the udev rules in /lib/udev/rules.d/* is defined which kind of hardware gets which name from the kernel.

See the rules for /dev/vd*:

# partitions do not have hardware identifiers
ENV{DEVTYPE}!="disk",                   GOTO="persistent_storage_not_a_disk"
# nor do paravirtualized hard disks
KERNEL=="vd*",                          GOTO="persistent_storage_not_a_disk"

...

KERNEL=="vd*",                          ATTRS{serial}=="?*", \
ENV{ID_BUS}="virtio",   ENV{ID_SERIAL}="$attr{serial}"

So /dev/vda is the first, virtual harddrive (no hardware identificators) and a bus id virtio. Looks like a qemu/kvm guest.

The udev rules for /dev/sd* devices can be more different hardware types: scsi, ata, ieee1394, usb, ...

share|improve this answer

/dev/ is the part in the unix directory tree that contains all "device" files -- unix traditionally treats just about everything you can access as a file to read from or write to.

So in essence, the /dev/sda is all device files found in your Harddrive while the /dev/vda is all device files found in the space allocated for your virtual machine.

share|improve this answer

One fairly fundamental way in which these /dev/.da device files differ that has not yet been mentioned is that they represent different kernel major numbers. If you follow that link you will land on a kernel source documentation page containing a table of mostly all of the allocated device major numbers. This same file is also very likely on your harddisk somewhere.

Here's what a quick CTRL-F has surfaced for me regarding your question:

112 block IBM iSeries virtual disk
      0 = /dev/iseries/vda  First virtual disk, whole disk
      8 = /dev/iseries/vdb  Second virtual disk, whole disk
        ...
    200 = /dev/iseries/vdz  26th virtual disk, whole disk
    208 = /dev/iseries/vdaa 27th virtual disk, whole disk
        ...
    248 = /dev/iseries/vdaf 32nd virtual disk, whole disk

    Partitions are handled in the same way as for IDE
    disks (see major number 3) except that the limit on
    partitions is 7.

The 112 number listed at top indicates the allocated major number and the various 0...8...200 numbers listed before each line indicate the possible minor number ranges. These numbers, among many other things, are used by the linux kernel to pair driver modules with physical devices - they identify a device type.

The above list accounts for 3 of 4 matches found with CTRL-F - here's the fourth:

202 block   Xen Virtual Block Device
      0 = /dev/xvda       First Xen VBD whole disk
      16 = /dev/xvdb      Second Xen VBD whole disk
      32 = /dev/xvdc      Third Xen VBD whole disk
        ...
      240 = /dev/xvdp     Sixteenth Xen VBD whole disk

            Partitions are handled in the same way as for IDE
            disks (see major number 3) except that the limit on
            partitions is 15.

There definitely seems to be a trend among vda block types. Note that these may not be completely up to date in the documentation - even as linked at kernel.org. The devs are, after all, only human. But another possible source of discrepancy is where your distribution's maintainers chose to locate the devices. A great number of the paths listed amount to little more than suggestions - there are many ways to relocate them.

And here's sda:

8 block SCSI disk devices (0-15)
      0 = /dev/sda      First SCSI disk whole disk
     16 = /dev/sdb      Second SCSI disk whole disk
     32 = /dev/sdc      Third SCSI disk whole disk
        ...
    240 = /dev/sdp      Sixteenth SCSI disk whole disk

    Partitions are handled in the same way as for IDE
    disks (see major number 3) except that the limit on
    partitions is 15.

As already noted - these paths are eminently configurable - but the major/minor numbers themselves serve as pretty explicit identifiers. You can check these with a stat call to a device file.

stat /dev/sda

  File: ‘/dev/sda’
  Size: 0               Blocks: 0          IO Block: 4096   block special file
Device: 5h/5d   Inode: 7598        Links: 1     Device type: 8,0
Access: (0660/brw-rw----)  Uid: (    0/    root)   Gid: (    6/    disk)
Access: 2014-07-18 11:10:13.112495427 -0700
Modify: 2014-07-16 18:59:41.313323401 -0700
Change: 2014-07-16 18:59:41.313323401 -0700
 Birth: -

That's my /dev/sda. There's a lot of information there, but to the right you can see that its Device Type is specified as major number 8, minor number 0. You can id pretty much any device file that way by comparing its maj/min to the table linked.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.