学堂 学堂 学堂公众号手机端

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

lewis 1年前 (2024-04-16) 阅读数 12 #技术

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

xen管理工具有xl 和xm xen版本是4.1以前使用xm/xend 以后使用xl 具体请看http://smilejay.com/2012/03/xl_or_xm/

xen虚拟机管理工具xm与virshhttp://xen虚拟机管理工具xm与virsh用法


[root@kcwdata]#ddif=/dev/zeroof=vm02.imgoflag=directbs=1Mseek=2048count=1#创建一个基于稀疏格式的磁盘镜像,大小2G
记录了1+0的读入
记录了1+0的写出
1048576字节(1.0MB)已复制,0.00701008秒,150MB/秒
格式化磁盘
[root@kcwdata]#mkfs.ext4vm02.img
mke2fs1.41.12(17-May-2010)
vm02.imgisnotablockspecialdevice.
无论如何也要继续?(y,n)y
警告:256块未使用.

文件系统标签=
操作系统:Linux
块大小=4096(log=2)
分块大小=4096(log=2)
Stride=0blocks,Stripewidth=0blocks
131328inodes,524288blocks
26227blocks(5.00%)reservedforthesuperuser
第一个数据块=0
Maximumfilesystemblocks=536870912
16blockgroups
32768blockspergroup,32768fragmentspergroup
8208inodespergroup
Superblockbackupsstoredonblocks:
	32768,98304,163840,229376,294912

正在写入inode表:完成
Creatingjournal(16384blocks):完成
Writingsuperblocksandfilesystemaccountinginformation:完成

Thisfilesystemwillbeautomaticallycheckedevery21mountsor
180days,whichevercomesfirst.Usetune2fs-cor-itooverride.

挂载磁盘镜像

[root@kcwdata]#mount-oloopvm02.img/mnt/

然后移植二进制文件

[root@kcwtmp]#bashbincp.sh#bincap是一个脚本移植自己想要的命令

Yourcommand:init
/sbin/init
copylib/lib64/libnih.so.1finished.
copylib/lib64/libnih-dbus.so.1finished.
copylib/lib64/libdbus-1.so.3finished.
copylib/lib64/libpthread.so.0finished.
copylib/lib64/librt.so.1finished.
copylib/lib64/libgcc_s.so.1finished.
copylib/lib64/libc.so.6finished.
copylib/lib64/ld-linux-x86-64.so.2finished.
copy/sbin/initfinished.
Continue:bash
/bin/bash
copylib/lib64/libtinfo.so.5finished.
copylib/lib64/libdl.so.2finished.
copy/bin/bashfinished.
Continue:ls
/bin/ls
copylib/lib64/libselinux.so.1finished.
copylib/lib64/libcap.so.2finished.
copylib/lib64/libacl.so.1finished.
copylib/lib64/libattr.so.1finished.
copy/bin/lsfinished.
Continue:cat
/bin/cat
copy/bin/catfinished.
Continue:

bincopy脚本

