Eucalyptus鏡像製作方法總結

經過幾天的奮鬥終於小有突破了。

製作Eucalyptus鏡像的方法主要有兩種,一種是在已有虛擬機上製作,另一種是以ISO的形勢來製作。一下主要來自Eucalyptus Community官方文檔的翻譯和國內論壇的整理。

第一種在VM上製作鏡像

該方法是在已經部署了Eucalyptus環境並且裝有CentOSVM上創建鏡像步驟:

1、 運行一個實例。

2、 確保實例上有足夠的空間創建新鏡像。

3、 使用KVM創建一個文件系統,並且將它掛載:

~$mkfs –t ext3 /dev/vdb

~$mount /dev/vdb /mnt

4、 SCP 你的eucalyptus 綁定證書到實例的/mnt下:

~$scp –I yourkey.private euca2-xxxxxxx-x509.zip [email protected]:/mnt

5、 SSH到實例:

~$ssh –I yourkey.private [email protected]

6、 安裝必備的工具:

~$yum install rsync unzip

7、 進入到/mnt(確保它有足夠的空間來創建image)

~$cd /mnt

8、 解壓eucalyptus證書到 /mnt/euca:

~$unzip euca2-admin-x509.zip -d euca/

9、 按照指導安裝Euca2ools on CentOS 5

10、安裝軟件到你要製作的image

11Source your Eucalyptus script:

/mnt/euca/eucarc

12、綁定image:

euca-bundle-vol -c ${EC2_CERT} -k ${EC2_PRIVATE_KEY} -u ${EC2_USER_ID} --ec2cert ${EUCALYPTUS_CERT} --no-inherit --kernel eki-47C7126D --ramdisk eri-80991354 -d /mnt -r x86_64 -p new.centos.5-3.x86-64.2GB.img -s 2048 -e /mnt,/root/.ssh

 

13、上傳bundle

euca-upload-bundle -b BUCKET_NAME -m /mnt/NEW_IMAGE_NAME.manifest.xml

 

如有"You do not have permission to access bucket: BUCKET_NAME" error。執行一下命令:

yum install -y ntp

ntpdate pool.ntp.org

 

14、註冊bundle:

euca-register BUCKET_NAME/NEW_IMAGE_NAME.manifest.xml

 

另一個例子(原理基本相同,只是實現手段不同)

1. Run an instance of the image.

2. SCP your Eucalyptus credential bundle (i.e., euca2-xxxxx-x509.zip) to the instance.

3. SSH into the instance.

4. Change to the super user: sudo su

5. apt-get update && apt-get -y install python-dev libssl-dev swig help2man unzip rsync make wget curl

6. Change to the /mnt device (it should have enough space to create new image bundle - I use 5GB for mine).

