Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Mar 2020 00:00:29 +0100
From:      Polytropon <freebsd@edvax.de>
To:        freebsd@dreamchaser.org
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: SD card formatting
Message-ID:  <20200316000029.a6ba47c9.freebsd@edvax.de>
In-Reply-To: <b7070f0e-a387-9c7e-945f-ab708f9f5a76@dreamchaser.org>
References:  <b7070f0e-a387-9c7e-945f-ab708f9f5a76@dreamchaser.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 15 Mar 2020 15:39:33 -0600, Gary Aitken wrote:
> 11.3-RELEASE-p6 GENERIC  amd64
> 
> I'm having trouble reading SD cards formatted in my camera (Olympus EM1-MkII)
> or on a Win 7 system.

What filesystem is in use? For cards, it's typically FAT.



> When attempting to mount, I get the following:
> 
> $ mount -t msdosfs /dev/da0s1 /mnt/memstick
> mount_msdosfs: /dev/da0s1: Invalid argument
> $ mount -t ntfs /dev/da0s1 /mnt/memstick
> mount: /dev/da0s1: Operation not supported by device
> 
> Cards used without formatting *usually* seem to work.

So those are preformatted (sometimes sold this way, sometimes
initialized when first used in a camera).



> If I look at the cards which don't mount using gpart, I see:
> 
> Card formatted in camera:
> $ gpart show -p /dev/da0
> =>       63  120944577    da0  MBR  (58G)
>           63      32705         - free -  (16M)
>        32768  120911872  da0s1  ntfs  [active]  (58G)
                                  ^^^^

It seems that the card has been accidentally formatted with NTFS.
In most cases, cameras cannot use that. If you want to mount it
on FreeBSD, use ntfs-3g.



> $ gpart show -r /dev/da0
> =>       63  120944577  da0  MBR  (58G)
>           63      32705       - free -  (16M)
>        32768  120911872    1  7  [active]  (58G)
> 
> If I look at cards that I know I can mount I see the following:
> 
> $ gpart show -p da0
> =>      63  30375873    da0  MBR  (14G)
>          63      8129         - free -  (4.0M)
>        8192  15118336  da0s1  fat32lba  (7.2G)
                                ^^^^^^^^
Correct.



>    15126528  15249408         - free -  (7.3G)
> $ gpart show -r /dev/da0
> =>      63  30375873  da0  MBR  (14G)
>          63      8129       - free -  (4.0M)
>        8192  15118336    1  12  (7.2G)
>    15126528  15249408       - free -  (7.3G)
> 
> or:
> 
> $ gpart show -p /dev/da0
> =>       1  15633407    da0  MBR  (7.5G)
>           1        31         - free -  (16K)
>          32  15633376  da0s1  fat32  (7.5G)
                                ^^^^^
Correct as well.



> $ gpart show -r /dev/da0
> =>       1  15633407  da0  MBR  (7.5G)
>           1        31       - free -  (16K)
>          32  15633376    1  11  (7.5G)
> 
> I tried reformatting as follows:
> 
> # gpart delete -i 1 da0
> da0s1 deleted
> # gpart add -i 1 -a 4M -t "\!11" da0
> da0s1 added
> # gpart show -r da0
> =>       63  120944577  da0  MBR  (58G)
>           63       8129       - free -  (4.0M)
>         8192  120930304    1  11  (58G)
>    120938496       6144       - free -  (3.0M)
> # newfs_msdos -F 32 /dev/da0s1
> /dev/da0s1: 120900736 sectors in 1889074 FAT32 clusters (32768 bytes/cluster)
> BytesPerSec=512 SecPerClust=64 ResSectors=32 FATs=2 Media=0xf0
> SecPerTrack=63 Heads=255 HiddenSecs=0 HugeSectors=120930304
> FATsecs=14759 RootCluster=2 FSInfo=1 Backup=2
> 
> If I put this card in the camera, I get an error ("Card Error")

Personally, I tend to leave the formatting to the camera which
I want to use the card in; the camera "knows best" what it can
uderstand. :-)

There is a simple reason: Several variants of FAT exist, and
some cameras often only support one out of that bag. If you
guess (and use) the wrong one, the camera will report an
error. So, as I suggested, let the camera do the right thing.



> If I again format the card in the camera, I can't mount it.

Have you checked _how_ the camera formats it? Check with
gpart (or fdisk, it still works!). There's also the following
totally unelegant way:

	# file -r - < /dev/da0

and / or

	# file -r - < /dev/da0s1

You should see a FAT summary.



> I need to reformat these cards so I can use them in the camera and on
> freebsd, and apparently neither the camera nor win7 does that, so...
> What's the right way to lay out, format, and create a file system on an
> SD card so it is usable by cameras and windoze?

Typically using the _camera_ to do this job is the right thing.
It's often nice to have the card in "mint condition" (i. e.,
nothing on it, no partitions, no filesystems). Using dd to
overwrite the first MB should be enough. On a "Windows" PC,
the card should then correctly be recognized as FAT. And on
FreeBSD, you can easily mount it with the -t msdos type.
Just make sure that you use /dev/da0 or /dev/da0s1 (some
cameras are tricky and initialize the card as /dev/da0
instead of /dev/da0s1, I never understood why).

In my /etc/fstab, I have the following entry for SD cards:

	/dev/da0s1  /media/sd  msdosfs  rw,noauto,noatime,-m=644,-M=755  0  0

So "mount /media/sd" does what you'd expect. :-)




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200316000029.a6ba47c9.freebsd>