To safely remove old files from the EFI System Partition (ESP) in Linux, follow these steps:
1. Identify and Remove Unnecessary Boot Entries:
Over time, the ESP can accumulate boot entries from previously installed operating systems. To clean these up:
sudo efibootmgr -v
This command displays all boot entries stored in the system's NVRAM.
-
Delete Unwanted Boot Entries:
Identify the boot number (e.g., Boot0002) of the entry you wish to remove. Then, execute:
sudo efibootmgr -b 0002 -B
Replace 0002 with the appropriate boot number. This action removes the specified boot entry from NVRAM[1].
2. Clean Up the EFI System Partition:
After removing boot entries, it's prudent to delete the corresponding files from the ESP to free up space:
-
Mount the ESP (if not already mounted):
The ESP is typically mounted at /boot/efi. If it's not mounted, you can mount it manually:
sudo mount /dev/sdX1 /boot/efi
Replace /dev/sdX1 with the correct partition identifier for your ESP.
- Navigate to the EFI Directory:
cd /boot/efi/EFI
- List Existing Bootloader Directories:
ls
This command displays directories corresponding to installed operating systems or bootloaders, such as Microsoft, ubuntu, fedora, etc.
-
Remove Unnecessary Directories:
If you've removed a boot entry and no longer use the associated operating system, delete its directory. For example, to remove the ubuntu directory:
sudo rm -rf ubuntu
Exercise caution to avoid deleting directories related to operating systems you still use[2].
3. Verify Remaining Space:
After cleaning up, check the available space on the ESP:
df -h /boot/efi
This command provides a human-readable format of disk usage, helping you confirm that the cleanup was successful.
Important Considerations:
-
Backup: Before making changes to the ESP, ensure you have a current backup of important data.
-
System Stability: Only remove entries and directories associated with operating systems or bootloaders you no longer use. Deleting essential files can render your system unbootable.
-
UEFI Firmware Behavior: Some UEFI firmware may automatically recreate boot entries if corresponding files exist in the ESP. In such cases, removing both the boot entry and the associated files is necessary to prevent reappearance[3].
By following these steps, you can effectively manage and clean up old files from the EFI System Partition in Linux, ensuring a tidy and efficient boot environment.