无来

不管你来还是不来
我都在这里,夜夜点亮
不是为了守候
只是为了做好我自己

0%

Oracle VirtualBox is a cross-platform virtualization application. It installs on your existing Intel or AMD-based computers, whether they are running Windows, Mac, Linux or Solaris operating systems. It extends the capabilities of your existing computer so that it can run multiple operating systems at the same time. Click here to read more about VirtualBox

Oracle has released VirtualBox 5.1.14 maintenance release of VirtualBox 5.1 on January 17th, 2017. In this release VirtualBox has improves stability and fixes regressions. To read more about this release read changelog.

This article will help you to install Oracle VirtualBox 5.1 on CentOS, Redhat and Fedora systems using Yum.

Step 1 – Add Required Yum Repositories

Firstly you are required to add VirtualBox yum repository in your system. Download repository file from its official site and place it under at __ /etc/yum.repos.d/virtualbox.repo __ .First navigate to /etc/yum.repos.d/ directory and use one of below commands as per your operating system.

1
2
3
4
5
6
7
# cd /etc/yum.repos.d/

For CentOS/RHEL Systems:
# wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo

For Fedora Systems:
# wget http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo

__ CentOS/RHEL __ Users also need to add EPEL yum repository using one of the following commands.

1
2
3
4
5
6
CentOS/RHEL 7, 64 Bit (x86_64):
# rpm -Uvh http://epel.mirror.net.in/epel/7/x86_64/e/epel-release-7-9.noarch.rpm

CentOS/RHEL 6, 64 Bit (x86_64):
# rpm -Uvh http://epel.mirror.net.in/epel/6/x86_64/epel-release-6-8.noarch.rpm

Step 2 – Install Required Packages

Before installing VirtualBox make sure to install all required packages to run VirtualBox like kernel-headers, kernel-devels etc. Use the following command to install required packages.

1
2
# yum install gcc make patch  dkms qt libgomp
# yum install kernel-headers kernel-devel fontforge binutils glibc-headers glibc-devel

Step 3 – Setup Environment Variable

VirtualBox installation required kernel source code to install required modules, So we need to configure environment variable __ KERN_DIR __ to which VirtualBox get kernel source code. In my case latest kernel source is available in ** 2.6.32-504.3.3.el6.x86_64 ** directory under ** /usr/src/kernels/ **. Make sure you are using correct source path.

1
# export KERN_DIR=/usr/src/kernels/2.6.32-504.3.3.el6.x86_64

Step 4 – Install Oracle VirtualBox and Setup

Use the following command to install VirtualBox 5.1 using yum command line tool. It will install the latest version of VirtualBox 5.1.x on your system.

1
# yum install VirtualBox-5.1

After installation, we need to rebuild kernel modules using the following command.

1
sudo /usr/lib/virtualbox/vboxdrv.sh setup

Step 5 – Start VirtualBox

Use following command to start VirtualBox from X windows. You can switch to GUI mode using ** init 5 ** or ** startx ** commands from terminal.

1
# virtualbox &

一、 Mac下将ISO写入U盘可使用命令行工具dd,操作如下:

1、找出U盘挂载的路径,使用如下命令:diskutil list

2、将U盘unmount(将N替换为挂载路径):diskutil unmountDisk /dev/disk[N]

3、写入U盘:sudo dd if=iso路径 of=/dev/rdisk[N] bs=1m rdisk 中加入r可以让写入速度加快

二、具体操作示例:

  1. 将iso转换成dmg 转iso 用

UDRW 替换为 UDTO

