红联Linux门户
Linux帮助

使用官方Fedora22 ISO镜像制作OpenStack云镜像

发布时间:2015-07-06 09:49:46来源:blog.csdn.net/u012211583作者:LiK1209

参考链接:http://blog.csdn.net/u012211583/article/details/46441827

使用Fedora官方云镜像创建的虚拟机不能直接使用密码登陆,这里使用Fedora官方ISO镜像(https://download.fedoraproject.org/pub/fedora/linux/releases/22/Server/x86_64/iso/Fedora-Server-DVD-x86_64-22.iso)制作可直接使用密码登陆的镜像。

硬件及软件资源请参考http://blog.csdn.net/u012211583/article/details/46441827。


(1) 准备环境

Linux实体机:

# cd /home/images/
# ls -lh
-rwxr-xr-x 1 root root 2.1G Jun 30 20:57 Fedora-Server-DVD-x86_64-22.iso

# mkdir cloudimg

# qemu-img create -f qcow2 cloudimg/fedora-22-x86_64.qcow2 5G
Formatting 'cloudimg/fedora-22-x86_64.qcow2', fmt=qcow2 size=5368709120 encryption=off cluster_size=65536 lazy_refcounts=off

# ls -lh cloudimg
-rw-r--r-- 1 root root 193K Jun 30 21:01 fedora-22-x86_64.qcow2


(2) 安装Fedora系统

说明:
a) 选择最小化安装,仅安装必要的软件包
b) 自定义磁盘分区:无swap分区,无单独/boot分区,所有磁盘空间全部挂载到根分区/,格式化为ext4。The Picture below.
c) 此处设置root用户密码为openstack。

使用官方Fedora22 ISO镜像制作OpenStack云镜像

# kvm -m 2048 -cdrom Fedora-Server-DVD-x86_64-22.iso \
-drive file=./cloudimg/fedora-22-x86_64.qcow2,if=virtio,index=0 \
-boot d -net nic -net user

安装完成后,fedora-22-x86_64.qcow2文件大约有2GB。

# ls -lh cloudimg/
-rw-r--r-- 1 root root 1.3G Jun 30 21:23 cloudimg/fedora-22-x86_64.qcow2


(3) 配置云镜像
使用virtual Machine Manager工具启动虚拟机,镜像选择/home/images/cloudimg/fedora-22-x86_64.qcow2

# virt-manager

Fedora22虚拟机:


(4) Install cloud tools and partition manager

# cat /etc/redhat-release
Fedora release 22 (Twenty Two)

Support hot-pluggable cloud volumes

# yum install acpid
# systemctl enable acpid.service

Enable connection with the metadata service

# echo "NOZEROCONF=yes" >> /etc/sysconfig/network

Support extending rootfs antomatically on the boot

# yum install cloud-init cloud-utils-growpart dracut-module-growpart
# systemctl enable cloud-init.service
# vim /etc/cloud/cloud.cfg
---

注: 安装完后growpart不会自动加载, 需要重新创建initramfs。

# lsinitrd /boot/initramfs-4.0.4-301.fc22.x86_64.img | grep grow
(None)

# mv /boot/initramfs-4.0.4-301.fc22.x86_64.img{,.bak}
# dracut -f
# dracut -f /boot/initramfs-4.0.4-301.fc22.x86_64.img \
4.0.4-301.fc22.x86_64
# lsinitrd /boot/initramfs-4.0.4-301.fc22.x86_64.img | grep grow
growroot
-rwxr-xr-x   1 root  root  15710 Mar 26 15:35 usr/bin/growpart
-rwxr-xr-x   1 root  root  133 Jun  7  2014 usr/lib/dracut/hooks/cmdline/99-growroot-dummy.sh
-rwxr-xr-x   1 root  root  2167 Jun  7  2014 usr/lib/dracut/hooks/pre-mount/99-growroot.sh

允许root用户登陆

# vi /etc/cloud/cloud.cfg
--- disable_root: 1
--- ssh_pwauth: 0
+++ disable_root: 0
+++ ssh_pwauth: 1

# vi /etc/ssh/sshd_config
---# PermitRootLogin yes
+++ PermitRootLogin yes
+++ useDNS no

关闭虚拟机fedora22

# shutdown -h now


(5) 清理虚拟机登陆日志,压缩镜像

# virt-sysprep -d fedora22
# cd /home/images/cloudimg
# qemu-img convert -c -f qcow2 -O qcow2 fedora-22-x86_64.qcow2 fedora-22-cloudimg-x86_64.qcow2
# ls -lh
-rw-r--r-- 1 root root 490M Jun 30 21:43 fedora-22-cloudimg-x86_64.qcow2
-rw-r--r-- 1 root root 1.3G Jun 30 21:31 fedora-22-x86_64.qcow2


(6) 验证根目录是否开启自调整

# qemu-img resize fedora-22-cloudimg-x86_64.qcow2 +1G
# virsh start fedora22

虚拟机fedora22:

# fdisk -l

# df -h


(7) 上传镜像

# glance image-create --name "Fedora 22 x86_64" --disk-format qcow2 \
--container-format bare \
--is-public True \
--is-protected True \
--file /home/images/cloudimg/fedora-22-cloudimg-x86_64.qcow2 \
--progress


遇到的几个问题:

a) 未安装dracut-module-growpart, 重新创建initramfs后未加载growpart

在网上没有找到Fedora22对应的dracut-module-growpart,用dracut-module-growpart.fc21代替也是可以的。

b) 安装cloud-init后,重启虚拟机发现开机并没有自动启动

# systemctl enable cloud-init.service


为OpenStack制作CoreOS虚拟机镜像(基于CoreOS官方提供镜像):http://www.linuxdiyf.com/linux/11940.html

CentOS mirrorlist导致的OpenStack镜像制作失败:http://www.linuxdiyf.com/linux/12112.html

使用ISO文件制作OpenStack使用的CoreOS镜像:http://www.linuxdiyf.com/linux/11941.html

OpenStack制作Ubuntu镜像:http://www.linuxdiyf.com/linux/11877.html

制作OpenStack用的CentOS 6.5镜像:http://www.linuxdiyf.com/linux/10408.html