RedHat qcow2格式镜像制作

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">前段时间搭建了一套OpenStack环境,建立虚拟机使用的红帽镜像是从在网上找的现成的,使用的时候发现有很多不如意的地方,本着自己动手丰衣足食的思想今天尝试着自己创建镜像,过程中问题多多,现记录如此</span>

之前创建过win7的镜像参考的这篇博客

http://my.oschina.net/guol/blog/95449 

实际建立时启动虚拟机的命令似乎用的是openstack镜像手册的例子,具体用的啥记不太清楚了,但是大部分操作都是照搬这篇博客的介绍。

openstack镜像制作教程:http://docs.openstack.org/image-guide 


始终没有从网上找到制作redhat qcow2格式镜像的分享,openstack官网教程也没有针对redhat镜像制作的介绍,考虑到redhat毕竟与centos ubuntu这些同根同源,相信差距也不会太大,因此制作时同时参考了 centos及ubuntu镜像的制作过程。

redhat镜像制作具体步骤如下:

制作前准备一个redhat.iso镜像文件,本次使用的镜像文件是 rhel-server-6.3-x86-64-dvd.iso、

制作镜像环境是ubuntu14.04 x86-64 server 

1. 创建一个镜像

qemu-img create -f qcow2 /tmp/trusty.qcow2 10G
Formatting '/tmp/trusty.qcow2', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536 lazy_refcounts=off 


2. 启动虚拟机实例

virt-install --virt-type kvm --name trusty --ram 1024 \
--cdrom=rhel-server-6.3-x86_64-dvd.iso \
--disk /tmp/trusty.qcow2,format=qcow2 \
--network network=default \
--graphics vnc,listen=0.0.0.0 --noautoconsole \
--os-type=linux --os-variant=rhel6
Starting install...
Creating domain...                                                                                                                                       |    0 B     00:01     
Domain installation still in progress. You can reconnect to 
the console to complete the installation process.


3. 通过vnc工具访问镜像环境IP,进入安装界面完成安装,安装后reboot,虽然是reboot实际是关机


4. 这几个操作主要应该是设置光驱地址,没有仔细研究,先按介绍来把

# virsh dumpxml trusty1
# virsh start trusty1 --paused
# virsh attach-disk --type cdrom --mode readonly trusty1 "" hdc
# virsh resume trusty1


5. 虚拟机启动后通过vnc登陆操作系统进行定制

修改网卡eth0随系统系统  /etc/sysconfig/network-scripts/ifup-eth 中ONBOOT="yes"

定制完后关机 shutdown -h now


6. 对虚拟机进行清理(很重要)

正常执行该命令即可(前提需更新 update-guestfs-appliance) 参考:https://www.redhat.com/archives/libguestfs/2012-May/msg00158.html

virt-sysprep -d trusty
但是由于操作系统中libguestfs版本的问题在lvm 会报错  参考: https://bugzilla.redhat.com/show_bug.cgi?id=1111662

Guestfs.Error("vgchange_uuid_all: Volume group has active logical volumes")

因此屏蔽掉 lvm-uuids

virt-sysprep --enable abrt-data,bash-history,blkid-tab,crash-data,cron-spool,dhcp-client-state,dhcp-server-state,dovecot-data,firstboot,hostname,logfiles,machine-id,mail-spool,net-hostname,net-hwaddr,pacct-log,package-manager-cache,pam-data,password,puppet-data-log,random-seed,rhn-systemid,rpm-db,samba-db-log,script,smolt-uuid,ssh-hostkeys,ssh-userdir,sssd-db-log,tmp-files,udev-persistent-net,utmp,yum-uuid  -d trusty1

7. virsh undefine trusty1

制作完成!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值