Ubuntu上Xen安裝虛擬機(jī)
方法一
dd一個(gè)空的磁盤
sudo dd if=/dev/zero of=/home/vm1.img bs=1G count=8
下載Xen VM通用配置文件
sudo wget http://mirrors.aliyun.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/xm-debian.cfg \
-O /etc/xen/vm1.conf
對(duì)下載下來的配置文件進(jìn)行相應(yīng)的修改
memory = 256
name = "vm1"
disk = [ 'tap2:tapdisk:aio:/home/vm1/vm1.img,xvda1,w']
執(zhí)行安裝命令
sudo xm create -f /etc/xen/vm1.conf -c install=true \
install-kernel="http://mirrors.aliyun.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/vmlinuz" \
install-ramdisk="http://mirrors.aliyun.com/ubuntu/dists/precise/main/installer-amd64/current/images/netboot/xen/initrd.gz" \
install-mirror="http://mirrors.aliyun.com/ubuntu"
方法二
dd一個(gè)空的磁盤
sudo dd if=/dev/zero of=/home/vm1.img bs=1G count=8
格式化磁盤
sudo dd if=/dev/zero of=/home/vm1.img bs=1G count=8
掛載磁盤
sudo mkdir /mnt/vm1
sudo mount -o loop /home/vm1.img /mnt/vm1
利用Domain0的文件系統(tǒng)創(chuàng)建DomainU的文件系統(tǒng)
#!/bin/bash
cat > /tmp/exclude.list EOF
/proc
/tmp/
/lost+found
/sys
/mnt
/media
/dev
/tmp
/home
/var/cache/apt
/var/cache/apt-xapian-index
/var/lib/apt
EOF/p>
p>#注意vmdisk變量后面的/
vmdisk='/mnt/'
rsync -arv --progress --exclude-from=/tmp/exclude.list / $vmdisk
mkdir -p ${vmdisk}/home ${vmdisk}/mnt ${vmdisk}/tmp ${vmdisk}/dev ${vmdisk}/proc ${vmdisk}/sys
卸載虛擬機(jī)磁盤
sudo umount /mnt/vm1
創(chuàng)建虛擬機(jī)配置文件
編輯vim /etc/xen/vm1.conf 如下
name = 'vm1'
vcpus = 1
memory = '2048'
disk = [ 'tap2:tapdisk:aio:/home/vm1/vm1.img,xvda,w']
vif = [ '' ]
on_reboot = 'restart'
on_crash = 'restart'
kernel = "/home/vm1/vmlinuz"
ramdisk = "/home/vm1/initrd.img"
extra = "ks=http://www.opstool.com/files/man/vm-ks.cfg"
啟動(dòng)虛擬機(jī)
sudo xm create -c /etc/xen/vm1.conf
判斷CPU是否支持虛擬化
Intel CPU的flag是vmx,AMD的CPU是svm。如果本身CPU支持但cat /proc/cpuinfo看不到,請(qǐng)檢查BIOS是否關(guān)閉了Intel的VT或AMD的SVM
cat /proc/cpuinfo | grep --color -E (vmx|svm)
查看Xen版本
cat /sys/hypervisor/version/major
cat /sys/hypervisor/version/minor
cat /sys/hypervisor/version/extra