xm如何创建xen精简小linux虚拟机
本篇文章给大家分享的是有关xm如何创建xen精简小linux虚拟机,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、做网站、海安网络推广、重庆小程序开发公司、海安网络营销、海安企业策划、海安品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供海安建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.com
xen管理工具有xl 和xm xen版本是4.1以前使用xm/xend 以后使用xl 具体请看http://smilejay.com/2012/03/xl_or_xm/
xen虚拟机管理工具xm与virsh http://xen虚拟机管理工具xm与virsh用法
[root@kcw data]# dd if=/dev/zero of=vm02.img oflag=direct bs=1M seek=2048 count=1 #创建一个基于稀疏格式的磁盘镜像,大小2G 记录了1+0 的读入 记录了1+0 的写出 1048576字节(1.0 MB)已复制,0.00701008 秒,150 MB/秒 格式化磁盘 [root@kcw data]# mkfs.ext4 vm02.img mke2fs 1.41.12 (17-May-2010) vm02.img is not a block special device. 无论如何也要继续? (y,n) y 警告: 256 块未使用. 文件系统标签= 操作系统:Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 131328 inodes, 524288 blocks 26227 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=536870912 16 block groups 32768 blocks per group, 32768 fragments per group 8208 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 正在写入inode表: 完成 Creating journal (16384 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 21 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
挂载磁盘镜像
[root@kcw data]# mount -o loop vm02.img /mnt/
然后移植二进制文件
[root@kcw tmp]# bash bincp.sh #bincap是一个脚本 移植自己想要的命令 Your command: init /sbin/init copy lib /lib64/libnih.so.1 finished. copy lib /lib64/libnih-dbus.so.1 finished. copy lib /lib64/libdbus-1.so.3 finished. copy lib /lib64/libpthread.so.0 finished. copy lib /lib64/librt.so.1 finished. copy lib /lib64/libgcc_s.so.1 finished. copy lib /lib64/libc.so.6 finished. copy lib /lib64/ld-linux-x86-64.so.2 finished. copy /sbin/init finished. Continue: bash /bin/bash copy lib /lib64/libtinfo.so.5 finished. copy lib /lib64/libdl.so.2 finished. copy /bin/bash finished. Continue: ls /bin/ls copy lib /lib64/libselinux.so.1 finished. copy lib /lib64/libcap.so.2 finished. copy lib /lib64/libacl.so.1 finished. copy lib /lib64/libattr.so.1 finished. copy /bin/ls finished. Continue: cat /bin/cat copy /bin/cat finished. Continue:
bincopy脚本
[root@kcw tmp]# cat bincp.sh #!/bin/bash # DEST=/mnt libcp() { LIBPATH=${1%/*} [ ! -d $DEST$LIBPATH ] && mkdir -p $DEST$LIBPATH [ ! -e $DEST${1} ] && cp $1 $DEST$LIBPATH && echo "copy lib $1 finished." } bincp() { CMDPATH=${1%/*} [ ! -d $DEST$CMDPATH ] && mkdir -p $DEST$CMDPATH [ ! -e $DEST${1} ] && cp $1 $DEST$CMDPATH for LIB in `ldd $1 | grep -o "/.*lib\(64\)\{0,1\}/[^[:space:]]\{1,\}"`; do libcp $LIB done } read -p "Your command: " CMD until [ $CMD == 'q' ]; do ! which $CMD && echo "Wrong command" && read -p "Input again:" CMD && continue COMMAND=` which $CMD | grep -v "^alias" | grep -o "[^[:space:]]\{1,\}"` bincp $COMMAND echo "copy $COMMAND finished." read -p "Continue: " CMD done
测试
[root@kcw mnt]# tree . . ├── bin │ ├── bash │ ├── cat │ └── ls ├── lib64 │ ├── ld-linux-x86-64.so.2 │ ├── libacl.so.1 │ ├── libattr.so.1 │ ├── libcap.so.2 │ ├── libc.so.6 │ ├── libdbus-1.so.3 │ ├── libdl.so.2 │ ├── libgcc_s.so.1 │ ├── libnih-dbus.so.1 │ ├── libnih.so.1 │ ├── libpthread.so.0 │ ├── librt.so.1 │ ├── libselinux.so.1 │ └── libtinfo.so.5 ├── lost+found └── sbin └── init 4 directories, 18 files [root@kcw mnt]# chroot /mnt/ #切换到刚才移植命令的小系统 bash-4.1# ls bin lib64 lost+found sbin bash-4.1#
创建系统需要的目录和文件
[root@kcw mnt]# mkdir proc sys dev etc/{init,rc.d} var/{log,run} usr/{lib64} -pv mkdir: 已创建目录 "proc" mkdir: 已创建目录 "sys" mkdir: 已创建目录 "dev" mkdir: 已创建目录 "etc" mkdir: 已创建目录 "etc/init" mkdir: 已创建目录 "etc/rc.d" mkdir: 已创建目录 "var" mkdir: 已创建目录 "var/log" mkdir: 已创建目录 "var/run" mkdir: 已创建目录 "usr" mkdir: 已创建目录 "usr/{lib64}" [root@kcw mnt]# ls bin dev etc lib64 lost+found proc sbin sys usr var #修改文件 [root@kcw mnt]# cp /etc/init/rcS.conf /mnt/etc/init/ [root@kcw mnt]# vim /mnt/etc/init/rcS.conf 内容如下 start on startup stop on runlevel task # Note: there can be no previous runlevel here, if we have one it's bad # information (we enter rc1 not rcS for maintenance). Run /etc/rc.d/rc # without information so that it defaults to previous=N runlevel=S. console output exec /etc/rc.d/rc.sysinit [root@kcw ~]# vim /mnt/etc/rc.d/rc.sysinit #编辑文件 #!/bin/bash # echo -e "\tWelcome to Mini CentOS 6.6 Linux" exec /bin/bash [root@kcw ~]# chmod +x /mnt/etc/rc.d/rc.sysinit #附加执行权限
测试启动
创建虚拟机配置文件
vim /etc/xen/vm02 #配置文件必须在/etc/xen目录下 具体参数格式请man xm ramdisk="/boot/initramfs-2.6.32-504.3.3.el6.x86_64.img" kernel="/boot/vmlinuz-2.6.32-504.3.3.el6.x86_64" name="vm02" vcpus=1 memory=256 vif=['bridge=br0'] disk=['file:/data/vm02.img,xvda,w'] root="/dev/xvda ro" extra="selinux=0 3 init=/sbin/init"
启动
[root@kcw xen]# xm create vm02 Using config file "./vm02". Started domain vm02 (id=10)
[root@kcw xen]# xm list #查看 Name ID Mem VCPUs State Time(s) Domain-0 0 2048 4 r----- 10935.1 vm01 9 512 2 -b---- 12.6 vm02 10 256 1 -b---- 4.5
启动过程
[root@kcw ~]# xm create -c vm02 Using config file "/etc/xen/vm02". Started domain vm02 (id=22) Initializing cgroup subsys cpuset Initializing cgroup subsys cpu Linux version 2.6.32-504.3.3.el6.x86_64 (mockbuild@c6b8.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) ) #1 SMP Wed Dec 17 01:55:02 UTC 2014 Command line: root=/dev/xvda ro selinux=0 3 init=/sbin/init KERNEL supported cpus: Intel GenuineIntel AMD AuthenticAMD Centaur CentaurHauls ACPI in unprivileged domain disabled released 0 pages of unused memory BIOS-provided physical RAM map: Xen: 0000000000000000 - 00000000000a0000 (usable) Xen: 00000000000a0000 - 0000000000100000 (reserved) Xen: 0000000000100000 - 0000000010000000 (usable) DMI not present or invalid. last_pfn = 0x10000 max_arch_pfn = 0x400000000 init_memory_mapping: 0000000000000000-0000000010000000 RAMDISK: 0204a000 - 054d7000 No NUMA configuration found Faking a node at 0000000000000000-0000000010000000 Bootmem setup node 0 0000000000000000-0000000010000000 NODE_DATA [0000000000058000 - 000000000008bfff] bootmap [000000000008c000 - 000000000008dfff] pages 2 (7 early reservations) ==> bootmem [0000000000 - 0010000000] #0 [0000000000 - 0000001000] BIOS data page ==> [0000000000 - 0000001000] #1 [000555a000 - 0005589000] XEN PAGETABLES ==> [000555a000 - 0005589000] #2 [0000006000 - 0000008000] TRAMPOLINE ==> [0000006000 - 0000008000] #3 [0001000000 - 0002029be4] TEXT DATA BSS ==> [0001000000 - 0002029be4] #4 [000204a000 - 00054d7000] RAMDISK ==> [000204a000 - 00054d7000] #5 [00054d7000 - 000555a000] XEN START INFO ==> [00054d7000 - 000555a000] #6 [0000008000 - 0000058000] PGTABLE ==> [0000008000 - 0000058000] Zone PFN ranges: DMA 0x00000001 -> 0x00001000 DMA32 0x00001000 -> 0x00100000 Normal 0x00100000 -> 0x00100000 Movable zone start PFN for each node early_node_map[2] active PFN ranges 0: 0x00000001 -> 0x000000a0 0: 0x00000100 -> 0x00010000 SFI: Simple Firmware Interface v0.7 http://simplefirmware.org SMP: Allowing 1 CPUs, 0 hotplug CPUs No local APIC present APIC: disable apic facility PM: Registered nosave memory: 00000000000a0000 - 0000000000100000 Allocating PCI resources starting at 10000000 (gap: 10000000:f0000000) Booting paravirtualized kernel on Xen Xen version: 4.2.5-38.el6 (preserve-AD) NR_CPUS:4096 nr_cpumask_bits:1 nr_cpu_ids:1 nr_node_ids:1 PERCPU: Embedded 30 pages/cpu @ffff8800055bf000 s90968 r8192 d23720 u122880 pcpu-alloc: s90968 r8192 d23720 u122880 alloc=30*4096 pcpu-alloc: [0] 0 Xen: using vcpu_info placement Built 1 zonelists in Node order, mobility grouping on. Total pages: 64460 Policy zone: DMA32 Kernel command line: root=/dev/xvda ro selinux=0 3 init=/sbin/init PID hash table entries: 1024 (order: 1, 8192 bytes) xsave/xrstor: enabled xstate_bv 0x7, cntxt size 0x340 Checking aperture... No AGP bridge found Memory: 186168k/262144k available (5336k kernel code, 388k absent, 75588k reserved, 7017k data, 1288k init) Hierarchical RCU implementation. NR_IRQS:33024 nr_irqs:256 Console: colour dummy device 80x25 console [tty0] enabled console [hvc0] enabled allocated 1048576 bytes of page_cgroup please try 'cgroup_disable=memory' option if you don't want memory cgroups installing Xen timer for CPU 0 Detected 2993.154 MHz processor. Calibrating delay loop (skipped), value calculated using timer frequency.. 5986.30 BogoMIPS (lpj=2993154) pid_max: default: 32768 minimum: 301 Security Framework initialized SELinux: Disabled at boot. Dentry cache hash table entries: 32768 (order: 6, 262144 bytes) Inode-cache hash table entries: 16384 (order: 5, 131072 bytes) Mount-cache hash table entries: 256 Initializing cgroup subsys ns Initializing cgroup subsys cpuacct Initializing cgroup subsys memory Initializing cgroup subsys devices Initializing cgroup subsys freezer Initializing cgroup subsys net_cls Initializing cgroup subsys blkio Initializing cgroup subsys perf_event Initializing cgroup subsys net_prio CPU: Unsupported number of siblings 16 alternatives: switching to unfair spinlock SMP alternatives: switching to UP code Freeing SMP alternatives: 36k freed ftrace: converting mcount calls to 0f 1f 44 00 00 ftrace: allocating 21918 entries in 86 pages Performance Events: unsupported p6 CPU model 60 no PMU driver, software events only. NMI watchdog disabled (cpu0): hardware events not enabled Brought up 1 CPUs devtmpfs: initialized Grant table initialized regulator: core version 0.5 NET: Registered protocol family 16 PCI: Fatal: No config space access function found bio: create slabat 0 ACPI: Interpreter disabled. xen_balloon: Initialising balloon driver. last_pfn = 0x10000 max_arch_pfn = 0x400000000 vgaarb: loaded SCSI subsystem initialized usbcore: registered new interface driver usbfs usbcore: registered new interface driver hub usbcore: registered new device driver usb PCI: System does not support PCI PCI: System does not support PCI NetLabel: Initializing NetLabel: domain hash size = 128 NetLabel: protocols = UNLABELED CIPSOv4 NetLabel: unlabeled traffic allowed by default Switching to clocksource xen pnp: PnP ACPI: disabled NET: Registered protocol family 2 IP route cache hash table entries: 2048 (order: 2, 16384 bytes) TCP established hash table entries: 8192 (order: 5, 131072 bytes) TCP bind hash table entries: 8192 (order: 5, 131072 bytes) TCP: Hash tables configured (established 8192 bind 8192) TCP reno registered NET: Registered protocol family 1 Trying to unpack rootfs image as initramfs... Freeing initrd memory: 53812k freed platform rtc_cmos: registered platform RTC device (no PNP device found) futex hash table entries: 256 (order: 2, 16384 bytes) audit: initializing netlink socket (disabled) type=2000 audit(1422347438.824:1): initialized HugeTLB registered 2 MB page size, pre-allocated 0 pages VFS: Disk quotas dquot_6.5.2 Dquot-cache hash table entries: 512 (order 0, 4096 bytes) msgmni has been set to 468 alg: No test for stdrng (krng) ksign: Installing public key data Loading keyring - Added public key A25F8C29DC55AB79 - User ID: CentOS (Kernel Module GPG key) Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251) io scheduler noop registered io scheduler anticipatory registered io scheduler deadline registered io scheduler cfq registered (default) pci_hotplug: PCI Hot Plug PCI Core version: 0.5 pciehp: PCI Express Hot Plug Controller Driver version: 0.4 acpiphp: ACPI Hot Plug PCI Controller Driver version: 0.5 Non-volatile memory driver v1.3 Linux agpgart interface v0.103 crash memory driver: version 1.1 Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled brd: module loaded loop: module loaded input: Macintosh mouse button emulation as /devices/virtual/input/input0 Fixed MDIO Bus: probed ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver uhci_hcd: USB Universal Host Controller Interface driver PNP: No PS/2 controller found. Probing ports directly. mice: PS/2 mouse device common for all mice rtc_cmos: probe of rtc_cmos failed with error -16 cpuidle: using governor ladder cpuidle: using governor menu EFI Variables Facility v0.08 2004-May-17 usbcore: registered new interface driver hiddev usbcore: registered new interface driver usbhid usbhid: v2.6:USB HID core driver GRE over IPv4 demultiplexor driver TCP cubic registered Initializing XFRM netlink socket NET: Registered protocol family 17 registered taskstats version 1 XENBUS: Device with no driver: device/vbd/51712 XENBUS: Device with no driver: device/vif/0 XENBUS: Device with no driver: device/console/0 drivers/rtc/hctosys.c: unable to open rtc device (rtc0) Initalizing network drop monitor service Freeing unused kernel memory: 1288k freed Write protecting the kernel read-only data: 10240k Freeing unused kernel memory: 788k freed Freeing unused kernel memory: 1568k freed dracut: dracut-004-356.el6 device-mapper: uevent: version 1.0.3 device-mapper: ioctl: 4.27.0-ioctl (2013-10-30) initialised: dm-devel@redhat.com udev: starting version 147 dracut: Starting plymouth daemon xlblk_init: register_blkdev major: 202 blkfront: xvda: barriers disabled xvda: unknown partition table EXT4-fs (xvda): mounted filesystem with ordered data mode. Opts: dracut: Mounted root filesystem /dev/xvda dracut: Switching root Welcome to Mini CentOS 6.6 Linux bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell bash-4.1# bash-4.1# ls bin dev etc lib64 lost+found proc sbin sys tmp usr var
以上就是xm如何创建xen精简小linux虚拟机,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联行业资讯频道。
当前题目:xm如何创建xen精简小linux虚拟机
网站网址:http://pwwzsj.com/article/gdgcgj.html