Memory cards are great for saving information and transferring it between digital cameras, mobile devices, and various computers. However, sometimes you try to access your SD card on Linux and find that some files are gone or inaccessible.
If you’re on Linux, you’ll soon discover that most of the information about recovery is focused on macOS or Windows. There’s little to no information on how to perform Linux SD card recovery. Luckily for you, we have the answers you need. This article will look at effective methods to recover files from an SD card on Linux.
In this article
Part 1: Prerequisites
It can be pretty frustrating when you lose data on your SD card. However, this is not the ideal time to panic. A single wrong move can significantly reduce your chances of returning your lost data. Below are some prerequisites you need to meet before beginning the recovery process.
Check If Your SD Card Is Mounted
The first thing you must do in such a situation is to confirm that your SD card is mounted. Most Linux distributions are configured to mount removable storage devices automatically. However, this doesn’t always happen. You won’t be able to access your SD card without mounting it. Therefore, you must follow the steps outlined below to ensure your SD card is mounted and your Ubuntu Linux PC can detect it.
Step 1: Launch the terminal by pressing the Ctrl + Alt + T buttons simultaneously. Most Linux distributions treat SD cards as SATA storage devices, so you should find them under the /dev/
subfolder.
Step 2: To access this subfolder, use the command:
ls -l /dev/sd
If you don’t find your SD card, you must mount it manually. Create a folder under /mnt/
and link it to the device you want to access.
Step 3: You can also use the mkdir
command to create a new folder to store the SD card. Since /mnt/
is protected, you’ll need to use sudo
to get temporary administrative rights.
Step 4: enter the /mnt
folder using the change Dir (cd) command:
cd /mnt
Step 5: Next, create a new folder for your SD card using the command:
sudo mkdir NAME OF SD_CARD
Step 6: You can now attach your SD card’s primary partition in the same format as the list you saw when you checked the /dev
folder. Use the command:
sudo mount /dev/SDCARDDEVICE /mnt/SDCARDFOLDER
That’s all you have to do; you’ll find that you can now access your card through the /mnt
mount point.
Backup the Available Contents on the SD Card
Before you attempt the Linux SD card recovery process, you must back up the available files on the SD card. This is to prevent further data loss after you recover the lost data. You can copy the data on an SD card to your Linux PC if the file size is small. Otherwise, you will need a data backup tool to speed up the process.
Gddrescue is a good option for data backup in Linux. You can use it to back your SD card to an image file. After the backup process, you can always recover your data from the image file without worrying if your SD card fails during the data recovery process. To backup data using Gddrescue, follow the steps below.
Step 1: Install Gddrescue on your Ubuntu Linux with the command:
sudo apt install gddrescue
Step 2: After installation, you can use the command below to find your SD card amongst the storage devices discovered:
lsblk
or ls -l /dev/sd*
Although the tool’s name is Gddrescue, the command to utilize this tool is ddresuce. You’ll also have to use sudo
for the entire backing-up process. To back up your data after installation, continue with the steps below.
Step 3: Use the command:
sudo ddresue -d /dev/SDCARDDEVICE/PATH/TO/IMAGE/FILE/IMAGEFILENAME/PATH/TO/LOG/FILE/MAPFILENAME
The command above works for a quick backup. If you want an extensive backup to save large data, you need to utilize the rx
flag to notify Gddrescue how many times it could overcome errors. The higher number you use, the higher the chance of recovery. However, this also means a higher scanning period.
Step 4: To set the number of retries as a number, enter the command:
sudo ddrescue -dr5 /dev/SDCARDDEVICE/PATH/TO/IMAGE/IMAGEFILENAME/PATH/TO/LOG/FILE/MAPFILENAME
Step 5: You can mount the created image as a storage device whenever you want to access its content.
Part 2: 4 Methods to Recover Files from SD Cards on Linux
Now that you have ensured your SD card is mounted correctly and have a backup of available content, you can proceed with the Linux SD card recovery process. There are four effective methods to recover files from an SD card in Linux, and we’ll review them in this section; let’s take a look.
Method 1: Repair the SD Card With Ubuntu’s GNOME Disk Utility
The first method you can use to recover data from an SD card on Linux is the GNOME Disk Utility. This Ubuntu SD card recovery tool effectively ensures you regain access to all your lost data. It repairs the SD card to make the storage device accessible once again. Below are the steps you need to follow to fix the SD card in Linux using this utility tool.
Step 1: Open the GNOME disk utility from the Whisker, Dash, or KDE menu.
Step 2: Locate the device file name for your flash reader. You’ll usually find that it reads ‘single flash reader.’
Step 3:If you find this option beneath the storage graph, click the downward-facing arrow to try and mount it. If it mounds, then you can start copying its files.
Step 4: Sometimes, it will read ‘no media.’ In such a case, try disconnecting and reconnecting the card and then check if anything changes. If you can, click on the gear icon and select the Create disk image option.
Step 5: Now, try saving it as an image file. Once this is successful, you can move on to the next step.
Step 6: Eject the card and insert a new black SD card of the same size. Write the disk image into this new card using the gear menu.
Step 7: You can now mount the new file system. However, you must ensure that the new card is entirely blank, as you could lose all the files on the card when you proceed.
Step 8: When you unmount the partition and Ubuntu still detects it, you can run a consistency check to ensure a recovery of the file system. If you have a FAT32, FAT12, rr FAT16 card, run the following command in the command line to begin recovery:
sudo fsck.msdos -r /dev/sdd1
However, you should replace the sdd1 part of the code with the name of the partition provided in the disk utility.
Step 9: If you formatted the card to work with a Linux file system, simply enter fsck.ext#
. Replace # with the ext number of the system if you remember it.
Method 2: Repair the SD Card on a Dual-Boot Ubuntu System
If the Ubuntu SD card recovery tool above doesn’t work out, you can use the dual-boot Ubuntu system for a Linux SD card recovery. If you install Linux alongside Windows, this is the best option.
You can repair the SD card using the chkdsk command in a Windows command prompt. Although Ubuntu offers a higher chance of recovering lost data from FAT devices, Windows can help you effectively recover NTFS devices. Below are steps you need to follow to repair your SD card on a dual-boot Ubuntu system.
Step 1: First, you need to reboot the computer, and when GRUB appears, prompt it to begin the installation of Microsoft Windows with the keyword.
Step 2: Afterwards, open a File Explorer window by simultaneously holding down the Windows + E buttons.
Step 3: Now, locate the drive letter Windows assigned to the memory card and select it. Windows might ask you to format the card; ignore this suggestion.
Step 4: Open a command prompt by searching ‘command prompt’ in the search bar and selecting the option when it appears.
Step 5: On the command prompt, type:
chkdisk /f E:
Ensure you replace E: with the drive letter Windows assigned to the SD card.
Step 6: If you got an error message, Windows didn’t have much luck recovering your memory card like Ubuntu.
Step 7: If you don’t have access to Microsoft Windows, you can run the command below on Ubuntu:
sudo ntfsfix -d /dev/sdd1
You need to replace the device file with the card’s name. Although this isn’t the Linux version of chkdsk, it will repair some inconsistencies.
Step 8: You can also use the following command to take a disk image of an NTFS memory card if the GNOME Disk Utility fails to do this:
ntfsclone -so dsk.img /dev/sdd1
Afterward, you can restore files from SD card in Linux to a blank memory card when it’s time.
Method 3: Recover Deleted or Lost Files From an SD Card With TestDisk for Linux
If the built-in Linux SD card recovery solutions don’t work, you can try data recovery tools like TestDisk for Linux. This tool will help you to recover various types of lost files from your SD card within a few minutes. Follow this tool’s steps below to recover files from an SD card in Linux.
Step 1: Install TestDisk using the Linux CLI prompt by running the command:
sudo apt-get install testdisk
Step 2: After installation, you must check the SD card for potential fixable issues using TestDisk. Therefore, run the tool by typing testdisk
in a terminal and pressing Enter.
Step 3: Select Create from the first menuto develop a new log file.
Step 4: Use the cursor keys to select your SD card from the list provided by TestDisk. Ensure you highlight proceed. You can use the left and right cursor keys to highlight it if it isn’t. After choosing the SD card, press Enter.
Step 5: Now, select the partition table type. This Linux SD card recovery tool might recognize the data remnant available and hint at the best option for you. If you use an SD card to store files and with smartphones, cameras, or PC, choose Intel.
Step 6: Select Analyze to check the card’s structure for any corrupt or lost partition. This step is essential for the recovery process.
Step 7: If it finds no partition, TestDisk will suggest you carry out a quick search. Usually, this option is effective enough to help you Undelete a lost partition. Press Enter to proceed.
Step 8: TestDisk will ensure every located partition is displayed. With SD cards, there’s usually only one. Check the provided option to change the partition type and make it bootable. Afterward, press Enter to recover your lost partition from the SD card in Linux.
Step 9: If TestDisk didn’t find any partition, you’d have to click the Deeper Search option. When TestDisk completes the search and you find your partition, select Write to proceed.
Step 10: That step will write the partition table to the SD card, undeleting the lost partition. TestDisk will then suggest you reboot your PC to effect the new changes. Navigate to the exit button and exit the app.
That’s all it takes. Hopefully, after your PC reboot, your SD card should be accessible with all lost data recovered for you.
Method 4: Recover Deleted or Lost Photos From an SD Card with PhotoRec for Linux
If you’re looking to recover photos from your SD card on Linux, then PhotoRec is the best option for you. If Linux can view your SD card as a mass storage device but can’t detect the file system, PhotoRec will help recover its files. Unlike TestDisk, this data recovery app doesn’t try to write to the device or fix it; it simply salvages the lost file to give you access. Follow the steps below to use PhotoRec for your Linux SD card recovery.
Step 1: If you don’t have it installed, you can download it from the Ubuntu repository with the command:
sudo apt-get install photorec
You often don’t have to install it because it comes in the TestDisk bundle.
Step 2: Run the app by entering photorec into a terminal after installation. And pressing Enter.
Step 3: Like with TestDisk, you have to choose your SD card from the device list provided by PhotoRec.
Step 4: Chances are that PhotoRec will detect a partition. However, selecting No partition is best to ensure the app scans the whole disk for lost files.
Step 5: On the app, visit Options and select the Keep corrupted files option. They’ll probably be unusable, but this will allow you to save fragmented test files and images. You can also enable the Low memory mode before exiting the options page.
Step 6: Back in the main menu, choose the types of files you want PhotoRec to recover. Although the name specifies photos, PhotoRec can recover more than image files.
Step 7: To speed up the scanning process for your lost data, disable the types of files you’re not looking to recover.
Step 8: PhotoRec will also ask you to select how you want to scan and the file system of your SD card. Most times, the best option for you is Others.
Step 9: Now, you have to choose a destination folder where PhotoRec can store the files it recovers.
Step 10: PhotoRec will start scanning the card for the files you’re looking for and then report the types of files it is located. Once you find the file you’re looking for, you can stop the process.
Step 11: When the scan ends, PhotoRec will remind you of the number of files it recovered and the folder that saved the recovered photos.
That’s the end of the recovery process. Now, you can exit the app and check out the files recovered by this file recovery tool.
Part 3: Format the SD Card After the Data Recovery on Linux
After you recover your files from the SD card, you can format them to eliminate any viruses or bad sectors. This ensures that you can use the card once again. There are different methods to format the SD Card after data recovery on Linux, and we’ll review them in this section.
Format SD Card in the Terminal
One of the best ways to format an SD card is through the terminal, and of the most effective methods is through Fdisk. Follow the steps below to format your SD card in the Linux terminal using FD.
Step 1: Press Ctrl + Alt + T simultaneously to open the terminal.
Step 2: Now utilize Fdisk on your SD card by entering the command:
sudo fdisk /dev/SDCARD
Ensure you replace SDCARD with the name of the card.
Step 3: Next, type p
and press Enter to view the card’s partition table.
Step 4: Type n
to create a new partition table, and then press p
to make this partition primary, followed by 1
, since you don’t have to create partitions anymore.
Step 5: Now press Enter to accept the default values of the partition’s first and last space. This also allows you to use the available disk space.
Step 6: If Fdisk detects a previous signature of the filesystem, it will ask you whether you want to keep or delete it. Choose to delete as you’re creating a new partition from scratch.
Step 7: Now, press w
to write the new partition to your SD Card and exit Fdisk afterward.
That’s all you have to do; your new partition is in place, but you have to format it before you can use it.
Step 8: You can format as FAT 32, the most common format with portable devices and computers, by entering the command:
sudo mkfs.vfat -F32 -v /dev/sdcl
Format SD Card With Disks
Another way you can format your SD to start using it once again is by using Disks. Disks allow users to manage their storage devices easily. Distributions like Linux Mint and Ubuntu also back it. Formatting your SD card in Linux using Disks is relatively easy; follow the steps below.
Step 1: Find the tools in your apps menu and run them.
Step 2: After launch, choose your SD card from the list provided and then create a new partition by clicking the Plus button provided.
Step 3: Leave the partition size and free some space following the settings provided because you want to use all the available space in your SD card.
Step 4: If you want, you can provide a new name for your SD card. For a full format, click Enable and choose the filesystem you prefer. We suggest FAT if you want full compatibility.
Step 5: Once the formatting process is complete, you can easily mount your SD card. Use Disks by clicking the Play button below the card name.
FAQs
Can a damaged SD card be recovered on Linux?
Yes, there are many tools you can use for Linux SD card recovery. Depending on the cause of data loss and what you’re looking for, the four methods provided in our guide above are the best for recovering files from a damaged SD card.
How to recover deleted photos from an SD card in Ubuntu?
The methods explored above for Ubuntu SD card recovery will help you recover all types of files, including photos, from the SD card.
Is SD card recovery on Linux the same as on Windows?
Not necessarily. Although the process can be pretty similar, the tools used are usually different. One way that the two operating systems differ is that Windows methods are usually GUI-based. On the other hand, Linux recovery methods are usually terminal-based.
Why should I first back up my SD card before performing the recovery?
The simplest way to put it is that when dealing with a faulty storage device, it’s best to first get the available data out of them when possible. Although recovering your data and using your storage device afterward is the goal, you must also prepare for scenarios where the card fails.
Conclusion
As we’ve seen, losing data on an SD card isn’t the end. You can recover data from SD on Linux following the methods shared in this guide. This article has broken down what looked like a complex process into simple steps for you to follow. Linux SD card recovery and making your SD card usable again can be straightforward if you follow the simple steps provided above.
For Windows XP/Vista/7/8/10/11
For macOS X 10.10 or later