iTranslated by AI
How to recover data from Ubuntu when the GUI is unresponsive [Recovery Mode]
Introduction
An issue occurred on a laptop with Ubuntu installed where the mouse and keyboard stopped working after GUI login. This is a record of the steps taken to migrate important data saved on the PC to a USB flash drive using recovery mode.
PC Environment
| Item | Details |
|---|---|
| Model | HP Elite |
| OS | Ubuntu 19.04 |
Preparation: Prepare a USB Flash Drive
It is recommended to format the USB flash drive using the highly compatible exFAT file system so that data can be read and written on other operating systems such as Windows or macOS.
General Flow
- Boot into recovery mode
- Mount the USB flash drive
- Copy the data
- Post-processing
1. Entering Recovery Mode
What is Recovery Mode?
It is a special mode used to boot with a minimal environment to perform troubleshooting and repair tasks when a system problem occurs. Unlike a normal boot, it starts with the minimum necessary system resources and provides access to a shell with administrative privileges.
-
After pressing the power button, repeatedly press the
ESCkey (for UEFI) orSHIFTkey (for BIOS) to display the bootloader menu. -
When the bootloader menu appears, select
Advanced options for Ubuntu.

-
Select
Ubuntu, with Linux... (recovery mode).

-
When a screen like the following appears, select
root Drop to root shell prompt.

-
When
Press Enter for maintenanceis displayed, press theEnterkey again. -
Success is when you reach a state where you can input commands (the prompt # is displayed).
If the File System is Read-Only
It seems that in recovery mode, the file system may be set to read-only by default. Since data cannot be copied in this state, execute the following command to allow writing.
mount -o remount,rw /
2. Mount the USB Device
Mount the connected USB flash drive to make it recognized and usable.
First, check the current disk configuration before connecting the USB flash drive.
-
Before connecting the USB flash drive you want to mount, enter the following command to check the list:
lsblk -
Connect the USB flash drive and enter the command again:
lsblk -
Compare the results with the previous one to find the USB flash drive you want to mount (e.g., sdb). Select a partition with sufficient capacity from sda1, sda2, sda... (in this case, sda2).
NAME MAJ:MIN RM SIZE RO TYPE sda 8:0 0 59.5G 0 disk ├─sda1 8:1 0 512M 0 part └─sda2 8:2 0 59G 0 part -
Create a mount point directory:
mkdir /mnt/usb -
Mount the USB flash drive:
mount /dev/sda2 /mnt/usb -
Move to the mount point directory and confirm it is correctly mounted:
cd /mnt/usb ls -
Success is if the files and folders inside the USB flash drive are displayed.
3. Copying Data to the USB Flash Drive
Copy the data to the USB flash drive using the cp command.
-
Check the directory containing the data you want to back up (in this example, we will back up the user's home directory).
cd /home/user pwd -
For good measure, check the mount destination directory as well.
cd /mnt/usb pwd -
Use the cp command to copy the data to the USB flash drive.
cp -r -v /home/user /mnt/usb -
Copying may take some time depending on the amount of data. After executing the command, wait patiently without performing any operations until the prompt (#) is displayed again.
-
Once the copy is complete, check the contents of the USB flash drive to ensure the data has been copied correctly.
cd /mnt/usb ls
4. Post-processing
-
Unmount (detach) the mounted USB flash drive.
umount /mnt/usb -
Shut down the system and remove the USB drive after the power is off.
shutdown -h now
Conclusion
The cp command has many options, so it is important to research them in advance. It is also essential to take regular backups. Please take this opportunity to reconsider your backup habits.
Discussion