Apart from networking and partition sharing I've made qemu work pretty much like I want it to. I've got a bit of a special setup, I need to pass through /dev/sda, /dev/sda1 and /dev/sda2. (Is it possible to passthrough /dev/sda without passing through /dev/sda3 with it? I can live with using alternative methods.)

/dev/sda (MBR) = Windows Bootmgr on /dev/sda1

/dev/sda1 = System Reserved partition (Windows's bootloader)

/dev/sda2 = Windows 7's C:/ partition

/dev/sda3 = Arch Linux (Host)

I've got /dev/sda3's grub installed into the MBR of /dev/sdc (meaning booting /dev/sdc will boot me into my arch Linux install, booting /dev/sda will boot me into Windows) I will be passing through /dev/sdc as well but this one is easy as the host doesn't need any access to this drive after booting.

Finally I have a GPT, (NTFS) storage partition on /dev/sdb2 that I want to be easily accessible from both the host and my guest at the same time (I want to share it between both systems)

How do I proceed with /dev/sda and /dev/sdb2?


You can use the device mapper to shape a device that contains the parts of the original device you want. For instance:

$ grep . /sys/class/block/sda/**/(size|start)

If I want to hide sda2, I can create a /dev/mapper/no_sda2 where sectors 224910 to 125045424 contain zeros:

  • First create a loop device as otherwise dmsetup will complain because /dev/sda is in use (while loop will not complain which doesn't sound very consistent to me):

    losetup /dev/loop0 /dev/sda
  • Then create /dev/mapper/no_sda2 as:

    dmsetup create no_sda2 << EOF
    0 224910 linear /dev/loop0 0
    224910 $((125045424-224910)) zero
  • this will allow me to mount /dev/mapper/no_sda2 on the VM and /dev/sda2 on the host and safely share the partitions between them? – Cestarian Jul 8 '14 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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