且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Xen 安装ubuntu xen DomU

更新时间:2022-09-13 17:43:43

Xen 安装ubuntu xen DomU

我文章已经写过 linux(ubuntu) install xen-3.4.2 ,没看过的朋友可以去看看,接下来我们安装虚拟系统,因为我的CPU不支持VT,所以我先注重说一下半虚拟化虚拟系统,先说我喜欢用的 debootstrap。
操作环境:
ISO:ubuntu-8.04.2-server-i386.iso
Dom0 : ubuntu-server 8.0.4
xen : 3.4.2
准备安装 虚拟系统
DomU : ubuntu-server 8.0.4
步骤:
一.安装虚拟系统:
新建一个4G的镜象文件,还是希望你用真实磁盘,因为这样会减少I/O平颈。
shell$> dd if=/dev/zero of=ubuntu.img bs=1M count=1 seek=4000
shell$>dd if=/dev/zero of=swap.img bs=1M count=1 seek=256
####格式化镜象文件####
shell$>mkfs.ext3 ubuntu.img
shell$>mkswap
#### 挂载ISO文件####
shell$>mount -o loop ubuntu-8.04.2-server-i386.iso /mnt
#####挂载空的静象文件到新建立的ubuntu文件夹####
shell$>mkdir  ubuntu
shell$> mount -o loop ubuntu.img ubuntu
#### 初始化环境########
shell$>/usr/bin/env -i HOME=/root TERM=$TERM PATH=/bin:/usr/bin:/sbin:/usr/sbin
####debootstrap通过ISO文件,安装纯净系统####
#### –arch i386 的意思32位,hardy 是ubuntu版本 8.0.4   ubuntu 是安装到哪个目录下###
shell$>/usr/sbin/debootstrap –arch i386 hardy ubuntu/ file:/mnt/ubuntu/
### 复制内核心模块进 虚拟系统###
shell $> cp /lib/modules/2.6.18.8-xenU  ubuntu/lib/modules/ -R
### 挂载 proc  dev ###chroot进系统配置系统
shell$>mount -t proc none ubuntu/proc
shell$>mount -o bind /dev ubuntu/dev
shell$>LANG=C chroot ubuntu /bin/bash
###给root创建密码
shell$>passwd root
shell$>dpkg-reconfigure –default-priority passwd
###加入apt-get 源###
shell$>vim /etc/apt/sources.list
deb http://mirrors.163.com/ubuntu/ hardy main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ hardy-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ hardy-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ hardy-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ hardy-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ hardy main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ hardy-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ hardy-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ hardy-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ hardy-backports main restricted universe multiverse
###更新源###安装openssh-server###
shell$>apt-get update
shell$>apt-get install openssh-server
#### 修改 IP 地址
shell $>vim /etc/network/interfaces
auto lo iface lo inet loopback
# The primary network interface
auto eth0 iface eth0 inet static
address 192.168.6.101
netmask 255.255.255.0
network 192.168.6.0
broadcast 192.168.6.255
gateway 192.168.6.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 202.106.0.20
###修改hostname 和 hosts
shell$>vim /etc/hostname
nginx
shell$>vim /etc/hosts
127.0.0.1       localhost
127.0.1.1       nginx          nginxs.com
#### 修改 fstab####
shell$> vim /etc/fstab
proc            /proc           proc    defaults        0       0
/dev/sda1       /               ext3    defaults,errors=remount-ro 0       1
/dev/sda2       none            swap    sw              0       0
### 卸载挂载区###
shell$>umount ubuntu/proc
shell$>umount ubuntu/dev
shell$>umount ubuntu
二. 创建 xen配置文件系统
shell $> cd /opt/
shell$>vim ubuntu.cfg
kernel = “/boot/vmlinuz-2.6.18.8-xenU”
ramdisk = “/boot/initrd.img-2.6.18.8-xenU”
memory = 256
name = “ubuntu”
disk = ['file:/ubuntu/ubuntu.img,sda1,w','file:/ubuntu/swap.img,sda2,w']
root = “/dev/sda1 ro”
on_poweroff = ‘destroy’
on_reboot   = ‘restart’
on_crash    = ‘restart’
vcpus       = ‘2′
extra = ‘xencons=tty1′
vif = [ '' ]
三,启动虚拟机“`
shell $> xm create ubuntu.cfg
shell $>xm list
xm list Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0   502     2     r—–  22161.
ubuntu                                          1   256     2     -b—-    439.0
四,连接虚拟机。
##xm console  可以连接 Domain 名 也可以连接ID ,我就连接的ID
shell$> xm console  1
 

本文转自Deidara 51CTO博客,原文链接:http://blog.51cto.com/deidara/270108,如需转载请自行联系原作者