Hacking Cloud VM to use User password to Login(2)
Based on my previous blog that talk about how to hack cloud image and we then can login to VM by using use and password directly.
http://gogosatellite.blogspot.tw/2016/08/html-charsetutf-8-cloud-vm-to-use-user.html
Thanks for this blog that describe the detailed process to hack vm.
http://frederik.orellana.dk/booting-ubuntu-14-04-cloud-images-without-a-cloud/
The following the the process cmd based on the above blog, and it works greatly.
wget cloud-images.ubuntu.com/trusty/current/trusty-server-cloudimg-amd64-disk1.img
qemu-img convert -c -O qcow2 trusty-server-cloudimg-amd64-disk1.img trusty-server-cloudimg-amd64-disk1_30GB.qcow2
qemu-img resize trusty-server-cloudimg-amd64-disk1_30GB.qcow2 30G
sudo modprobe nbd
sudo qemu-nbd -c /dev/nbd0 `pwd`/trusty-server-cloudimg-amd64-disk1_30GB.qcow2
ls image || mkdir image
sudo mount /dev/nbd0p1 image
sudo sed -ri 's|(/boot/vmlinuz-3.13.0-24-generic\s*root=LABEL=cloudimg-rootfs.*)$|\1 ds=nocloud|' image/boot/grub/grub.cfg
sudo sed -ri 's|^(GRUB_CMDLINE_LINUX_DEFAULT=).*$|\1" ds=nocloud"|' image/etc/default/grub
sudo sed -ri 's|^#(GRUB_TERMINAL=console)$|\1|' image/etc/default/grub
sudo mkdir -p image/var/lib/cloud/seed/nocloud
sudo tee image/var/lib/cloud/seed/nocloud/meta-data <<EOF
instance-id: ubuntu
local-hostname: ubuntu
EOF
sudo tee image/var/lib/cloud/seed/nocloud/user-data <<EOF
#cloud-config
password: ubuntu
chpasswd: { expire: False }
ssh_pwauth: True
EOF
sudo sed -ri "s|^(127.0.0.1\s*localhost)$|\1\n127.0.0.1 `cat image/etc/hostname`|" image/etc/hosts
sudo sync
sudo umount image
sudo qemu-nbd -d /dev/nbd0
sudo modprobe -r nbd
No comments:
Post a Comment