AWS – Export Amazon EC2 instance to VirtualBox

若要從Amazon EC2 instance import系統出來的做法…

Dump the EBS volume into a downloadable file

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

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

# dd if=/dev/xvda | lzma -z -0 > ./ec2.img.lzma

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

解壓縮成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

然後掛載它

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拿掉