1
2
3
4
5
6
7
8
9
10
11
12
lapommedeMacBook-Pro:~ lapomme$ sudo hdiutil convert -format UDRW -o /linux.dmg kali.iso
Password:
正在读取Master Boot Record(MBR:0)…
正在读取Kali Live (Apple_ISO:1)…
正在读取(Windows_NTFS_Hidden:2)…
............................................................................
正在读取(DOS_FAT_12:3)…
..............................................................................
已耗时:10.178s
速度:288.3M 字节/秒
节省:0.0%
created: /linux.dmg
  1. 查看u盘盘符

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    lapommedeMacBook-Pro:~ lapomme$ diskutil list
    /dev/disk0 (internal, physical):
    #: TYPE NAME SIZE IDENTIFIER
    0: GUID_partition_scheme *251.0 GB disk0
    1: EFI EFI 209.7 MB disk0s1
    2: Apple_CoreStorage Macintosh HD 250.1 GB disk0s2
    3: Apple_Boot Recovery HD 650.0 MB disk0s3
    /dev/disk1 (internal, virtual):
    #: TYPE NAME SIZE IDENTIFIER
    0: Apple_HFS Macintosh HD +249.8 GB disk1
    Logical Volume on disk0s2
    E2BD4617-5A22-46A9-A6F4-D54E3EE92BBC
    Unencrypted
    /dev/disk2 (external, physical):
    #: TYPE NAME SIZE IDENTIFIER
    0: FDisk_partition_scheme *62.0 GB disk2
    1: DOS_FAT_32 UNTITLED 1 62.0 GB disk2s1
    /dev/disk3 (disk image):
    #: TYPE NAME SIZE IDENTIFIER
    0: FDisk_partition_scheme +3.1 GB disk3
    1: 0x17 3.0 GB disk3s1
    2: DOS_FAT_12 NO NAME 110.1 MB disk3s2
  2. 取消挂载U盘

    1
    2
    lapommedeMacBook-Pro:~ lapomme$ diskutil umountDisk /dev/disk2
    Unmount of all volumes on disk2 was successful
  3. 用dd命令写入U盘

说明:

(1)sudo dd if=源路径 of=/dev/r卷标 bs=1m [‘r’ 会让命令执行加快一点] [‘bs’为一次填充的容量]

(2)获取映像名称和完整路径可以直接将文件拖入终端,即在终端中显示

1
2
3
4
lapommedeMacBook-Pro:~ lapomme$ sudo dd if=/linux.dmg of=/dev/rdisk2 bs=1m
2934+1 records in
2934+1 records out
3076767744 bytes transferred in 149.567568 secs (20571089 bytes/sec)
  1. 查看磁盘进度,可以用iostat命令查看磁盘写入状态

    1
    2
    3
    4
    5
    6
    7
    lapommedeMacBook-Pro:~ lapomme$ iostat -w 2
    disk0 disk2 disk3 cpu load average
    KB/t tps MB/s KB/t tps MB/s KB/t tps MB/s us sy id 1m 5m 15m
    102.71 25 2.49 598.70 0 0.15 24.76 1 0.02 5 4 90 2.04 1.71 1.69
    512.00 48 23.93 1024.00 24 23.93 0.00 0 0.00 1 3 96 2.11 1.74 1.69
    473.00 26 11.99 1024.00 12 11.98 0.00 0 0.00 3 3 93 2.11 1.74 1.69
    491.68 50 23.99 1024.00 24 23.99 0.00 0 0.00 24 8 68 2.11 1.74 1.69
  2. 操作完毕后将U盘弹出

    1
    2
    lapommedeMacBook-Pro:~ lapomme$ diskutil eject /dev/disk2
    Disk /dev/disk2 ejected

1.导出OVA -> test.ova

2.copy到服务器&导入

1
[root@localhost vm] BoxManage import test.ovf

