หากคุณใช้ virtualization ไม่ว่าจะเป็น business หรือ pleasure คุณอาจเคยเจอ VirtualBox โซลูชันฟรีที่ powerful และ highly versatile ที่ให้ desktop users enormous flexibility เมื่อพูดถึงการ deploy operating systems 任何方式
และหากคุณมากกว่าแค่ hobbyist ที่เพลิดเพลินกับ virtualization เพราะ geekiness หรือ aspiring software enthusiast ที่เรียนรู้ทางรอบ operating systems ใหม่ๆ โดยความสามารถของ virtualization คุณจะเจอ scenario ต่อไปนี้: คุณต้อง deploy a large number of virtual machines
คุณไม่มีเวลา fiddle กับ individual installations แน่นอน การ configure machines ทีละตัว manually เป็น worst thing ที่คุณสามารถทำได้เมื่อ massively deploying an install base มันซ้ำซ้อนของ bad habits มันช้า ไม่ efficient และคุณมีแนวโน้มสูงสุดที่จะจบลงด้วย number of different setups ทำให้ environment ของคุณอยู่ใน inconsistent state
เพื่อแก้ไขปัญหานี้ คุณต้องการ bit-by-bit solution ที่จะ replicate basic installation image ของคุณเป็น desired number of copies นี่เรียกว่า cloning VirtualBox มอบ solution นี้ มาดูวิธีทำกัน

Cloning
มี several ways ที่คุณสามารถไปเกี่ยวกับ cloning
Copy
คุณสามารถ manually copy hard disk ที่ installed image อยู่ได้ Virtual machine hard disks เป็น files ดังนั้นจึงเป็น fairly simple deal ผมสาธิต concept นี้เมื่อสักครู่นี้ แม้จะกับ virtualization products อื่นๆ: VMware Server 和 VMware ESXi
Imaging
คุณยังสามารถใช้ dedicated imaging software ได้ เช่น CloneZilla คุณ boot into live environment, image disks/partitions 然後 restore image ไปยัง empty disk ใน second virtual machine สร้าง exact copy
Conversion
เรายัง學會了如何使用 VMware Converter 來轉換我們的 images 來回在 desired formats 之間 同時保留 basic image VirtualBox 提供 yet another method
Cloning in VirtualBox
VirtualBox 包含 built-in utility สำหรับ disk management 稱為 VBoxManage utility นี้ available บนทั้ง Windows และ Linux VirtualBox installations ใน Windows คุณจะพบมันใน VirtualBox directory ใน Linux มันจะ被添加到 execution path
VBoxManage 可以做 far more than clone 執行 VBoxManage /? 在 Windows 或 VBoxManage --help 在 Linux เพื่อดู staggering list of options
VBoxManage cloning syntax คือ:
VBoxManage clonehd <old> <new> --format VDI
What we have here?
hdclone บอกเรา operation 我們想要執行
<old> 和 <new> 是 hard disks 的 names 例如 ubuntu-9.04.vdi 是 original ของเรา และ ubuntu-9.04-cloned.vdi จะ是 clone ของเรา
--format VDI 告訴我們 format 我們想要 disk ของเราเป็น Like QEMU VirtualBox 有 ability 來處理不同的 virtual hard disk formats 這使它 compatible กับ virtualization products อื่นๆ ใน market
基本上 只是這樣 運行命令 並觀察 progress 在命令行窗口 中 不管是在 Windows 或 Linux
一會兒後 您將有 clone available:
您現在可以 attach new disk 到任何 virtual machine 和 boot exact copy ของ existing setup ของคุณ Believe it or not 那就是 whole magic!
Alternative method
也可以使用 ordinary copy กับ VirtualBox 就像 VMware 一樣 然而 一些 users 報告 plain file copy 有時會 corrupt target file 個人來說 我沒有遇到任何 issues 使用這個 但如果您遇到問題 您可能想嘗試這個 trick:
Tar/rar/zip image ก่อน copy 這似乎在 ordinary file copy 不夠好的那些 cases 中有效 The best way 以確保您的 copy 成功 是 check MD5 sum of the target file 和 compare 它到 original 和當然 您應該 boot virtual machine ของ您從 new disk 以確保它工作如預期
Conclusion
這是一個 very short 但 useful tutorial 我們現在學會了如何使用 VBoxManage 來改善和自動化我們 environment 的 administration 由於這個 utility 從 command line 運行 所以可以在 scripts 中使用它 並 schedule cloning, backups 等
在下一篇文章中 我們將學習如何添加 disks 到 virtual machines 在續集之後 我們將 expand/shrink virtual disks 在第四部分 VirtualBox management 我們將學習 different ways of configuring networking 和 sharing
Have fun!