Recover root password with grub

In boot menu select OS, for example Ubuntu and press e to edit

Navigate down to the line with linux. Press ctrl+e to navigate to the end

Remove consoles and change ro to rw. Then add init=/bin/bash. Press Ctrl+x or F10 to boot with this configuration and the boot process starts

Change the root password - as usual with this command:

passwd
Finally - continue the boot process with this command:
exec /sbin/init