kvm虛擬機(jī)制作qcow2鏡像

1秉溉、構(gòu)造空鏡像

qemu-img create -f qcow2 centos-7-guest.qcow2 10G

qcow2临谱、raw都可以乒裆;還能相互轉(zhuǎn)換套利。

2、創(chuàng)建虛擬機(jī) 根據(jù)指定的跟鏡像

virt-install --virt-type kvm --name centos-7-guest --ram 1024 --disk centos-7-guest.qcow2,format=qcow2 --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --location=CentOS-7-x86_64-Minimal-2009.iso

virt-install命令:

[[root@controller guest]# virt-install --help
usage: virt-install --name NAME --memory MB STORAGE INSTALL [options]

Create a new virtual machine from specified install media.

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  --connect URI         Connect to hypervisor with libvirt URI

General Options:
  -n NAME, --name NAME  Name of the guest instance
  --memory MEMORY       Configure guest memory allocation. Ex:
                        --memory 1024 (in MiB)
                        --memory 512,maxmemory=1024
                        --memory 512,maxmemory=1024,hotplugmemorymax=2048,hotplugmemoryslots=2
  --vcpus VCPUS         Number of vcpus to configure for your guest. Ex:
                        --vcpus 5
                        --vcpus 5,maxvcpus=10,cpuset=1-4,6,8
                        --vcpus sockets=2,cores=4,threads=2
  --cpu CPU             CPU model and features. Ex:
                        --cpu coreduo,+x2apic
                        --cpu host-passthrough
                        --cpu host
  --metadata METADATA   Configure guest metadata. Ex:
                        --metadata name=foo,title="My pretty title",uuid=...
                        --metadata description="My nice long description"

Installation Method Options:
  --cdrom CDROM         CD-ROM installation media
  -l LOCATION, --location LOCATION
                        Installation source (eg, nfs:host:/path,
                        http://host/path, ftp://host/path)
  --pxe                 Boot from the network using the PXE protocol
  --import              Build guest around an existing disk image
  --livecd              Treat the CD-ROM media as a Live CD
  -x EXTRA_ARGS, --extra-args EXTRA_ARGS
                        Additional arguments to pass to the install kernel
                        booted from --location
  --initrd-inject INITRD_INJECT
                        Add given file to root of initrd from --location
  --os-variant DISTRO_VARIANT
                        The OS variant being installed guests, e.g.
                        'fedora18', 'rhel6', 'winxp', etc.
  --boot BOOT           Configure guest boot settings. Ex:
                        --boot hd,cdrom,menu=on
                        --boot init=/sbin/init (for containers)
  --idmap IDMAP         Enable user namespace for LXC container. Ex:
                        --idmap uid_start=0,uid_target=1000,uid_count=10

Device Options:
  --disk DISK           Specify storage with various options. Ex.
                        --disk size=10 (new 10GiB image in default location)
                        --disk /my/existing/disk,cache=none
                        --disk device=cdrom,bus=scsi
                        --disk=?
  -w NETWORK, --network NETWORK
                        Configure a guest network interface. Ex:
                        --network bridge=mybr0
                        --network network=my_libvirt_virtual_net
                        --network network=mynet,model=virtio,mac=00:11...
                        --network none
                        --network help
  --graphics GRAPHICS   Configure guest display settings. Ex:
                        --graphics vnc
                        --graphics spice,port=5901,tlsport=5902
                        --graphics none
                        --graphics vnc,password=foobar,port=5910,keymap=ja
  --controller CONTROLLER
                        Configure a guest controller device. Ex:
                        --controller type=usb,model=ich9-ehci1
  --input INPUT         Configure a guest input device. Ex:
                        --input tablet
                        --input keyboard,bus=usb
  --serial SERIAL       Configure a guest serial device
  --parallel PARALLEL   Configure a guest parallel device
  --channel CHANNEL     Configure a guest communication channel
  --console CONSOLE     Configure a text console connection between the guest
                        and host
  --hostdev HOSTDEV     Configure physical USB/PCI/etc host devices to be
                        shared with the guest
  --filesystem FILESYSTEM
                        Pass host directory to the guest. Ex:
                        --filesystem /my/source/dir,/dir/in/guest
                        --filesystem template_name,/,type=template
  --sound [SOUND]       Configure guest sound device emulation
  --watchdog WATCHDOG   Configure a guest watchdog device
  --video VIDEO         Configure guest video hardware.
  --smartcard SMARTCARD
                        Configure a guest smartcard device. Ex:
                        --smartcard mode=passthrough
  --redirdev REDIRDEV   Configure a guest redirection device. Ex:
                        --redirdev usb,type=tcp,server=192.168.1.1:4000
  --memballoon MEMBALLOON
                        Configure a guest memballoon device. Ex:
                        --memballoon model=virtio
  --tpm TPM             Configure a guest TPM device. Ex:
                        --tpm /dev/tpm
  --rng RNG             Configure a guest RNG device. Ex:
                        --rng /dev/urandom
  --panic PANIC         Configure a guest panic device. Ex:
                        --panic default
  --memdev MEMDEV       Configure a guest memory device. Ex:
                        --memdev dimm,target_size=1024

Guest Configuration Options:
  --security SECURITY   Set domain security driver configuration.
  --cputune CPUTUNE     Tune CPU parameters for the domain process.
  --numatune NUMATUNE   Tune NUMA policy for the domain process.
  --memtune MEMTUNE     Tune memory policy for the domain process.
  --blkiotune BLKIOTUNE
                        Tune blkio policy for the domain process.
  --memorybacking MEMORYBACKING
                        Set memory backing policy for the domain process. Ex:
                        --memorybacking hugepages=on
  --features FEATURES   Set domain <features> XML. Ex:
                        --features acpi=off
                        --features apic=on,eoi=on
  --clock CLOCK         Set domain <clock> XML. Ex:
                        --clock offset=localtime,rtc_tickpolicy=catchup
  --pm PM               Configure VM power management features
  --events EVENTS       Configure VM lifecycle management policy
  --resource RESOURCE   Configure VM resource partitioning (cgroups)
  --sysinfo SYSINFO     Configure SMBIOS System Information. Ex:
                        --sysinfo emulate
                        --sysinfo host
                        --sysinfo bios_vendor=Vendor_Inc.,bios_version=1.2.3-abc,...
                        --sysinfo system_manufacturer=System_Corp.,system_product=Computer,...
                        --sysinfo baseBoard_manufacturer=Baseboard_Corp.,baseBoard_product=Motherboard,...
  --qemu-commandline QEMU_COMMANDLINE
                        Pass arguments directly to the qemu emulator. Ex:
                        --qemu-commandline='-display gtk,gl=on'
                        --qemu-commandline env=DISPLAY=:0.1

Virtualization Platform Options:
  -v, --hvm             This guest should be a fully virtualized guest
  -p, --paravirt        This guest should be a paravirtualized guest
  --container           This guest should be a container guest
  --virt-type HV_TYPE   Hypervisor name to use (kvm, qemu, xen, ...)
  --arch ARCH           The CPU architecture to simulate
  --machine MACHINE     The machine type to emulate

Miscellaneous Options:
  --autostart           Have domain autostart on host boot up.
  --transient           Create a transient domain.
  --wait WAIT           Minutes to wait for install to complete.
  --noautoconsole       Don't automatically try to connect to the guest
                        console
  --noreboot            Don't boot guest after completing install.
  --print-xml [XMLONLY]
                        Print the generated domain XML rather than create the
                        guest.
  --dry-run             Run through install process, but do not create devices
                        or define the guest.
  --check CHECK         Enable or disable validation checks. Example:
                        --check path_in_use=off
                        --check all=off
  -q, --quiet           Suppress non-error output
  -d, --debug           Print debugging information

Use '--option=?' or '--option help' to see available suboptions
See man page for examples and full option syntax.
[root@svr ~]#

3鹤耍、查看kvm虛擬機(jī)

[root@controller guest]$ virsh list
 Id    Name                           State
----------------------------------------------------
 1   instance-00000c0e             running
 2   centos-7-guest                running

4肉迫、virt-manager

virt-maneger

進(jìn)入虛擬機(jī) dhcpclient 配置網(wǎng)絡(luò) 修改虛擬機(jī)(自我定制,愛咋改咋改) 關(guān)閉虛擬機(jī)

5稿黄、清理

virt-sysprep -d centos-7-guest

[root@controller guest]$ virt-sysprep -d centos-7-guest
[   0.0] Examining the guest ...
[   3.4] Performing "abrt-data" ...
[   3.4] Performing "backup-files" ...
[   4.1] Performing "bash-history" ...
[   4.1] Performing "blkid-tab" ...
[   4.1] Performing "crash-data" ...
[   4.1] Performing "cron-spool" ...
[   4.1] Performing "dhcp-client-state" ...
[   4.2] Performing "dhcp-server-state" ...
[   4.2] Performing "dovecot-data" ...
[   4.2] Performing "logfiles" ...
[   4.2] Performing "machine-id" ...
[   4.2] Performing "mail-spool" ...
[   4.2] Performing "net-hostname" ...
[   4.2] Performing "net-hwaddr" ...
[   4.3] Performing "pacct-log" ...
[   4.3] Performing "package-manager-cache" ...
[   4.3] Performing "pam-data" ...
[   4.3] Performing "passwd-backups" ...
[   4.3] Performing "puppet-data-log" ...
[   4.3] Performing "rh-subscription-manager" ...
[   4.3] Performing "rhn-systemid" ...
[   4.3] Performing "rpm-db" ...
[   4.3] Performing "samba-db-log" ...
[   4.3] Performing "script" ...
[   4.3] Performing "smolt-uuid" ...
[   4.4] Performing "ssh-hostkeys" ...
[   4.4] Performing "ssh-userdir" ...
[   4.4] Performing "sssd-db-log" ...
[   4.4] Performing "tmp-files" ...
[   4.4] Performing "udev-persistent-net" ...
[   4.4] Performing "utmp" ...
[   4.4] Performing "yum-uuid" ...
[   4.4] Performing "customize" ...
[   4.4] Setting a random seed
[   4.4] Setting the machine ID in /etc/machine-id
[   4.5] Performing "lvm-uuids" ...

6喊衫、壓縮鏡像文件

virt-sparsify --compress centos-7-guest.qcow2 centos-7-guest01.qcow2

[root@controller guest]$ virt-sparsify --compress centos-7-guest.qcow2 centos-7-guest01.qcow2
[   0.3] Create overlay file in /tmp to protect source disk
[   0.4] Examine source disk
[   2.6] Fill free space in /dev/centos/root with zero
 100% ?????????????????????????????????????????????????????????????????????????????????? 00:00
[  11.7] Clearing Linux swap on /dev/centos/swap
[  12.6] Fill free space in /dev/sda1 with zero
[  15.2] Copy to destination and make sparse
[ 102.9] Sparsify operation completed with no errors.
virt-sparsify: Before deleting the old disk, carefully check that the
target disk boots and works correctly.

[root@controller guest]$ ll -h
-rw-r--r-- 1 qemu qemu 973M Mar 14 15:29 CentOS-7-x86_64-Minimal-2009.iso
-rw-r--r-- 1 root root 692M Mar 14 16:40 centos-7-guest01.qcow2
-rw-r--r-- 1 qemu qemu 1.9G Mar 14 16:34 centos-7-guest.qcow2

7、上傳鏡像 open stack

glance image create --name centos7-guest --container-format bare --disk-format qcow2 --file centos-7-guest01.qcow2

注:在環(huán)境直接創(chuàng)建虛擬機(jī):

virt-install --virt-type kvm --name centos-7-guest --ram 1024 --disk centos-7-guest01.qcow2,format=qcow2 --network network=default --graphics vnc,listen=0.0.0.0 --noautoconsole --import
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末杆怕,一起剝皮案震驚了整個(gè)濱河市族购,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌财著,老刑警劉巖联四,帶你破解...
    沈念sama閱讀 217,277評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件撑碴,死亡現(xiàn)場(chǎng)離奇詭異撑教,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)醉拓,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評(píng)論 3 393
  • 文/潘曉璐 我一進(jìn)店門伟姐,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人亿卤,你說我怎么就攤上這事愤兵。” “怎么了排吴?”我有些...
    開封第一講書人閱讀 163,624評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵秆乳,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我钻哩,道長(zhǎng)屹堰,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,356評(píng)論 1 293
  • 正文 為了忘掉前任街氢,我火速辦了婚禮扯键,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘珊肃。我一直安慰自己荣刑,他們只是感情好馅笙,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,402評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著厉亏,像睡著了一般董习。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上爱只,一...
    開封第一講書人閱讀 51,292評(píng)論 1 301
  • 那天阱飘,我揣著相機(jī)與錄音,去河邊找鬼虱颗。 笑死沥匈,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的忘渔。 我是一名探鬼主播高帖,決...
    沈念sama閱讀 40,135評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼畦粮!你這毒婦竟也來了散址?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,992評(píng)論 0 275
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤宣赔,失蹤者是張志新(化名)和其女友劉穎预麸,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體儒将,經(jīng)...
    沈念sama閱讀 45,429評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡吏祸,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,636評(píng)論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了钩蚊。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片贡翘。...
    茶點(diǎn)故事閱讀 39,785評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖砰逻,靈堂內(nèi)的尸體忽然破棺而出鸣驱,到底是詐尸還是另有隱情,我是刑警寧澤蝠咆,帶...
    沈念sama閱讀 35,492評(píng)論 5 345
  • 正文 年R本政府宣布踊东,位于F島的核電站,受9級(jí)特大地震影響刚操,放射性物質(zhì)發(fā)生泄漏闸翅。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,092評(píng)論 3 328
  • 文/蒙蒙 一赡茸、第九天 我趴在偏房一處隱蔽的房頂上張望缎脾。 院中可真熱鬧,春花似錦占卧、人聲如沸遗菠。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)辙纬。三九已至豁遭,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間贺拣,已是汗流浹背蓖谢。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留譬涡,地道東北人闪幽。 一個(gè)月前我還...
    沈念sama閱讀 47,891評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像涡匀,于是被迫代替她去往敵國(guó)和親盯腌。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,713評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容