Linux 作为虚拟机在硬盘上启动本机操作系统

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9811742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:18:47  来源:igfitidea点击:

Boot a native OS on a hard disk as a virtual machine

windowslinuxvirtual-machine

提问by YankeeWhiskey

I'm searching for a solution to boot a native OS on a hard disk as a virtual machine.

我正在寻找一种在硬盘上将本机操作系统作为虚拟机启动的解决方案。

It's like what VMware Fusion did on a Mac which boots Windows in Boot Camp as a virtual machine.

这就像 VMware Fusion 在 Mac 上所做的那样,它将 Boot Camp 中的 Windows 作为虚拟机启动。

In detail, I have Windows installed on /dev/sda2 and Ubuntu 11.10 on /dev/sda5.

详细地说,我在 /dev/sda2 上安装了 Windows,在 /dev/sda5 上安装了 Ubuntu 11.10。

Is there anyway to use a virtual machine software to boot the Windows on /dev/sda2 as a virtual machine while I'm using Ubuntu?

无论如何,在我使用 Ubuntu 时,是否可以使用虚拟机软件将 /dev/sda2 上的 Windows 作为虚拟机启动?

采纳答案by TryTryAgain

Yes, I did this long ago following this guide:

是的,我很久以前就按照本指南这样做了:

https://lists.ubuntu.com/archives/ubuntu-us-nm/2008-February/000521.html

https://lists.ubuntu.com/archives/ubuntu-us-nm/2008-February/000521.html

of course, always backup and be careful!

当然,总是备份并小心!

Essentially:

本质上:

  1. Used a USB 3.5 HD enclosure and connect the XP drive to it.

    If the drive was shutdown uncleanly you may need to manually mount it with the following command.

    sudo mount ntfs-3g /dev/whereyourdriveis /mount/somemountpoint -o force

    Once the drive is mounted under linux contiunue to step 2.

  2. Launch VMWare.

  3. Go to File -> New -> New Virtual Machine.
  4. Select "Custom"
  5. Select Next
  6. Select your operating system (i.e. Win XP)
  7. Select Next
  8. Give it a name like "WindowsXP"
  9. Select Next 10 Specify processor One or Two
  10. Select Next
  11. Choose public or private (on a single-user machine this doesn't matter)
  12. Select Next
  13. Select the memory to devote to the virtual machine. 512 MB is a pretty useful number.
  14. Select your network connection
  15. Select Next.
  16. Leave SCSI set to BusLogic
  17. Select Next
  18. Select Use Physical Disk
  19. Select Next
  20. Select Use Entire Drive
  21. Select Next
  22. Specify the place to save the VM
  23. At this point you're done Select Power On to boot the Physical drive in VMWare!
  1. 使用 USB 3.5 HD 外壳并将 XP 驱动器连接到它。

    如果驱动器被不干净地关闭,您可能需要使用以下命令手动安装它。

    sudo mount ntfs-3g /dev/whereyourdriveis /mount/somemountpoint -o force

    在 linux 下安装驱动器后,继续执行步骤 2。

  2. 启动 VMWare。

  3. 转到文件 -> 新建 -> 新建虚拟机。
  4. 选择“自定义”
  5. 选择下一步
  6. 选择您的操作系统(即 Win XP)
  7. 选择下一步
  8. 给它起一个像“WindowsXP”这样的名字
  9. 选择下一个 10 指定处理器一或二
  10. 选择下一步
  11. 选择公共或私有(在单用户机器上这无关紧要)
  12. 选择下一步
  13. 选择用于虚拟机的内存。512 MB 是一个非常有用的数字。
  14. 选择您的网络连接
  15. 选择下一步。
  16. 将 SCSI 设置为 BusLogic
  17. 选择下一步
  18. 选择使用物理磁盘
  19. 选择下一步
  20. 选择使用整个驱动器
  21. 选择下一步
  22. 指定保存 VM 的位置
  23. 此时您已完成选择 Power On 以在 VMWare 中启动物理驱动器!

More Info: I should add, I have successfully done this, but I also had success using this methodyears even years before. So there are at least two known and tested ways for accomplishing this that I can tell you.

更多信息:我应该补充一点,我已经成功地做到了这一点,但我几年前甚至几年前也成功地使用了这种方法。因此,我可以告诉您至少有两种已知且经过测试的方法可以实现这一点。

回答by jianglai

You can do this via VirtualBox raw disk access. (http://www.virtualbox.org/manual/ch09.html) It basically creates a "virtual" disk file that points to the actual partition and loads it as a disk drive in the VM. I've installed Linux guest in VB on Windows host in such a way, and the installation can boot from the VM or by itself.

您可以通过 VirtualBox 原始磁盘访问来执行此操作。( http://www.virtualbox.org/manual/ch09.html) 它基本上创建了一个指向实际分区的“虚拟”磁盘文件,并将其作为磁盘驱动器加载到 VM 中。我已经以这种方式在 Windows 主机上的 VB 中安装了 Linux 来宾,并且安装可以从 VM 或自行启动。

回答by deFreitas

As answered, this also can be done in VirtualBox, this is the way that works for me

正如回答的那样,这也可以在 VirtualBox 中完成,这是对我有用的方式

Always, make sure that you are running as Administrator(Windows)or Sudo(Linux), any changes that you do will write to the REALdisk, so be carefull

始终确保您以管理员身份运行(Windows)Sudo(Linux),您所做的任何更改都会写入真实磁盘,因此请小心

In Windows

在 Windows 中

C:\Program Files\Oracle\VirtualBox>VBoxManage.exe internalcommands createrawvmdk -filename "E:\virtualbox\linuxhd.vmdk" -rawdisk "\.\PhysicalDrive1"
RAW host disk access VMDK file E:\virtualbox\linuxhd.vmdk created successfully.

In Linux

在 Linux 中

$ VBoxManage internalcommands createrawvmdk -filename "~/linuxhd.vmdk" -rawdisk "/dev/sda"

It will create a file with something around 1kbthat is a link to the physical hard drive.

它将创建一个文件,1kb其中包含指向物理硬盘驱动器的链接。

Then create a Virtual Machine as ever you do.

然后像往常一样创建一个虚拟机。

If you want to map only a partition

如果只想映射一个分区

At Windows

在 Windows

\.\Physicaldrive1 -partitions 1

(Disk start with 0, partitions with 1)

(磁盘以 0 开头,分区以 1 开头)

At Linux (Much more intuitive)

在 Linux 上(更直观)

/dev/sda1
/dev/sda2
etc.

Eventually you can get resolution issues

最终你可以得到解决问题

Eventually you can get resolution issues even after install vboxadditions, in my experience the problem is your /etc/X11/xorg.confit is configured to your specific real hardware specs(I have a offboard GPU for example), least in my case I solve it simply removing this file (xorg auto configure at boot, only will not work if you set some specific setting), so run:

最终,即使在安装后vboxadditions,您仍会遇到解决问题,根据我的经验,问题在于您将/etc/X11/xorg.conf其配置为您特定的实际硬件规格(例如,我有一个板外 GPU),至少在我的情况下,我只需删除此文件即可解决它(xorg auto在启动时配置,只有在你设置了一些特定的设置时才会工作),所以运行:

sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.original && sudo rm /etc/X11/xorg.conf

Reference

参考