使用官方Fedora22 ISO映象製作OpenStack雲映象
阿新 • • 發佈:2019-02-11
參考連結:
使用Fedora官方雲映象建立的虛擬機器不能直接使用密碼登陸,這裡使用Fedora官方ISO映象製作可直接使用密碼登陸的映象。
硬體及軟體資源請參考這篇博文。
(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。
# 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