[root@kcwtmp]#catbincp.sh
#!/bin/bash
#
DEST=/mnt
libcp(){
LIBPATH=${1%/*}
[!-d$DEST$LIBPATH]&&mkdir-p$DEST$LIBPATH
[!-e$DEST${1}]&&cp$1$DEST$LIBPATH&&echo"copylib$1finished."
}

bincp(){
CMDPATH=${1%/*}
[!-d$DEST$CMDPATH]&&mkdir-p$DEST$CMDPATH
[!-e$DEST${1}]&&cp$1$DEST$CMDPATH

forLIBin`ldd$1|grep-o"/.*lib\(64\)\{0,1\}/[^[:space:]]\{1,\}"`;do
libcp$LIB
done
}

read-p"Yourcommand:"CMD
until[$CMD=='q'];do
!which$CMD&&echo"Wrongcommand"&&read-p"Inputagain:"CMD&&continue
COMMAND=`which$CMD|grep-v"^alias"|grep-o"[^[:space:]]\{1,\}"`
bincp$COMMAND
echo"copy$COMMANDfinished."
read-p"Continue:"CMD
done

测试

[root@kcwmnt]#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

4directories,18files
[root@kcwmnt]#chroot/mnt/#切换到刚才移植命令的小系统
bash-4.1#ls
binlib64lost+found	sbin
bash-4.1#

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

[root@kcwmnt]#mkdirprocsysdevetc/{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@kcwmnt]#ls
bindevetclib64lost+foundprocsbinsysusrvar
#修改文件
[root@kcwmnt]#cp/etc/init/rcS.conf/mnt/etc/init/
[root@kcwmnt]#vim/mnt/etc/init/rcS.conf
内容如下
startonstartup

stoponrunlevel

task

#Note:therecanbenopreviousrunlevelhere,ifwehaveoneit'sbad
#information(weenterrc1notrcSformaintenance).Run/etc/rc.d/rc
#withoutinformationsothatitdefaultstoprevious=Nrunlevel=S.
consoleoutput
exec/etc/rc.d/rc.sysinit

[root@kcw~]#vim/mnt/etc/rc.d/rc.sysinit#编辑文件
#!/bin/bash
#
echo-e"\tWelcometoMiniCentOS6.6Linux"
exec/bin/bash

[root@kcw~]#chmod+x/mnt/etc/rc.d/rc.sysinit#附加执行权限

测试启动

创建虚拟机配置文件

vim/etc/xen/vm02#配置文件必须在/etc/xen目录下具体参数格式请manxm
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/xvdaro"
extra="selinux=03init=/sbin/init"

启动

[root@kcwxen]#xmcreatevm02
Usingconfigfile"./vm02".
Starteddomainvm02(id=10)
[root@kcwxen]#xmlist#查看
NameIDMemVCPUsStateTime(s)
Domain-0020484r-----10935.1
vm0195122-b----12.6
vm02102561-b----4.5

启动过程

[root@kcw~]#xmcreate-cvm02
Usingconfigfile"/etc/xen/vm02".
Starteddomainvm02(id=22)
Initializingcgroupsubsyscpuset
Initializingcgroupsubsyscpu
Linuxversion2.6.32-504.3.3.el6.x86_64(mockbuild@c6b8.bsys.dev.centos.org)(gccversion4.4.720120313(RedHat4.4.7-11)(GCC))#1SMPWedDec1701:55:02UTC2014
Commandline:root=/dev/xvdaroselinux=03init=/sbin/init
KERNELsupportedcpus:
IntelGenuineIntel
AMDAuthenticAMD
CentaurCentaurHauls
ACPIinunprivilegeddomaindisabled
released0pagesofunusedmemory
BIOS-providedphysicalRAMmap:
Xen:0000000000000000-00000000000a0000(usable)
Xen:00000000000a0000-0000000000100000(reserved)
Xen:0000000000100000-0000000010000000(usable)
DMInotpresentorinvalid.
last_pfn=0x10000max_arch_pfn=0x400000000
init_memory_mapping:0000000000000000-0000000010000000
RAMDISK:0204a000-054d7000
NoNUMAconfigurationfound
Fakinganodeat0000000000000000-0000000010000000
Bootmemsetupnode00000000000000000-0000000010000000
NODE_DATA[0000000000058000-000000000008bfff]
bootmap[000000000008c000-000000000008dfff]pages2
(7earlyreservations)==>bootmem[0000000000-0010000000]
#0[0000000000-0000001000]BIOSdatapage==>[0000000000-0000001000]
#1[000555a000-0005589000]XENPAGETABLES==>[000555a000-0005589000]
#2[0000006000-0000008000]TRAMPOLINE==>[0000006000-0000008000]
#3[0001000000-0002029be4]TEXTDATABSS==>[0001000000-0002029be4]
#4[000204a000-00054d7000]RAMDISK==>[000204a000-00054d7000]
#5[00054d7000-000555a000]XENSTARTINFO==>[00054d7000-000555a000]
#6[0000008000-0000058000]PGTABLE==>[0000008000-0000058000]
ZonePFNranges:
DMA0x00000001->0x00001000
DMA320x00001000->0x00100000
Normal0x00100000->0x00100000
MovablezonestartPFNforeachnode
early_node_map[2]activePFNranges
0:0x00000001->0x000000a0
0:0x00000100->0x00010000
SFI:SimpleFirmwareInterfacev0.7http://simplefirmware.org
SMP:Allowing1CPUs,0hotplugCPUs
NolocalAPICpresent
APIC:disableapicfacility
PM:Registerednosavememory:00000000000a0000-0000000000100000
AllocatingPCIresourcesstartingat10000000(gap:10000000:f0000000)
BootingparavirtualizedkernelonXen
Xenversion:4.2.5-38.el6(preserve-AD)
NR_CPUS:4096nr_cpumask_bits:1nr_cpu_ids:1nr_node_ids:1
PERCPU:Embedded30pages/cpu@ffff8800055bf000s90968r8192d23720u122880
pcpu-alloc:s90968r8192d23720u122880alloc=30*4096
pcpu-alloc:[0]0
Xen:usingvcpu_infoplacement
Built1zonelistsinNodeorder,mobilitygroupingon.Totalpages:64460
Policyzone:DMA32
Kernelcommandline:root=/dev/xvdaroselinux=03init=/sbin/init
PIDhashtableentries:1024(order:1,8192bytes)
xsave/xrstor:enabledxstate_bv0x7,cntxtsize0x340
Checkingaperture...
NoAGPbridgefound
Memory:186168k/262144kavailable(5336kkernelcode,388kabsent,75588kreserved,7017kdata,1288kinit)
HierarchicalRCUimplementation.
NR_IRQS:33024nr_irqs:256
Console:colourdummydevice80x25
console[tty0]enabled
console[hvc0]enabled
allocated1048576bytesofpage_cgroup
pleasetry'cgroup_disable=memory'optionifyoudon'twantmemorycgroups
installingXentimerforCPU0
Detected2993.154MHzprocessor.
Calibratingdelayloop(skipped),valuecalculatedusingtimerfrequency..5986.30BogoMIPS(lpj=2993154)
pid_max:default:32768minimum:301
SecurityFrameworkinitialized
SELinux:Disabledatboot.
Dentrycachehashtableentries:32768(order:6,262144bytes)
Inode-cachehashtableentries:16384(order:5,131072bytes)
Mount-cachehashtableentries:256
Initializingcgroupsubsysns
Initializingcgroupsubsyscpuacct
Initializingcgroupsubsysmemory
Initializingcgroupsubsysdevices
Initializingcgroupsubsysfreezer
Initializingcgroupsubsysnet_cls
Initializingcgroupsubsysblkio
Initializingcgroupsubsysperf_event
Initializingcgroupsubsysnet_prio
CPU:Unsupportednumberofsiblings16
alternatives:switchingtounfairspinlock
SMPalternatives:switchingtoUPcode
FreeingSMPalternatives:36kfreed
ftrace:convertingmcountcallsto0f1f440000
ftrace:allocating21918entriesin86pages
PerformanceEvents:unsupportedp6CPUmodel60noPMUdriver,softwareeventsonly.
NMIwatchdogdisabled(cpu0):hardwareeventsnotenabled
Broughtup1CPUs
devtmpfs:initialized
Granttableinitialized
regulator:coreversion0.5
NET:Registeredprotocolfamily16
PCI:Fatal:Noconfigspaceaccessfunctionfound
bio:createslab<bio-0>at0
ACPI:Interpreterdisabled.
xen_balloon:Initialisingballoondriver.
last_pfn=0x10000max_arch_pfn=0x400000000
vgaarb:loaded
SCSIsubsysteminitialized
usbcore:registerednewinterfacedriverusbfs
usbcore:registerednewinterfacedriverhub
usbcore:registerednewdevicedriverusb
PCI:SystemdoesnotsupportPCI
PCI:SystemdoesnotsupportPCI
NetLabel:Initializing
NetLabel:domainhashsize=128
NetLabel:protocols=UNLABELEDCIPSOv4
NetLabel:unlabeledtrafficallowedbydefault
Switchingtoclocksourcexen
pnp:PnPACPI:disabled
NET:Registeredprotocolfamily2
IProutecachehashtableentries:2048(order:2,16384bytes)
TCPestablishedhashtableentries:8192(order:5,131072bytes)
TCPbindhashtableentries:8192(order:5,131072bytes)
TCP:Hashtablesconfigured(established8192bind8192)
TCPrenoregistered
NET:Registeredprotocolfamily1
Tryingtounpackrootfsimageasinitramfs...
Freeinginitrdmemory:53812kfreed
platformrtc_cmos:registeredplatformRTCdevice(noPNPdevicefound)
futexhashtableentries:256(order:2,16384bytes)
audit:initializingnetlinksocket(disabled)
type=2000audit(1422347438.824:1):initialized
HugeTLBregistered2MBpagesize,pre-allocated0pages
VFS:Diskquotasdquot_6.5.2
Dquot-cachehashtableentries:512(order0,4096bytes)
msgmnihasbeensetto468
alg:Notestforstdrng(krng)
ksign:Installingpublickeydata
Loadingkeyring
-AddedpublickeyA25F8C29DC55AB79
-UserID:CentOS(KernelModuleGPGkey)
BlocklayerSCSIgeneric(bsg)driverversion0.4loaded(major251)
ioschedulernoopregistered
ioscheduleranticipatoryregistered
ioschedulerdeadlineregistered
ioschedulercfqregistered(default)
pci_hotplug:PCIHotPlugPCICoreversion:0.5
pciehp:PCIExpressHotPlugControllerDriverversion:0.4
acpiphp:ACPIHotPlugPCIControllerDriverversion:0.5
Non-volatilememorydriverv1.3
Linuxagpgartinterfacev0.103
crashmemorydriver:version1.1
Serial:8250/16550driver,4ports,IRQsharingenabled
brd:moduleloaded
loop:moduleloaded
input:Macintoshmousebuttonemulationas/devices/virtual/input/input0
FixedMDIOBus:probed
ehci_hcd:USB2.0'Enhanced'HostController(EHCI)Driver
ohci_hcd:USB1.1'Open'HostController(OHCI)Driver
uhci_hcd:USBUniversalHostControllerInterfacedriver
PNP:NoPS/2controllerfound.Probingportsdirectly.
mice:PS/2mousedevicecommonforallmice
rtc_cmos:probeofrtc_cmosfailedwitherror-16
cpuidle:usinggovernorladder
cpuidle:usinggovernormenu
EFIVariablesFacilityv0.082004-May-17
usbcore:registerednewinterfacedriverhiddev
usbcore:registerednewinterfacedriverusbhid
usbhid:v2.6:USBHIDcoredriver
GREoverIPv4demultiplexordriver
TCPcubicregistered
InitializingXFRMnetlinksocket
NET:Registeredprotocolfamily17
registeredtaskstatsversion1
XENBUS:Devicewithnodriver:device/vbd/51712
XENBUS:Devicewithnodriver:device/vif/0
XENBUS:Devicewithnodriver:device/console/0
drivers/rtc/hctosys.c:unabletoopenrtcdevice(rtc0)
Initalizingnetworkdropmonitorservice
Freeingunusedkernelmemory:1288kfreed
Writeprotectingthekernelread-onlydata:10240k
Freeingunusedkernelmemory:788kfreed
Freeingunusedkernelmemory:1568kfreed
dracut:dracut-004-356.el6
device-mapper:uevent:version1.0.3
device-mapper:ioctl:4.27.0-ioctl(2013-10-30)initialised:dm-devel@redhat.com
udev:startingversion147
dracut:Startingplymouthdaemon
xlblk_init:register_blkdevmajor:202
blkfront:xvda:barriersdisabled
xvda:unknownpartitiontable
EXT4-fs(xvda):mountedfilesystemwithordereddatamode.Opts:
dracut:Mountedrootfilesystem/dev/xvda
dracut:Switchingroot
	WelcometoMiniCentOS6.6Linux
bash:cannotsetterminalprocessgroup(-1):Inappropriateioctlfordevice
bash:nojobcontrolinthisshell
bash-4.1#
bash-4.1#ls
bindevetclib64lost+foundproc	sbinsystmp	usrvar

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

版权声明

本文仅代表作者观点,不代表博信信息网立场。

热门