Saturday, June 16, 2012

Lupa Password Root pada server Virtual Machine

Kegiatan ini sebenarnya sudah selesai saya lakukan pada tanggal 28 Februari 2012. Tetapi, baru sekarang sempat saya tuliskan lagi. Mudah-mudahan berguna 

SITUATION :

1. Forget / lost  root password at Ubuntu OS.
2. The OS is Virtual Machine. So using physical CD is not possible to recover it.
3. Using GRUB bootloader trick (press ESC or SHIFT) was failed.



--------------------------------------
SOLUTION
--------------------------------------

1. Login as user who has sudo to root at Host Server (physical server)

2. Instal Kpartx
   sudo apt-get install kpartx

3. Stop the VM
   virsh shutdownd VM_name

4. Go to folder where VM_name.img image file is kept
   cd /folder_location/VM/images

5. Look at loop partition which to be mounted
   kpartx -l VM_name.img
6. Create folder /mnt/another_folder
   mkdir -p /mnt/another_folder

7. Mount loop partition of VM_name.img   mount /dev/mapper/loop0p2 /mnt/another_folder

9. Go to /mnt/another_folder
   cd /mnt/iec_prod

9. Copy hash password from another Linux file. For this case, I used my password hash from Host Server (physical server)
   a. less /etc/shadow
   b. Copy entry hash password of my user from it.


10. Paste it into /mnt/another_folder/etc/shadow file
   a. cd /mnt/another_folder/etc/shadow
   b. vi /mnt/another_folder/etc/shadow
   c. Change root hash password from the hash which copied before
   d. Save it


11. Unmount /mnt/another_folder and make sure it really unmount
    a. umount /mnt/another_folder
    b. ls /mnt/another_folder  -->  Should be empty !!


12. Start the VM
    virsh start VM_name

13. Try to login with root password. Now you can login !!

---------------
References :
---------------

http://panoskrt.wordpress.com/2009/01/21/mounting-partitions-within-image-file/
http://www.linuxquestions.org/questions/linux-software-2/mount-qemu-image-541263/
http://www.linuxquestions.org/questions/linux-general-1/how-to-mount-img-file-882386/
http://www.linuxquestions.org/questions/linux-software-2/mounting-a-single-fat32-partition-inside-a-full-disc-image-776922/#post3798799
http://en.wikibooks.org/wiki/QEMU/Images#Mounting_an_image_on_the_host
https://wiki.archlinux.org/index.php/QEMU#Mounting_the_hard_disk_image_-_raw_image
http://rwmj.wordpress.com/2010/07/11/sed-like-configuration-file-editing-with-virt-edit/
http://rwmj.wordpress.com/2010/08/25/libguestfs-binaries-for-all-linux-distros/
http://rwmj.wordpress.com/2009/09/23/virt-edit/
  
Post a Comment