Thursday, 13 May 2010

How To Reset A Forgotten root Password On A Linux Virtual Machine on XenServer

I recently had to carry out some maintenance on a Linux server hosted on our XenServer. However I had forgotten the root password. Lesson learned to save password in a secure location such as an encrypted usb stick or in an encrypted file on my cell phone. Anyway I digress, on the make it just work section.

From Xencenter select the virtual machine you want to boot in single user mode.

Shut down your virtual machine using the Xencenter controls.

Right click on the Boot Options for your virtual machine and select Properties.

Change the OS Boot Parameters to

rw init=/bin/bash

NOTE If you already have something in the OS Boot Parameters you will need to take note of this as you will need to put it back once the password reset is complete.

Save and Start your virtual machine

Your system will now boot up in single user mode.

Now its time to change your password

machinename# passwd root

Type in your new password you will then be asked to confirm it.

Your password has now been reset.
Shutdown your virtual machine.
machinename# shutdown -h now

Now go Back to the Xencenter Application and Startup options and remove rw init=/bin/bash and change it back to whatever was there before.
Start up your virtual machine and you should be able to logon with your new root password.