查看虚拟机镜像文件配置信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
[root@localhost vm]# VBoxManage showvminfo HKAirline
Name: HKAirline
Groups: /
Guest OS: Red Hat (64-bit)
UUID: 041f669d-2974-4322-a046-a55903285424
Config file: /root/VirtualBox VMs/HKAirline/HKAirline.vbox
Snapshot folder: /root/VirtualBox VMs/HKAirline/Snapshots
Log folder: /root/VirtualBox VMs/HKAirline/Logs
Hardware UUID: 041f669d-2974-4322-a046-a55903285424
Memory size: 2048MB
Page Fusion: off
VRAM size: 16MB
CPU exec cap: 100%
HPET: off
Chipset: piix3
Firmware: BIOS
Number of CPUs: 1
PAE: on
Long Mode: on
Triple Fault Reset: off
APIC: on
X2APIC: on
CPUID Portability Level: 0
CPUID overrides: None
Boot menu mode: message and menu
Boot Device (1): Floppy
Boot Device (2): DVD
Boot Device (3): HardDisk
Boot Device (4): Not Assigned
ACPI: on
IOAPIC: on
BIOS APIC mode: APIC
Time offset: 0ms
RTC: UTC
Hardw. virt.ext: on
Nested Paging: on
Large Pages: on
VT-x VPID: on
VT-x unr. exec.: on
Paravirt. Provider: Default
Effective Paravirt. Provider: KVM
State: powered off (since 2017-08-03T11:27:45.000000000)
Monitor count: 1
3D Acceleration: off
2D Video Acceleration: off
Teleporter Enabled: off
Teleporter Port: 0
Teleporter Address:
Teleporter Password:
Tracing Enabled: off
Allow Tracing to Access VM: off
Tracing Configuration:
Autostart Enabled: off
Autostart Delay: 0
Default Frontend:
Storage Controller Name (0): IDE
Storage Controller Type (0): PIIX4
Storage Controller Instance Number (0): 0
Storage Controller Max Port Count (0): 2
Storage Controller Port Count (0): 2
Storage Controller Bootable (0): on
Storage Controller Name (1): SATA
Storage Controller Type (1): IntelAhci
Storage Controller Instance Number (1): 0
Storage Controller Max Port Count (1): 30
Storage Controller Port Count (1): 2
Storage Controller Bootable (1): on
IDE (1, 0): Empty
SATA (0, 0): /root/VirtualBox VMs/HKAirline/HKAirline-disk001.vmdk (UUID: 6afa88f3-3035-4aa5-a940-f6ec43bc56bb)
NIC 1: MAC: 0800274D5932, Attachment: Bridged Interface 'eth0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 2: MAC: 0800279B57E7, Attachment: Bridged Interface 'eth0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 3: MAC: 080027716E47, Attachment: Bridged Interface 'eth0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 4: MAC: 080027C363BB, Attachment: Bridged Interface 'eth0', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 5: disabled
NIC 6: disabled
NIC 7: disabled
NIC 8: disabled
Pointing Device: PS/2 Mouse
Keyboard Device: PS/2 Keyboard
UART 1: disabled
UART 2: disabled
UART 3: disabled
UART 4: disabled
LPT 1: disabled
LPT 2: disabled
Audio: enabled (Driver: ALSA, Controller: AC97, Codec: AD1980)
Clipboard Mode: disabled
Drag and drop Mode: disabled
VRDE: enabled (Address 0.0.0.0, Ports 3389, MultiConn: off, ReuseSingleConn: off, Authentication type: external)
Video redirection: disabled
VRDE property: TCP/Ports = "3389"
VRDE property: TCP/Address = <not set>
VRDE property: VideoChannel/Enabled = <not set>
VRDE property: VideoChannel/Quality = <not set>
VRDE property: VideoChannel/DownscaleProtection = <not set>
VRDE property: Client/DisableDisplay = <not set>
VRDE property: Client/DisableInput = <not set>
VRDE property: Client/DisableAudio = <not set>
VRDE property: Client/DisableUSB = <not set>
VRDE property: Client/DisableClipboard = <not set>
VRDE property: Client/DisableUpstreamAudio = <not set>
VRDE property: Client/DisableRDPDR = <not set>
VRDE property: H3DRedirect/Enabled = <not set>
VRDE property: Security/Method = <not set>
VRDE property: Security/ServerCertificate = <not set>
VRDE property: Security/ServerPrivateKey = <not set>
VRDE property: Security/CACertificate = <not set>
VRDE property: Audio/RateCorrectionMode = <not set>
VRDE property: Audio/LogPath = <not set>
USB: enabled
EHCI: disabled
XHCI: disabled

