LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-23-2019, 07:59 AM   #1
jesusangel
LQ Newbie
 
Registered: Nov 2019
Posts: 9

Rep: Reputation: Disabled
Can't write to micro SD card


Hello,

I have a micro SD card which I was using in a Raspberry PI 3. I can read from and write to it, but after remounting the filesystems, the new files disappear.

The card has two partitions, one with a FAT32 filesystem and other one with an ext4 filesystem.

Code:
Disk /dev/sda: 14,9 GiB, 16021192704 bytes, 31291392 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x8f1eafaf

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1         8192   131071   122880   60M  c W95 FAT32 (LBA)
/dev/sda2       131072 31291391 31160320 14,9G 83 Linux
The card is not write protected:


Code:
# hdparm -r /dev/sda

/dev/sda:
 readonly      =  0 (off)
I can mount the filesystems RW and a write operation in the card doesn't return any error:


Code:
/dev/sda1 on /mnt/slot1 type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro)
/dev/sda2 on /mnt/loop type ext4 (rw,relatime,data=ordered)

# file loop/rnd.bin 
loop/rnd.bin: data

# umount /mnt/loop
# mount /dev/sda2 /mnt/loop
# ls -l /mnt/loop/rnd.bin
Can't access to /mnt/loop/rnd.bin. No such file or directory
I have checked both filesystems:

Code:
# dosfsck -w -r -l -a -v -t /dev/sda1
fsck.fat 4.1 (2017-01-24)
Checking we can access the last sector of the filesystem
Boot sector contents:
System ID "mkfs.fat"
Media byte 0xf8 (hard disk)
       512 bytes per logical sector
      8192 bytes per cluster
         1 reserved sector
First FAT starts at byte 512 (sector 1)
         2 FATs, 16 bit entries
     16384 bytes per FAT (= 32 sectors)
Root directory starts at byte 33280 (sector 65)
       512 root directory entries
Data area starts at byte 49664 (sector 97)
      7673 data clusters (62857216 bytes)
63 sectors/track, 255 heads
         0 hidden sectors
    122880 sectors total
Checking file /boot
../..
Checking file /overlays/imx219.dtbo (IMX219~1.DTB)
Checking for bad clusters.
Reclaiming unconnected clusters.
/dev/sda1: 215 files, 3020/7673 clusters

#  fsck.ext4 -fv /dev/sda2
e2fsck 1.43.4 (31-Jan-2017)
Paso 1: Verificando nodos-i, bloques y tamaños
Paso 2: Verificando la estructura de directorios
Paso 3: Revisando la conectividad de directorios
Paso 4: Revisando las cuentas de referencia
Paso 5: Revisando el resumen de información de grupos

      208423 nodos-i utilizados (21.68%, el 961520)
         654 ficheros no contiguos (0.3%)
         399 directorios no contiguos (0.2%)
             número de nodos-i con bloques ind/dind/tind: 0/0/0
             Histograma de las profundidades de «extents»: 188727/231
     2177729 bloques usados (55.91%, el 3895040)
           0 bloques dañados
           1 fichero grande

      165610 ficheros regulares
       23075 directorios
          55 dispositivos de caracteres
          25 dispositivos de bloque
           0 fifos
          64 vínculos
       19649 enlaces simbólicos (19377 vínculos simbólicos rápidos)
           0 zócalos
------------
      208478 ficheros
I tried also to delete the partitions but I couldn't. I couldn't either create new filesystem. The mkfs.ext4 ran without errors, but after mounting the new filesystem, the old files are still there.

What's happening?
Maybe the card is broken?

Kind regards,
 
Old 12-23-2019, 09:56 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,892

Rep: Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317
sometimes there is a switch on the card (or on the adapter?) and you can lock it. Or probably the card is broken.
 
Old 12-23-2019, 10:01 AM   #3
jesusangel
LQ Newbie
 
Registered: Nov 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
Yes, the adapter has a switch on it. But I switched it both on and off and it wasn't any difference. I made a backup and I've ordered a new card just in case the old one is broken.

Quote:
Originally Posted by pan64 View Post
sometimes there is a switch on the card (or on the adapter?) and you can lock it. Or probably the card is broken.

Last edited by jesusangel; 12-23-2019 at 10:03 AM.
 
Old 12-23-2019, 11:13 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,892

Rep: Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317
but what if that adapter switch is broken?
 
Old 12-23-2019, 05:12 PM   #5
jesusangel
LQ Newbie
 
Registered: Nov 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
I have tested the adapter with another micro SD card and it works well.

Quote:
Originally Posted by pan64 View Post
but what if that adapter switch is broken?
 
Old 12-24-2019, 05:25 AM   #6
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,499

Rep: Reputation: Disabled
You need to use sudo to enable root user/system usage.

When you mount a disk at a different mount point/directory, it will hide everything on the disk, as the files are in a different directory.

To create a new file system you need the root user's permissions.
 
Old 12-24-2019, 08:18 AM   #7
jesusangel
LQ Newbie
 
Registered: Nov 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
If you saw the code fragments above, I was working as root all the time. Look for the # in front off all commands. I wasn't getting any non access or permissions errors. All comands ran well, but after unmounting and mounting the filesystem, all the changes made disappear. It looks like the filesystem is readonly, although I can write to it, but all the changes are lost after remounting the filesystem.

I think there is something wrong in this sd card. I read bad sd cards sometimes turn into read only before failing totally. It's weird, because the system doesn't show any error. Now I'm going to try with a new sd card. I'll copy all the data from the bad one to the new one and afterwards I'll try to wipe the old one.

Quote:
Originally Posted by fatmac View Post
You need to use sudo to enable root user/system usage.

When you mount a disk at a different mount point/directory, it will hide everything on the disk, as the files are in a different directory.

To create a new file system you need the root user's permissions.
 
Old 12-24-2019, 09:23 AM   #8
jesusangel
LQ Newbie
 
Registered: Nov 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
Hello,

Definitely, there is something wrong in this SD card. I ran gparted as root and deleted the two partitions in the SD card. Then I applied the operations by clicking on the green check. Gparted showed all the pending operations where ran successfully, but after refreshing the devices, the partitions were still there.

I replaced the SD card with a new one. Fortunately, I had a backup so I didn't have to reinstall the OS from scratch.

Thanks all for your replies.

Kind regards,
 
  


Reply

Tags
readonly, sdcard



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Can Linux mount and write to an exFAT micro SD card? qajaq Linux - Hardware 7 06-20-2017 03:46 PM
LXer: Micro-Application Services Require Micro-Network Services LXer Syndicated Linux News 0 11-30-2016 02:21 AM
[SOLVED] Strange behaviour 2Gb SD then 16Gb micro SD in usb All in 1 micro card reader hdp160 Linux - Hardware 4 08-03-2015 06:06 AM
People who call it M$ or Micro$oft or Micro$loth lowpro2k3 General 48 12-24-2007 12:19 AM
LXer: Imation 4GB Micro Hard Drive: Still Micro on the Outside, More Giga on the Inside LXer Syndicated Linux News 0 12-28-2005 06:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration