If i put sd card in raspberry pi and want check whether it is working or not. Is there any procedure in raspberry pi to check it. I want to check my either my SD card is broken down or corrupted.
The following are steps I usually use to check any (micro)SD and/or USB memory sticks when I plugged into a USB port on my Linux desktop computer. Since your Rpi presumably runs on a Linux OS, I would not hesitate to share it here with you.
- Before I insert any USB devices and/or storages, I usually run a Linux
dmesgutility to dump out the latest information the utility will report and make a note of the last line. Once the USB storage is inserted into a USB port, I rerun the Linux
dmesgutility to dump out the information about the USB storage. This way, I can be sure the 2nd run produces the information I need in its few last lines that clearly shows which device the USB storage occupies and/or how many partitions the USB storage has.
- Also, I can basically run any
parted /dev/[disk], and/or
gparted /dev/[disk](GUI version) to look for the partition table(s) of the USB storage. Note,
/dev/[disk]is the USB storage disk in question. For a microSD card, it is usually a
/dev/mmcblk0p2(2nd partition), etc., when it is inserted into a microSD slot of the Rpi device. If you use a microSD card reader, then perhaps it will be mounted as
/dev/sdX2(2nd partition), etc., where
Xis the disc and usually is b, c, d, etc.
- Once I have the partition, I can run a
fsck /dev/[partition]to check the condition of the partition. If it reports any corruptions, I usually run it again with -fy switch, i.e.
fsck -fy /dev/[partition], to automatically fix the partition. Remember, this is a destructive act. So, unless you know what you are doing, you may wanna do a backup of the USB storage using a Linux
ddutility prior to issuing such a command. I usually ignore the backup.
- Once the above action is done, I usually repeat the above process again 1x to ensure it completely removes the corrupted files.
- Once I ensure the USB storage gets fixed, I usually mount it, i.e.
mount /dev/[partition] /mnt, etc., to check its integrity. While doing so, I would also look for some generated files (usually with extension .chk) and/or files under the
lost+founddirectory on the root directory of the USB storage. If you mount your USB storage on
/mntdirectory, then you can check
/mnt/lost+foundsubdirectory to see any recovered files there. I usually just delete them to free some spaces occupied by the files, but they may be invaluable to you to peruse and/or save.
That's all there to it and I hope it will help.
Following the answer from @user91822 is a good advice. This all will check if the filesystem is corrupted and will repair it. B.t.w. this will be done on every boot as long as you have set
/boot/cmdline.txt. This is the default setting on Raspbian so mostly just a reboot may fix software errors within the file system.
But this all does not work if the hardware of the SD Card does not work properly anymore. The hardware of a SD Card does not report write errors so the operating system means everything is ok but single bits may not be stored. To check this kind of error you have to do a read after write check on the SD Card with unbuffered I/O. To get more information on this you can look at Detect an SD card that became read-only.