千家信息网

xm如何创建xen精简小linux虚拟机

发表于:2025-01-25 作者:千家信息网编辑
千家信息网最后更新 2025年01月25日,本篇文章给大家分享的是有关xm如何创建xen精简小linux虚拟机,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。xen管理工具有xl 和
千家信息网最后更新 2025年01月25日xm如何创建xen精简小linux虚拟机

本篇文章给大家分享的是有关xm如何创建xen精简小linux虚拟机,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

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 blocks131328 inodes, 524288 blocks26227 blocks (5.00%) reserved for the super user第一个数据块=0Maximum filesystem blocks=53687091216 block groups32768 blocks per group, 32768 fragments per group8208 inodes per groupSuperblock 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 or180 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/initcopy 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/bashcopy lib /lib64/libtinfo.so.5 finished.copy lib /lib64/libdl.so.2 finished.copy /bin/bash finished.Continue: ls/bin/lscopy 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/catcopy /bin/cat finished.Continue:

bincopy脚本

[root@kcw tmp]# cat bincp.sh #!/bin/bash#DEST=/mntlibcp() {  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: " CMDuntil [ $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: " CMDdone

测试

[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    └── init4 directories, 18 files[root@kcw mnt]# chroot /mnt/  #切换到刚才移植命令的小系统bash-4.1# lsbin  lib64  lost+found      sbinbash-4.1#

创建系统需要的目录和文件

[root@kcw mnt]# mkdir proc sys dev etc/{init,rc.d} var/{log,run} usr/{lib64} -pvmkdir: 已创建目录 "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]# lsbin  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 startupstop on runleveltask# 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 outputexec /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 xmramdisk="/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=1memory=256vif=['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 vm02Using 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.1vm01                                         9   512     2     -b----     12.6vm02                                        10   256     1     -b----      4.5

启动过程

[root@kcw ~]# xm create -c vm02Using config file "/etc/xen/vm02".Started domain vm02 (id=22)Initializing cgroup subsys cpusetInitializing cgroup subsys cpuLinux 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 2014Command line: root=/dev/xvda ro selinux=0 3 init=/sbin/initKERNEL supported cpus:  Intel GenuineIntel  AMD AuthenticAMD  Centaur CentaurHaulsACPI in unprivileged domain disabledreleased 0 pages of unused memoryBIOS-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 = 0x400000000init_memory_mapping: 0000000000000000-0000000010000000RAMDISK: 0204a000 - 054d7000No NUMA configuration foundFaking a node at 0000000000000000-0000000010000000Bootmem 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 -> 0x00100000Movable zone start PFN for each nodeearly_node_map[2] active PFN ranges    0: 0x00000001 -> 0x000000a0    0: 0x00000100 -> 0x00010000SFI: Simple Firmware Interface v0.7 http://simplefirmware.orgSMP: Allowing 1 CPUs, 0 hotplug CPUsNo local APIC presentAPIC: disable apic facilityPM: Registered nosave memory: 00000000000a0000 - 0000000000100000Allocating PCI resources starting at 10000000 (gap: 10000000:f0000000)Booting paravirtualized kernel on XenXen version: 4.2.5-38.el6 (preserve-AD)NR_CPUS:4096 nr_cpumask_bits:1 nr_cpu_ids:1 nr_node_ids:1PERCPU: Embedded 30 pages/cpu @ffff8800055bf000 s90968 r8192 d23720 u122880pcpu-alloc: s90968 r8192 d23720 u122880 alloc=30*4096pcpu-alloc: [0] 0 Xen: using vcpu_info placementBuilt 1 zonelists in Node order, mobility grouping on.  Total pages: 64460Policy zone: DMA32Kernel command line: root=/dev/xvda ro selinux=0 3 init=/sbin/initPID hash table entries: 1024 (order: 1, 8192 bytes)xsave/xrstor: enabled xstate_bv 0x7, cntxt size 0x340Checking aperture...No AGP bridge foundMemory: 186168k/262144k available (5336k kernel code, 388k absent, 75588k reserved, 7017k data, 1288k init)Hierarchical RCU implementation.NR_IRQS:33024 nr_irqs:256Console: colour dummy device 80x25console [tty0] enabledconsole [hvc0] enabledallocated 1048576 bytes of page_cgroupplease try 'cgroup_disable=memory' option if you don't want memory cgroupsinstalling Xen timer for CPU 0Detected 2993.154 MHz processor.Calibrating delay loop (skipped), value calculated using timer frequency.. 5986.30 BogoMIPS (lpj=2993154)pid_max: default: 32768 minimum: 301Security Framework initializedSELinux:  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: 256Initializing cgroup subsys nsInitializing cgroup subsys cpuacctInitializing cgroup subsys memoryInitializing cgroup subsys devicesInitializing cgroup subsys freezerInitializing cgroup subsys net_clsInitializing cgroup subsys blkioInitializing cgroup subsys perf_eventInitializing cgroup subsys net_prioCPU: Unsupported number of siblings 16alternatives: switching to unfair spinlockSMP alternatives: switching to UP codeFreeing SMP alternatives: 36k freedftrace: converting mcount calls to 0f 1f 44 00 00ftrace: allocating 21918 entries in 86 pagesPerformance Events: unsupported p6 CPU model 60 no PMU driver, software events only.NMI watchdog disabled (cpu0): hardware events not enabledBrought up 1 CPUsdevtmpfs: initializedGrant table initializedregulator: core version 0.5NET: Registered protocol family 16PCI: Fatal: No config space access function foundbio: create slab  at 0ACPI: Interpreter disabled.xen_balloon: Initialising balloon driver.last_pfn = 0x10000 max_arch_pfn = 0x400000000vgaarb: loadedSCSI subsystem initializedusbcore: registered new interface driver usbfsusbcore: registered new interface driver hubusbcore: registered new device driver usbPCI: System does not support PCIPCI: System does not support PCINetLabel: InitializingNetLabel:  domain hash size = 128NetLabel:  protocols = UNLABELED CIPSOv4NetLabel:  unlabeled traffic allowed by defaultSwitching to clocksource xenpnp: PnP ACPI: disabledNET: Registered protocol family 2IP 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 registeredNET: Registered protocol family 1Trying to unpack rootfs image as initramfs...Freeing initrd memory: 53812k freedplatform 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): initializedHugeTLB registered 2 MB page size, pre-allocated 0 pagesVFS: Disk quotas dquot_6.5.2Dquot-cache hash table entries: 512 (order 0, 4096 bytes)msgmni has been set to 468alg: No test for stdrng (krng)ksign: Installing public key dataLoading 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 registeredio scheduler anticipatory registeredio scheduler deadline registeredio scheduler cfq registered (default)pci_hotplug: PCI Hot Plug PCI Core version: 0.5pciehp: PCI Express Hot Plug Controller Driver version: 0.4acpiphp: ACPI Hot Plug PCI Controller Driver version: 0.5Non-volatile memory driver v1.3Linux agpgart interface v0.103crash memory driver: version 1.1Serial: 8250/16550 driver, 4 ports, IRQ sharing enabledbrd: module loadedloop: module loadedinput: Macintosh mouse button emulation as /devices/virtual/input/input0Fixed MDIO Bus: probedehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driverohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driveruhci_hcd: USB Universal Host Controller Interface driverPNP: No PS/2 controller found. Probing ports directly.mice: PS/2 mouse device common for all micertc_cmos: probe of rtc_cmos failed with error -16cpuidle: using governor laddercpuidle: using governor menuEFI Variables Facility v0.08 2004-May-17usbcore: registered new interface driver hiddevusbcore: registered new interface driver usbhidusbhid: v2.6:USB HID core driverGRE over IPv4 demultiplexor driverTCP cubic registeredInitializing XFRM netlink socketNET: Registered protocol family 17registered taskstats version 1XENBUS: Device with no driver: device/vbd/51712XENBUS: Device with no driver: device/vif/0XENBUS: Device with no driver: device/console/0drivers/rtc/hctosys.c: unable to open rtc device (rtc0)Initalizing network drop monitor serviceFreeing unused kernel memory: 1288k freedWrite protecting the kernel read-only data: 10240kFreeing unused kernel memory: 788k freedFreeing unused kernel memory: 1568k freeddracut: dracut-004-356.el6device-mapper: uevent: version 1.0.3device-mapper: ioctl: 4.27.0-ioctl (2013-10-30) initialised: dm-devel@redhat.comudev: starting version 147dracut: Starting plymouth daemonxlblk_init: register_blkdev major: 202 blkfront: xvda: barriers disabled xvda: unknown partition tableEXT4-fs (xvda): mounted filesystem with ordered data mode. Opts: dracut: Mounted root filesystem /dev/xvdadracut: Switching root        Welcome to Mini CentOS 6.6 Linuxbash: cannot set terminal process group (-1): Inappropriate ioctl for devicebash: no job control in this shellbash-4.1# bash-4.1# lsbin  dev  etc  lib64  lost+found  proc        sbin  sys  tmp      usr  var

以上就是xm如何创建xen精简小linux虚拟机,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注行业资讯频道。

0