USB Device Filters:

<none>

Bandwidth groups: <none>

Shared folders: <none>

Video capturing: not active
Capture screens: 0
Capture file: /root/VirtualBox VMs/HKAirline/HKAirline.webm
Capture dimensions: 1024x768
Capture rate: 512 kbps
Capture FPS: 25

Guest:

Configured memory balloon size: 0 MB

3.检查服务器的网卡名称

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@localhost var]# ifconfig
enp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 11.0.0.30 netmask 255.255.255.0 broadcast 11.0.0.255
inet6 fe80::7627:eaff:fe0b:cbdd prefixlen 64 scopeid 0x20<link>
ether 74:27:ea:0b:cb:dd txqueuelen 1000 (Ethernet)
RX packets 1176518 bytes 1473593219 (1.3 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 629933 bytes 45138166 (43.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 83 bytes 7928 (7.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 83 bytes 7928 (7.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


5. 启动网卡配置

1
/usr/lib/virtualbox/vboxdrv.sh setup

5.1 安装内核

1
2
3
4
5
6
7
8
9
[root@localhost ~]# yum install kernel-headers-$(uname -r)
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* epel: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.btte.net
* updates: mirror.bit.edu.cn
No package kernel-headers-3.10.0-327.el7.x86_64 available.
Error: Nothing to do

5.2 查看内核

1
2
3
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

5.3 下载匹配内核

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@localhost ~]# wget ftp://ftp.pbone.net/mirror/ftp.scientificlinux.org/linux/scientific/7.0/x86_64/updates/security/kernel-devel-3.10.0-
327.el7.x86_64.rpm
--2017-08-03 09:00:48-- ftp://ftp.pbone.net/mirror/ftp.scientificlinux.org/linux/scientific/7.0/x86_64/updates/security/kernel-devel-3.10.0-327.el7.x86_64.rpm
=> ‘kernel-devel-3.10.0-327.el7.x86_64.rpm.1’
Resolving ftp.pbone.net (ftp.pbone.net)... 85.14.85.4
Connecting to ftp.pbone.net (ftp.pbone.net)|85.14.85.4|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD (1) /mirror/ftp.scientificlinux.org/linux/scientific/7.0/x86_64/updates/security ... done.
==> SIZE kernel-devel-3.10.0-327.el7.x86_64.rpm ... 11470260
==> PASV ... done. ==> RETR kernel-devel-3.10.0-327.el7.x86_64.rpm ... done.
Length: 11470260 (11M) (unauthoritative)

100%[====================================================================================================>] 11,470,260 603KB/s in 28s

2017-08-03 09:01:21 (406 KB/s) - ‘kernel-devel-3.10.0-327.el7.x86_64.rpm’ saved [11470260]


安装依赖包

1
yum install make gcc libpcap libpcap-devel -y

安装

通过如下命令直接安装:

1
rpm -ivh kernel-devel-3.10.0-327.el7.x86_64.rpm

如果系统已经安装了较高版本的内核头文件,则需要通过如下命令实现降级:

1
rpm -Uvh --oldpackage kernel-devel-3.10.0-327.el7.x86_64.rpm

查看Bradge接口

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost vm]# VBoxManage list bridgedifs
Name: enp3s0
GUID: 33706e65-3073-4000-8000-7427ea0bcbdd
DHCP: Disabled
IPAddress: 11.0.0.30
NetworkMask: 255.255.255.0
IPV6Address: fe80:0000:0000:0000:7627:eaff:fe0b:cbdd
IPV6NetworkMaskPrefixLength: 64
HardwareAddress: 74:27:ea:0b:cb:dd
MediumType: Ethernet
Status: Up
VBoxNetworkName: HostInterfaceNetworking-enp3s0

修改网卡设备的名称

1
[root@localhost vm]# VBoxManage modifyvm HKAirline --bridgeadapter4 enp3s0

启动虚拟机

1
VBoxManage startvm HKAirline --type headless

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ cat /etc/tmpfiles.d/tmp.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.

# See tmpfiles.d(5) for details

# Clear tmp directories separately, to make them easier to override
D /tmp 1777 root root 0
D /var/tmp 1777 root root 10d

# Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-*
x /var/tmp/systemd-private-*
X /tmp/systemd-private-*/tmp
X /var/tmp/systemd-private-*/tmp

548
down vote
yes, Brian, you are right: those are the steps, but if you want to end having back a vmdk hard disk (maybe you are interested in using the disk in vwmare too) you miss one more step. So the complete howto is:

1
2
3
4
VBoxManage clonehd "source.vmdk" "cloned.vdi" --format vdi
VBoxManage modifyhd "cloned.vdi" --resize 51200
VBoxManage clonehd "cloned.vdi" "resized.vmdk" --format vmdk
The above will resize the hard disk up to 50GB (50 * 1024MB).

To complete things you need to resize the drive too! To achieve this, you might want to download gparted iso and boot from that iso to resize your drive (select the iso from within the virtualbox settings).

P.S. If your new size is too small, you’ll get the same error even with your new vdi file.

1
down vote
In case it is a fixed drive and not a removable drive, you can add the entry permanently.

1
sudo vi /etc/fstab

Add an entry in the following format:

1
<file-system> <mount-point> <type> <options> <dump> <pass>

And then do:

1
mount -a

mount -o remount,rw /

0 Prepare

yum install pciutils -y

1 get PCI info:

1
2
3
4
5
6
[root@localhost ~] lspci | grep Ethernet   
05:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
06:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
07:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
08:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection

2 add config to cat /usr/lib/udev/rules.d/60-net.rules.

Notice: param KERNELS

1
2
3
4
5
6
[root@localhost ~]# cat /usr/lib/udev/rules.d/60-net.rules
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", ATTR{type}=="1", PROGRAM="/lib/udev/rename_device", RESULT=="?*", NAME="$result"
SUBSYSTEMS=="pci", ACTION=="add", DRIVERS=="?*", KERNELS=="0000:00:05.0", NAME="vfnet0"
SUBSYSTEMS=="pci", ACTION=="add", DRIVERS=="?*", KERNELS=="0000:00:06.0", NAME="vfnet1"
SUBSYSTEMS=="pci", ACTION=="add", DRIVERS=="?*", KERNELS=="0000:00:07.0", NAME="vfnet2"
SUBSYSTEMS=="pci", ACTION=="add", DRIVERS=="?*", KERNELS=="0000:00:08.0", NAME="vfnet3"

3 reboot

4 check

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@localhost ~]# cat /usr/lib/udev/rules.d/60-net.rules
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: vfnet0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
link/ether f2:d5:5d:21:4e:38 brd ff:ff:ff:ff:ff:ff
3: vfnet1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
link/ether 3e:ec:21:1a:d2:86 brd ff:ff:ff:ff:ff:ff
4: vfnet2: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
link/ether be:70:05:01:46:04 brd ff:ff:ff:ff:ff:ff
5: vfnet3: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP qlen 1000
link/ether e6:de:61:c9:a8:d1 brd ff:ff:ff:ff:ff:ff

I’ve learned how to continue to use the ethX prefix. I’m still using the udev rules that I mentioned in post above. So at bootup udev will rename my interfaces netX. And then using /etc/rc.local I’ve included the following commands to rename them from netX back to ethX.

1
2
3
4
/sbin/ip link set net0 down
/sbin/ip link set net0 name eth0
/sbin/ip link set eth0 up
...

Using the ip command I can change the name of the interfaces after the initial bootup is completed.