16

I was playing with qemu on Linux when I discovered that I could just run

sudo qemu -hda /dev/sda

And it would boot up my system again! I closed qemu immediately after Grub was loaded successfully though, because the command is run using sudo and I was afraid it would damage my /dev/sda.

Could anyone explain how dangerous this could be?

xiaq
  • 486
  • 1
  • 4
  • 15
  • It did break my system on Ubuntu 14.04 AMD64: it reboot into the root partition anymore :-) – Ciro Santilli OurBigBook.com Aug 24 '15 at 10:01
  • It is shockingly surprising that it is even possible, especially give the scant documentation on how to use QEMU for beginners. It's extremely easy to make this mistake, especially since many examples are using exactly `/dev/sda`... Crazy! – not2qubit Nov 26 '18 at 21:25

2 Answers2

10

I would say it is incredibly dangerous.

You are right in your supposition that it would likely damage your /dev/sda.

Two systems accessing the same block device, each with their own cache and buffers, will definitely mean that each has a different idea of what is actually on the filesystem - changes made by one operating system will not be propagated properly to the other and you will start getting files overwriting each other.

All in all a horrible mess.

Now, if you had 2 operating systems installed on 2 different partitions (dual booting) you could use qemu to boot one of them inside the other, but you must never ever ever boot the same OS twice (unless it's a read-only OS like a live CD image for instance)

Majenko
  • 32,128
  • 4
  • 61
  • 81
4

You can safely run this command by using the -snapshot switch.

qemu usage:
-snapshot write to temporary files instead of disk image files

not2qubit
  • 1,993
  • 4
  • 28
  • 35
Low power
  • 239
  • 1
  • 3