glance制作Linux镜像,为OpenStack制作自定义镜像(centos linux/windows),因为我们现有的应用大...

为OpenStack制作自定义镜像(centos linux/windows),因为我们现有的应用大

在OpenStack平台搭建好以后,我们可以用下载一些现成的镜像来进行测试,比如Ubuntu,比如CentOS,但是每个应用都需要不同的环境,记录一下如何制作自定义的镜像。因为我们现有的应用大多运行在Centos5.5和Windows2008上,所以以这2个为例子:

1. Centos5.5

整个安装流程是按照OpenStack的官方文档,制作ami(Amazon Machine Image)格式,glance还支持raw和qcow2等多种格式,如果用raw这种格式,流程应该更简单,不过我没有测试过。

以下是具体的流程:

用kvm-img创建一个5G大小的镜像文件:kvm-img create -f raw centos55.img 5G

启动kvm,指定vnc端口kvm -m 512 -boot d -cdrom CentOS5.5-dvd.iso -drive file=centos55.img,index=0,if=scsi,boot=on -net nic -net user -nographic -vnc :1

然后用vnc访问host:1来进行安装,因为是基础镜像,选择了最小化安装,除了sshd server,其他组件都没有安装。安装好以后,重启动,登入到虚拟机,将firewall和selinux等都disable掉,这些可以留给镜像的使用者在启动实例后自行设置,不需要在这个基础镜像中做任何配置。另外在Centos5.x下默认没有加载virtio驱动,所以我们需要执行如下命令:mkinitrd --with virtio_pci --with virtio_blk --with virtio_net --with virtio_balloon --with virtio -f /boot/initrd-$(uname -r) $(uname -r)

结束以后关闭虚拟机。将镜像文件挂载:losetup -f centos55.img

losetup -a

用fdisk找到找到偏移量和Block Sizefdisk -c -u -l /dev/loop0

比如偏移量是63,Block Size是512,那么记录一下63*512=32256

然后重新从偏移量开始挂载losetup -d /dev/loop0

losetup -f -o 32256 centos55.img

losetup -a

拷贝出最终镜像dd if=/dev/loop0 of=centos55.final.img

losetup -d /dev/loop0

然后挂载最终镜像到/mntmount -o loop centos55.final.img /mnt

修改 /mnt/etc/fstab

LABEL=/ 改成LABEL=uec-rootfs

拷贝出AKI和ARI文件以后umountcp /mnt/boot/vmlinuz-2.6.18-194.el5 centos55/

cp /mnt/boot/initrd-2.6.18-194.el5 centos55/

umount /mnt

然后将最终镜像修改一下标签tune2fs -L uec-rootfs centos55.final.img

这样就得到3个amazon格式的文件,用glance add命令上传到glance服务器glance add -A your_glance_token name="centos55-ramdisk" is_public=true container_format=ari disk_format=ari < initrd-2.6.18-194.el5

glance add -A your_glance_token name="centos55-kernal" is_public=true container_format=aki disk_format=aki < vmlinuz-2.6.18-194.el5

glance add -A your_glance_token name="centos55" is_public=true container_format=ami disk_format=ami kernel_id=4 ramdisk_id=3 < centos55.final.img

如果你的glance server和制作镜像的机器不在同一台,可以指定-H参数来上传,另外第3个命令中的kernel_id和ramdisk_id是从前面2个命令中的结果中获取镜像上传好以后,就能通过dashboard或者命令行来从这个镜像启动实例,因为这个镜像是最基础的,你可以在启动的实例上安装需要的组件,比如mysql/ruby等等,再对实例做个snapshot,就可以制作出各种立即可用的镜像。

2. Windows2008

这里windows2008我采用qcow2格式来制作镜像,流程和centos类似用kvm-img创建一个10G大小的镜像文件:kvm-img create -f qcow2 win2008.img 10G

因为windows没有默认的virtio驱动,所以先下载:wget http://alt.fedoraproject.org/pub/alt/virtio-win/latest/images/bin/virtio-win-0.1-15.iso

wget http://alt.fedoraproject.org/pub/alt/virtio-win/latest/images/bin/virtio-win-1.1.16.vfd

启动kvm,映射驱动vfd到软盘Akvm -m 1024 -cdrom en_windows_server_2008_r2_dvd.iso -drive file=win2008.img,if=virtio,boot=on -fda virtio-win-1.1.16.vfd -boot d -nographic -vnc :1

用vnc访问安装,在安装的时候需要选择一下硬盘驱动,安装好以后,停掉虚拟机,重新用以下命令启动:kvm -m 1024 -drive file=win2008.img,if=virtio,boot=on -cdrom virtio-win-0.1-15.iso -net nic,model=virtio -net user -boot c -nographic -vnc :1

再用vnc访问,应该会提示自动安装好了virtio的网卡驱动,用glance添加这个镜像,指定格式为qcow2glance add -A your_glance_token name="win2008" is_public=true disk_format=qcow2 < win2008.img

这样就完成了,完成镜像以后,我们还可以在security group里面添加3389和22端口,这样能够允许rdp和ssh访问对应的windows和Linux实例。

更多关于OpenStack的介绍请看《OpenStack的简介和相关资料》一文

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值