Recover Password
This section describes how to reset a lost password.
Boot the router into
ONIE Rescue
mode.a. Power cycle the router and press the
Esc
key to enter the SONiC GRUB mode.GNU GRUB version 2.02 +----------------------------------------------------------------------------+ |*SONiC-OS-azure_Cisco_202012.105636 | | ONIE | | | | | | | | | | | +----------------------------------------------------------------------------+ Use the ^ and v keys to select which entry is highlighted. Press enter to boot the selected OS, `e' to edit the commands before booting or `c' for a command-line.
b. Select
ONIE
and press theEnter
key.c. Select
ONIE: Rescue
from the list of options.GNU GRUB version 2.02 +----------------------------------------------------------------------------+ | ONIE: Install OS | |*ONIE: Rescue | | ONIE: Uninstall OS | | ONIE: Update ONIE | | ONIE: Embed ONIE | | | | | | | +----------------------------------------------------------------------------+ Use the ^ and v keys to select which entry is highlighted. Press enter to boot the selected OS, `e' to edit the commands before booting or `c' for a command-line.
Note: If you select
Install OS
, ONIE might update the boot order and the router will boot into the successive GRUB menu bypassing the option to boot into the SONiC partition. You may have to use the efibootmgr command from ONIE to change the boot order back to SONiC as the first option.The router enters the ONIE Rescue mode.
Mount the SONiC partition.
a. Check the disk partitions where SONiC is installed.
ONIE:/ # parted -l Model: ATA Micron_5300_MTFD (scsi) Disk /dev/sda: 128GB Sector size (logical/physical): 512B/4096B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 269MB 268MB fat16 EFI System boot, hidden 2 269MB 404MB 134MB ext4 ONIE-BOOT hidden 3 404MB 34.8GB 34.4GB ext4 SONiC-OS
In the example, SONiC is installed on the third partition of the disk
/dev/sda
location. So, mount the/dev/sda3
partition to update the password file.b. Create a folder to mount the SONiC partition. In this example, you create
sonic_recovery
folder.ONIE:/ # mkdir /mnt/sonic_recovery
c. Mount the SONiC partition to the
sonic_recovery
folder.ONIE:/ # mount -t ext4 /dev/sda3 /mnt/sonic_recovery
Remove the password.
a. Enter the SONiC partition folder.
ONIE:/ # cd /mnt/sonic_recovery
b. View the files mounted in the
/dev/sda3
partition.ONIE:/mnt/sonic_recovery # ls -al drwxr-xr-x 9 root 0 4096 Apr 5 07:34 . drwxr-xr-x 5 root 0 100 Apr 5 07:52 .. drwxr-xr-x 2 root 0 4096 Mar 30 20:42 disk-img drwxr-xr-x 5 root 0 4096 Mar 30 20:40 grub drwxr-xr-x 8 root 0 4096 Mar 31 20:42 image-azure-cisco_202012.105636 drwx------ 2 root 0 16384 Apr 1 20:39 lost+found -rw-r--r-- 1 root 0 854 Apr 2 20:40 machine.conf drwxr-xr-x 4 root 0 4096 Apr 2 13:20 reboot-cause drwxr-xr-x 3 root 0 4096 Apr 2 20:44 warmboot
c. Enter the directory where the SONiC image is saved, and then enter the
/etc
subdirectory.ONIE:/mnt/sonic_recovery # cd image-azure_cisco_202012.10563 ONIE:/mnt/sonic_recovery/image-azure_cisco_202012.10563 # cd rw ONIE:/mnt/sonic_recovery/image-azure_cisco_202012.10563/rw # cd etc ONIE:/mnt/sonic_recovery/image-azure_cisco_202012.10563/rw/etc # ls adjtime group ld.so.cache network passwd- ssh cron.d gshadow linuxptp nsswitch.conf profile.d sysctl.d default gshadow- machine-id nsswitch.conf.old rsyslog.conf systemd dhcp hostname modprobe.d ntp.conf shadow tacplus_nss.conf ebtables.filter hosts modules-load.d pam.d shadowgroup hosts.old mtab passwd sonic
The
shadow
file is the password file.d. Search the username for which you want to recover the password. In this example, you recover the password for the username
cisco
.ONIE:/mnt/sonic_recovery/image-azure_cisco_202012.10563/rw/etc # ls -al | grep shadow -rw-r----- 1 root 42 603 Apr 5 14:28 gshadow -rw-r----- 1 root 42 581 Apr 5 21:04 gshadow -rw------- 1 root 42 860 Apr 5 14:28 gshadow -rw------- 1 root 42 828 Apr 5 21:04 gshadow ONIE:/mnt/sonic_recovery/image-azure_cisco_202012.10563/rw/etc # grep cisco shadow cisco:6$sjaIDBUmsklcsnnTUYt/sdfkjKGDWFLdnlakkjbbjXAD1:19262:0:99999:7:::
e. Remove the password for the
cisco
username using vi shadow command. Alternatively, you can also use thesed
command. Delete the characters between the first and the second colon symbol (:). In this example, the password 6$sjaIDBUmsklcsnnTUYt/sdfkjKGDWFLdnlakkjbbjXAD1 between the first and second colon symbols is removed as displayed in step 3d.cisco::19262:0:99999:7:::
After you delete the password, use the
wq
command to save the file and quit the mode. The ONIE prompt is displayed.Reboot the router.
ONIE:/mnt/sonic_recovery/image-azure_cisco_202012.10563/rw/etc # reboot
Select the SONiC image from the GRUB mode, and press the
Enter
key.Enter the username and set a new password.
Last login: Wed Apr 6 18:52:14 UTC 2020 on ttyS0 Linux sonic 4.19.0-9-cisco-amd64 #1 SMP Debian 4.19.118-2+deb10u1 (2020-06-07) x86_64 You are on ____ ___ _ _ _ ____ / ___| / _ \| \ | (_)/ ___| \___ \| | | | \| | | | ___) | |_| | |\ | | |___ |____/ \___/|_| \_|_|\____| -- Software for Open Networking in the Cloud -- Unauthorized access and/or use are prohibited. All access and/or use are subject to monitoring. Help: http://azure.github.io/SONiC/ sonic:~cisco New password: Retype new password:
The new password is updated successfully.