使用VirtualBox搭建linux环境

本文描述了使用vbox搭建linux环境时可能遇到的一些问题.

virtualbox 下载地址

传送门

各发行版地址

网易镜像 搜狐镜像

可能会遇到的问题

磁盘大小选择

  • 在建立虚拟磁盘可以选择动态分配,并且尽量大一些,虽然vbox提供resize操作,但是十分不方便。动态分配磁盘不会占据很多磁盘空间。

版本选择

  • 尽量选择i386发型版,并且将cpu的PAE选项勾选上。

网络

  • 在有网络的时候将网卡从nat方式改成桥接模式,便于ssh访问。

  • 没有网络的时候可以使用如下命令映射端口,使用ssh访问

1
VBoxManage modifyvm "hostname" --natpf1 "guestssh,tcp,,2222,,22"

然后使用2222端口访问ssh服务。

  • 安装完成后,可以同过clone来重复安装相同版本发行版,但是会遇到网卡问题。解决方式如下:

注释掉第一个网卡,并改名第二个网卡为eth0

/etc/udev/rules.d/70-persistent-net.rules

1
2
3
4
5
6
7
8
9
10
11
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x8086:/sys/devices/pci0000:00/0000:00:03.0 (e1000)
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:f0:78:2b", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:/sys/devices/pci0000:00/0000:00:03.0 (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:fc:ab:9d", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

备份

使用导出虚拟机备份,推荐使用ova格式。