Format SD card on V4k for media

Let me move this to a new Thread already for you

Done, here we go

@fzinken thank you.

OK, folks. I did a lot of poking around the net to discover the ‘best’ way to format flash media a couple of years back. I suspect it’s an area where the recommendations in the earlier days of SD cards are no longer valid because their controllers have got smarter.

The idea is, flash memory can only be written to a blank (erased) recording unit (RU) and recording units can only be erased in batches (allocation units - AU). At the logical beginning of a partition you get the FAT which is being written a lot. You want to keep the FAT inside a minimum number of AUs so that only a few logical AUs are being thrashed. When it’s time to erase, the controller swaps in a blank physical AU to that logical position at the start of the partition and copies stuff into it so there are some blank RUs to go at for new/changed data.

Ah, but ext4 doesn’t have a FAT, you say. But it does, by default, put the journal at the start of the partition, so a similar argument applies.

Bottom line: AU alignment seems like a good thing to do to reduce card wear.

The actual size of an AU is a bit of a mystery. It can be read from the reserved part of the SD card but only in a SD card slot, not from a USB card reader. It depends on the size of the card and whether it’s in UHS mode. It is allowed to be up to 64MiB per the SDXC spec.

I used the SDformatter official software and a USB card reader to format 32G, 64G and 128G cards and they start the partition at 4MiB, 16MiB and 16MiB respectively (FAT32, exFAT and exFAT). The SDXC cards are Samsung EVOs. Maybe other makers are different, but until better info emerges, that’s my recommendation: 4MiB offset for SDHC, 16MiB for SDXC.


@grahamh I tested your second command out of curiosity, but the result is rather strange. I used hardcoded values since I use a 64GB card:

parted -s /dev/mmcblk1 mklabel msdos mkpart primary fat32 16MiB 256MiB \
		&& parted /dev/mmcblk1 set 1 lba on \
		&& parted -s /dev/mmcblk1 -- mkpart primary ext4 256MiB -1s

results in:

$ lsblk -blo NAME,SIZE |grep mmcblk1
mmcblk1      63864569856
mmcblk1p1      251658240
mmcblk1p2    63596134400

This seems strange to me, because mmcblk1p2 should be 63847792640 which would be exactly 16MiB smaller than the entire storage, like it was with the card formatted by the manufacturer:

mmcblk1      63864569856
mmcblk1p1    63847792640

So, it seems that your previous command is the one which actually starts the partition after 16MiB:

parted -s /dev/mmcblk1 mklabel msdos -- mkpart primary ext4 16MiB -1s

Yes, that’s a quote from my script osmc-restore designed to prepare a bootable SD card for use with an RPi or for re-imaging a Vero4k. I just quoted it to show the different offsets I use, based on card size.

I see, thanks for the info.