7. Unzip your Eucalyptus credentials zip file under /mnt, and delete the zip file from the login directory (so it doesn't get bundled in the new image).

8. Download Euca2ools 1.2 source code and dependencies source code from Eucalyptus' download page.

9. Follow the instructions to build Euc2ools. Make sure to uninstall the old Euca2ools before building the new one, if it is installed on the instance (i.e., apt-get remove euca2ools).

10. Install any other software you want on the instance.

11. Remove the udev rules: rm /etc/udev/rules.d/70*

12. Change to the /mnt directory and source your Eucalyptus script:

cd /mnt
. eucarc

13. Bundle the image:

 

euca-bundle-image -c ${EC2_CERT} -k ${EC2_PRIVATE_KEY} -u ${EC2_USER_ID} --ec2cert ${EUCALYPTUS_CERT} --no-inherit --kernel eki-KKKKKKKK --ramdisk eri-RRRRRRRR -d /mnt -r ARCH -p NEW_IMAGE_NAME -s SIZE_IN_MBs

eki-KKKKKKKK -> same as with running instance
eri-RRRRRRRR -> same as with running instance

Example:

euca-bundle-image -c ${EC2_CERT} -k ${EC2_PRIVATE_KEY} -u ${EC2_USER_ID} --ec2cert ${EUCALYPTUS_CERT} --no-inherit --kernel eki-0A104321 --ramdisk eri-1B031216 -d /mnt -r x86_64 -p myimage -s 5120

 

14. Upload bundle:

euca-upload-bundle -b BUCKET_NAME -m /mnt/NEW_IMAGE_NAME.manifest.xml

Example:

euca-upload-bundle -b test1 -m /mnt/myimage.manifest.xml

 

15. Register bundle:

euca-register BUCKET_NAME/NEW_IMAGE_NAME.manifest.xml

Example:

euca-register test1/myimage.manifest.xml

第二種使用ISOKVM中創建windows鏡像

下面分三步製作EMI(eucalyptus machine image),EKI(eucalyptus kernel image),ERI(eucalyputs ramdisk image)

第一步要製作EMI

1、在~下創建virtualxp目錄用來存放鏡像文件:

~$mkdir virtualxp

 

2、創建一個用於執行windows安裝的硬盤鏡像,並可以設置該鏡像的大小。例如,如下命令就創建了一個10GB的硬盤鏡像win.img

~$dd if=/dev/zero of=~/virtualxp/win.img bs=1M count=10000

 

3、放入winxp安裝盤並執行以下命令(必須是安裝盤,我沒有測試ghost,論壇上說ghost

陳功):

    ~$kvm –m 1024 –boot d –cdrom /dev/cdrom –drive file=~/virtualxp/win.img,

If=scsi,boot=on

 

執行上述命令,將會在窗口虛擬環境qume下進入我們熟悉的windows xp安裝,因爲xp安裝在一個未被格式化的硬盤的鏡像(win.img)上,首先會要求分區,並且至少分成兩個區,分區完了就直接安裝,安裝完成可能會假死,可以試着關閉窗口,通過如下命令進入我們剛裝好的xp系統:

~$kvm -m 1024 -boot c -drive file=~/virtualxp/win.img,if=scsi,boot=on

 -net nic,model=e1000

 

這兩條命令可能會報錯,基本不會影響安裝,另外安裝時間是超長,我前後用了2小時左右。

第二步製作EKI

/usr/lib/syslinux 下找到 memdisk,複製到 ~/virtualxp 下。(如果沒有syslinux,可以下載安裝:apt-get install syslinux

第三步製作ERI

1、創建軟盤鏡像 win-boot.img

~$dd if=/dev/zero of=~/virtualxp/win-boot.img bs=512 count=2880

 

2、以加載軟盤的方式進入windows鏡像

~$kvm -m 1024 -boot c -drive file=~/virtualxp/win.img,if=scsi,boot=on,index=1 -fda ~/virtualxp/win-boot.img

 

3、在進入鏡像的xp系統後,找到 ntldrntdetect.comsym_hi.sys boot.ini這四個隱藏文件,其中將 sym_hi.sys 改名爲 Ntbootdd.sys,如果沒有boot.ini創建一個 boot.ini 文件,內容如下:

[boot loader]

timeout=30

Default= multi(0)disk(0)rdisk(0)partition(1)\Windows

[operating systems]

multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Windows XP"

 

將上述的四個文件拷貝到軟盤當中(先格式化),注意,這裏說的軟盤是指在KVM虛擬機中的xp系統所看到的軟盤。

 

至此,windows xpeucalyptus鏡像基本製作完畢!

 

第四步是分別bundle 鏡像到eucalyptus上:

這些操作跟綁定其他OS鏡像基本上一致:

1、進入到 ~/virtualxp

 

2、綁定EKI

euca-bundle-image -i memdisk -d ./kernel --kernel true

euca-upload-bundle -b winxp-bucket -m ./kernel/memdisk.manifest.xml

euca-register winxp-bucket/memdisk.manifest.xml

 

3、綁定ERI

euca-bundle-image -i win-boot.img -d ./ramdisk --ramdisk true

euca-upload-bundle -b winxp-bucket -m ./ramdisk/win-boot.img.manifest.xml

euca-register winxp-bucket/win-boot.img.manifest.xml

 

4、綁定EMI

euca-bundle-image -i win.img -d ./image

euca-upload-bundle -b winxp-bucket -m ./image/win.img.manifest.xml

euca-register winxp-bucket/win.img.manifest.xml

 

這樣windowsXP就可以在eucalyptus上使用。

第三種使用ISOKVM中創建linux鏡像

下面是步驟

1、創建虛擬硬盤用來安裝系統,如下創建一個大小爲4G的虛擬硬盤new.img:

~$dd if=/dev/zero of=new.img bs=1M count=4096

 

2、以CDROM模式啓動KVMnew.img做爲啓動硬盤:

~$kvm -cdrom iso_image -drive if=scsi,file=new.img,boot=off

 

3、在虛擬窗口中選擇一個分區正常安裝系統。

 

NOTE: most distributions will remember the network interfaces by the MAC address so that interfaces will always be the same (that is eth0 and eth1 will no t be inverted accidentally). In Eucalyptus you have to get the distribution to forget the NIC, so that every instance will see the interface as the first interface. To do so you may want to see to the specific disrtibution: for example debian/ubuntu uses udev so check /etc/udev/rules.d/*net* while centos may have something in /etc/network-scripts/ifcfg-eth0. Failure to do so may leave your instance without network;

 

4、找到開始塊和跟文件系統的大小,提取文件:

~$dd if=new.img of=rootfs.img bs=512 skip=63 count=2000

 

Rootfs.img 就是包含跟文件的系統,確保 kernel/initrdimg的兼容性。

 

總結

    以上幾種方法,從實現原理上都有一定的相似之處,即製作EMI,EKI,ERI,三部分。我製作了第二種windows鏡像,經測試,可以運行在Eucalyptus環境下,但存在BUG,不能再次登錄,初步分析是引導文件處許修改,正想辦法解決。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章