» VirtualBox使用U盘启动系统自由空间Feelings, thoughts, freedom ...

五月 22nd, 2010 | admin |

      在《VirtualBox使用U盘》一篇中,仅仅介绍了怎样使得guest使用U盘。而前段时间去机房使用我的U盘的时候,发现里面什么都没有,还好里面东西比较少,只有一个LiveUSB系统,格式化,从新安装我的LiveUSB系统。但是我是怎么知道安装后的LiveUSB是否为可启动呢?重启电脑,调BIOS为USB启动,就知道了。但是这样需要重启电脑,调BIOS,于是就想到了VirtualBox不是可以虚拟电脑吗?
      打开VirtualBox看看设置里面,发现boot order里面只有软盘,硬盘,光盘,网络。就是没有USB,那怎么办呢?想了想,在添加硬盘的时候不是可以使用物理硬盘吗?那我的U盘也当作物理硬盘不就行了吗?翻开UserManual.pdf,找找看。发现有下面的东东:

5 Virtual storage
As the virtual machine will most probably expect to see a hard disk built into its virtual computer, VirtualBox must be able to present “real” storage to the guest as a virtual hard disk. There are presently three methods in which to achieve this:
   1. Most commonly, VirtualBox will use large image ?les on a real hard disk and
      present them to a guest as a virtual hard disk. This is described in chapter
      5.2,Disk image ?les (VDI, VMDK, VHD, HDD), page 81.
   2. Alternatively, if you have iSCSI storage servers, you can attach such a
      server to VirtualBox as well; this is described in chapter 5.9, iSCSI servers,
      page 89.
   3. Finally, as an experimental feature, you can allow a virtual machine to
      access one of your host disks directly; this advanced feature is described in
      chapter 9.5.1,

      Using a raw host hard disk from a guest, page 150.

有三种方法添加硬盘,注意第三种方法(Finally,红色部分)是这里需要的。于是跟着它的指引到了150页。

Warning: Raw hard disk access is for expert users only. Incorrect use or use
of an outdated con?guration can lead to total loss of data on the physical
disk. Most importantly, do not attempt to boot the partition with the cur-
rently running host operating system in a guest. This will lead to severe data
corruption.

意思是说,Raw hard disk 模式只是给专家使用,使用不正确将会导致整个物理磁盘的数据丢失。丫的,反正我是做实验,丢失就丢失咯,不怕它。继续看下来:

Raw hard disk access – both for entire disks and individual partitions – is imple- mented as part of the VMDK image format support. As a result, you will need to create a special VMDK image ?le which de?nes where the data will be stored. After creating such a special VMDK image, you can use it like a regular virtual disk image. For exam- ple, you can use the Virtual Media Manager (chapter 5.3, The Virtual Media Manager, page 82) or VBoxManage to assign the image to a virtual machine.

需要创建一个VMDK镜像,可以使用VBoxManage创建。太强大了VBoxManage.

9.5.1.1 Access to entire physical hard disk
While this variant is the simplest to set up, you must be aware that this will give a guest operating system direct and full access to an entire physical disk. If your host operating system is also booted from this disk, please take special care to not access the partition from the guest at all. On the positive side, the physical disk can be repartitioned in arbitrary ways without having to recreate the image ?le that gives access to the raw disk. To create an image that represents an entire physical hard disk (which will not contain any actual data, as this will all be stored on the physical disk), on a Linux host, use the command VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk -rawdisk /dev/sda
This creates the image /path/to/file.vmdk (must be absolute), and all data will be read and written from /dev/sda.

再一次提醒,这样的vmdk是直接对物理磁盘操作(读写等),会对磁盘的数据有一定的风险,消极点说,可能会破坏磁盘原有的分区结构。
md的,偶不怕,又不是拿真正的硬盘来使用,U盘而已。。反正做实验。呵呵。
按照它给出的命令来创建就行了。偶的步骤如下:
1、插上U盘。记得所有的guest都不能使用该U盘,具体操作是在guest窗口上:设备->分配USB设备->将对应的USB设备不要选中。
2、等host挂载好U盘后,使用df来看看U盘的设备文件是哪个。如我的:

[yorks@localhost VirtualBox]$ df -h
文件系统              容量  已用 可用 已用% 挂载点
/dev/sda9              15G  9.5G  4.0G  71% /
/dev/shm              950M     0  950M   0% /dev/shm
/dev/sda1              20G   13G  6.7G  66% /winC
/dev/sda2             9.5G  6.7G  2.3G  75% /otherLinux
/dev/sda3              45G   39G  6.3G  87% /Data
/dev/sda5              25G   22G  3.3G  87% /Medium
/dev/sda6              15G   11G  4.0G  74% /winD
/dev/sda7              19G   17G  1.7G  91% /home
/dev/sdb1             981M  751M  230M  77% /media/disk

对应的U盘就是/dev/sdb

3、赋予当前用户对/dev/sdb读写的权力:

[root@localhost VirtualBox]# ls -l /dev/sdb
brw-rw—- 1 root disk 8, 16 05-22 11:33 /dev/sdb
[root@localhost VirtualBox]# ls -l /dev/sdb
brw-rw—- 1 root disk 8, 16 05-22 11:33 /dev/sdb
[root@localhost VirtualBox]# chmod o+rw /dev/sdb
[root@localhost VirtualBox]# ls -l /dev/sdb
brw-rw-rw- 1 root disk 8, 16 05-22 11:33 /dev/sdb
[root@localhost VirtualBox]# exit

4、创建vmdk镜像文件:

[yorks@localhost VirtualBox]$ VBoxManage internalcommands createrawvmdk -filename /Data/virtual_pc/usbDisk.vmdk -rawdisk /dev/sdb
Sun VirtualBox Command Line Management Interface Version 3.1.6
(C) 2005-2010 Sun Microsystems, Inc.
All rights reserved.

RAW host disk access VMDK file /Data/virtual_pc/usbDisk.vmdk created successfully.

5、新建guest添加磁盘的时候使用刚刚创建的usbDisk.vmdk文件。

6、启动guest,成功。

整个过程并不复杂,但是具有危险性,所有建议备份好U盘的资料,再使用该功能。


Leave a Comment

注意: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。使用'@all ',将会将评论发送给之前所有其它评论者。请务必注意user必须和评论者名相匹配(大小写一致)。

郑重声明:资讯 【» VirtualBox使用U盘启动系统自由空间Feelings, thoughts, freedom ...】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——