AWS – Export Amazon EC2 instance to VirtualBox

Dump the EBS volume into a downloadable file

先在aws產生免費8g,再產生50g以上的空間出來存放檔案
/dev/vda1 8G
/dev/vdb 50G

登入伺服器,執行dd指令,把這個parttion COPY出來存成檔案, 記得檔案要放在50g那邊的空間

  • 執行dd指令,把這個parttion COPY出來存成檔案
  • dd if=/dev/xvda | lzma -z -0 > ./ec2.img.lzma

然後把檔案scp出來,記得要本機是用ubuntu做…因為掛載要用ubuntu機器。
解壓縮成img。

# lzma -cd ec2.img.lzma > ec2.img

Check img

# fdisk -l ec2.img

The offset is equal to Start times sector size. In my case 2048 times 512, which equals 1048576. Now, I can mount the img file as a partition:

這個意思是指Sector 開始值2048 x 512=1048576

然後掛載它

# mount -o loop,offset=1048576 ec2.img /mnt/disk
 
# chroot /mnt/disk;
 
# rm /etc/systemd/system/multi-user.target.wants/cloud*;
 
# echo "+ : ALL : ALL" >> /etc/security/access.conf;
 
exit;
 
umount /mnt/disk;

Convert the raw image to the desired VM

VBoxManage convertfromraw ec2.img ec2.vdi –format VDI

在用的時間

14.04 版本有一個問題


cloud-init is attempting to contact 169.254.169.254, a link-local IP address that cloud providers

請修改 /etc/cloud/cloud.cfg.d/90_dpkg.cfg

# to update this file, run dpkg-reconfigure cloud-init

datasource_list: [ NoCloud, ConfigDrive, OpenNebula, Azure, AltCloud, OVF, MAAS, GCE, OpenStack, CloudSigma, Ec2, CloudStack, None ]


to:


# to update this file, run dpkg-reconfigure cloud-init


datasource_list: [ None ]


If possible, you’ll want to run dpkg-reconfigure cloud-init to make the change.

16.04版本有二個問題

第一個問題同上…

第二個問題是會出現
要到grub.conf把tty=0拿掉…
/mnt/boot/grub/grub.cfg to remove the console=ttyS0 bits
/etc/default/grub.d/50-cloudimg-setting.cfg console=ttyS0拿掉

參考連結:

http://diogomelo.net/blog/16/export-amazon-ec2-instance-to-virtualbox