0

I lost my password to both root and sudo and need to remove ubuntu and erase my HDD. Needless to say this was a stupid newby screwup. I have backed up everything I want to save. How do I rescue my HDD?

Alien
  • 1
  • 1
    If you don't want reset the password and already have backups why not just reinstall? –  Jun 25 '19 at 21:04
  • 3
    You don't need the root or sudo password if you are just going to format and install another OS. Just boot to the other OS and step through the installation. – Terrance Jun 25 '19 at 21:07
  • Can try this first before installing again, even if just for fun. https://askubuntu.com/questions/24006/how-do-i-reset-a-lost-administrative-password – crip659 Jun 25 '19 at 23:08
  • 4
    Possible duplicate of How do I reset a lost administrative password? since the actual goal here is to regain the ability to exercise full control of a computer in the face of forgotten passwords. (@Alien If you still want to reinstall for some reason and erase the whole disk, or if you have already erased the disk so you want to reinstall Ubuntu for that reason, then How do I install Ubuntu? includes information about doing that.) – Eliah Kagan Jun 26 '19 at 00:38

1 Answers1

2

If all that is wrong is you've forgotten your passwords, you shouldn't have to remove Ubuntu and erase your HDD. What I would do is simply boot up Linux in live mode from my Ubuntu USB thumb drive, chroot into the hard drive installation, and change your passwords. Easy peasy...

  1. Boot from your Ubuntu USB Thumb drive in Linux Live mode. Don't re-install Ubuntu.

  2. Once booted into live Linux, open a Terminal and start working through these commands:

mkdir linux

sudo mount /dev/sdXX linux

(replace "/dev/sdXX" with whatever device/partition number is correct for the "/" root Linux partition on your hard drive. You might need to run "gparted" to have a look at your partition tables to figure out what is what)

sudo chroot linux /bin/bash

mount -t devtmpfs udev /dev

mount -t proc proc /proc

mount -t sysfs sysfs /sys

passwd USERNAME

(replace USERNAME with whatever your user name was. Or use "root" to change the root password on your HDD).

The chroot command lets you operate on your HDD's Linux system as if you were booted from it, even though you're really booted from the USB thumb drive. It also acts kind of like "su -" in that you will be in your HDD's Linux as root (without requiring your HDD's root password).

Once all that is done, you have to unmount all the stuff we previously mounted from within the chroot environment before exiting. Otherwise, Ubuntu will have a hard time unmounting the Linux partition cleanly when you shutdown.

umount /sys

umount /proc

umount /dev

exit

sudo umount linux

sync

And there you have it. Shutdown and reboot into Linux on your HDD and you should be good to go!

K9spud
  • 266