标签:xen 杂记
一、xl安装centos6下在光盘镜像 isolinux目录下的两个文件
[root@node1 ~]# ll
total 40228
drwxr-xr-x 35 root root 4096 Sep 11 08:39 busybox-1.22.1
-rw-r--r-- 1 root root 2218650 Sep 11 08:08 busybox-1.22.1.tar.bz2
-rw-r--r-- 1 root root 34815427 Sep 12 05:22 initrd.img
-rw-r--r-- 1 root root 4152336 Sep 12 05:22 vmlinuz
创建目录存放:
[root@node1 ~]# mkdir /images/kernel
[root@node1 ~]# mv vmlinuz initrd.img /images/kernel/
[root@node1 xen]# pwd
/etc/xen
[root@node1 xen]# cp busybox centos
[root@node1 xen]# vim centos
name = "centos-001"
kernel = "/images/kernel/vmlinuz"
ramdisk = "/images/kernel/initrd.img"
extra = ""
vif = [ ‘bridge=xenbr0‘ ]
disk = [ ‘/images/xen/centos6.6.img,qcow2,xvda,rw‘ ]
#root = "/dev/xvda ro"
[root@node1 xen]# qemu-img create -f qcow2 -o size=120G,preallocation=metadata /images/xen/centos6.6.img
[root@node1 xen]# xl create /etc/xen/centos
[root@node1 xen]# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 1024 1 r----- 691.5
centos-001 21 512 1 r----- 5.8
连接控制界面:
[root@node1 xen]# xl console centos-001
手动配置IP:
选择镜像FTP目录
以此类推安装系统即可
[root@node1 ~]# xl destroy centos-001
修改配置文件
vim /etc/xen/centos
extra = "ks=http://172.16.0.1/centos6.x86_64.cfg"
on_reboot = "shutdown"
开机后就会自动安装系统
[root@node1 xen]# xl create /etc/xen/centos
vim /etc/xen/centos
name = "centos-001"
bootloader = "pygrub"
memory = 512
vcpus = 1
vif = [ ‘bridge=xenbr0‘ ]
disk = [ ‘/images/xen/centos6.6.img,qcow2,xvda,rw‘ ]
# xl shutdown centos-001
[root@node1 xen]# yum info cloud-init
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Available Packages
Name : cloud-init
Arch : noarch
Version : 0.7.4
Release : 2.el6
Size : 487 k
Repo : ali-epel
Summary : Cloud instance init scripts
[root@node1 xen]# vim /etc/xen/busybox
vfb = [ ‘sbl=1‘ ]
测试:
[root@node1 ~]# yum install tigervnc
[root@node1 ~]# vim /etc/sysconfig/vncservers
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 800x600"
[root@node1 ~]# vim /etc/xen/centos
vfb = [ ‘vnc=1‘ ]
vfb = [ ‘vnc=1,vnclisten=0.0.0.0,vncpasswd=123456‘ ]
fdisk /dev/sda
Last cylinder, +cylinders or +size{K,M,G} (24134-32636, default 32636): +30G
/dev/sda11 24134 28050 31463302+ 83 Linux
Command (m for help): t
Partition number (1-11): 11
Hex code (type L to list codes): 8e
/dev/sda11 24134 28050 31463302+ 8e Linux LVM
[root@node1 ~]# partx -a /dev/sda
[root@node1 ~]# partx -a /dev/sda
如果遇到系统grub损坏,进入拯救模式:
# grub-install /dev/sda
创建物理卷
[root@node1 ~]# pvcreate /dev/sda11
Physical volume "/dev/sda11" successfully created
创建卷组:
[root@node1 ~]# vgcreate myvg /dev/sda11
Volume group "myvg" successfully created
创建名为“bbox”的逻辑卷
[root@node1 ~]# lvcreate -L 2G -n bbox myvg
Logical volume "bbox" created.
格式化:
[root@node1 ~]# mke2fs -t ext2 /dev/myvg/bbox
挂载:
[root@node1 ~]# mount /dev/myvg/bbox /mnt/
[root@node1 ~]# cp -a busybox-1.22.1/_install/* /mnt/
[root@node1 mnt]# cd /mnt/
[root@node1 mnt]# mkdir -pv proc dev sys tmp etc var boot usr
# cd /etc/xen/
[root@node1 xen]# cp busybox bbox
[root@node1 xen]# vim bbox
name = "bbox-001"
kernel = "/boot/vmlinuz"
ramdisk = "/boot/initramfs.img"
extra = "selinux=0 init=/bin/sh"
vif = [ ‘bridge=xenbr0‘ ]
disk = [ ‘/dev/myvg/bbox,raw,xvda,rw‘ ]
查看生成的配置信息:
[root@node1 xen]# xl create bbox -n
启动测试:
[root@node1 xen]# xl create bbox -c
/ #
[root@node1 xen]# yum install libvirt libvirt-daemon-xen.x86_64 virt-manager
[root@node1 xen]# service libvirtd start
启动,会弹出图形界面
[root@node1 xen]# virt-manager
弹出第一个窗口点 no
创建虚拟机:
图形界面很简单,就不截图了。
磁盘目录 /var/lib/libvirt/images/
[root@node1 ~]# yum install libvirt-client
[root@node1 ~]# virsh help
查看处于运行的虚拟机
[root@node1 ~]# virsh list
Id Name State
----------------------------------------------------
0 Domain-0 running
关闭虚拟机
[root@node1 ~]# virsh destroy centos
标签:xen 杂记
原文地址:http://blog.51cto.com/zhongle21/2086908