Ubuntu 16.04: Boot into rescue mode (a.k.a recovery mode)

Rescue mode (a.k.a. recovery mode) provides a minimal environment (though not as minimal as emergency mode) that enables you to perform system recovery tasks. To enter rescue mode, reboot the machine while repeatedly pressing ESC, until you get to the GRUB menu:

Now, press “e” while highlighting the “Ubuntu” option. You will be brought to a GRUB file editor. Add the word “emergency” to the end of the “linux” boot option.

Press F10. The machine will now boot. Press ENTER to enter recovery mode:

You should now have access to a root shell. If you want to make any modification to your file system you’ll need to mount the root partition:

$ mount -o remount,rw /

You are now free to edit files.