Format SD card on V4k for media

We’ve discussed this before. The journal is 128MiB. I think it makes sense to make sure that fits into a number of whole erase blocks (AUs), which for an SDXC card are 16MiB. It may be chance, but the only card I’ve ever had fail was not aligned in this way.

Is this only the case for SDXC?
I’ve also seen better efforts at alignment than we do and I’m always open to suggestions.

Key places:


For sizes >32GB, AUs are 16MiB. For smaller cards (not tiny ones, too small for OSMC) AUs are 4MiB. So you could pretend all cards are SDXC and lose space or test for card capacity. These are the parameters I’m using:

# find out how big it is to determine AU size
	DISKSIZE=$(lsblk -blo NAME,SIZE | grep "$MEDIA " | sed 's/^\S*\s*\(\S*\)\s.*/\1/')
	if (( DISKSIZE > 33000000000)); then

	echo Formatting SD card $MEDIA
	parted -s /dev/$MEDIA mklabel msdos mkpart primary fat32 $BLANK $PART1 \
		&& parted /dev/"$MEDIA" set 1 lba on \
		&& parted -s /dev/$MEDIA -- mkpart primary ext4 $PART1 -1s

Some ppl put a small partition at the beginning instead of blank space. I haven’t researched the pros and cons of that.

Sorry to revive this topic, but it was the only useful topic found for “sd card ext4 vero4k” via search engines.

I just put a 64GB microSD card (Sandisk Ultra SDSQUNS-064G-GN3MN 64GB 80MB/s UHS-I Class 10 microSDXC Card) into my Vero4K, but it seems it got mounted as exFAT via FUSE. I’d rather use ext4.

However, I’m quite puzzled why you guys are either creating 2 partitions or start the first one 16MB into the card. Can you please explain why this is necessary? Is this just for alignment thus performance or does it also extend the life of the sd card?

There are no guides how to move the kodi library onto a sd card and/or external usb drive. Or maybe I missed them. I could copy the existing .kodi directory onto the card/drive and mount it over the one in my home directory. But is this the preferred way to do this or are there better options?

You are plugging in an already formatted card, so the Vero is going to use the current formatting. After all, you wouldn’t want it to just blindly reformat your SD card would you?

There is plenty of information here about how to format a drive (or SD Card) to ext4.

As to using it, you could just use fstab to mount the card at /home/osmc/.kodi

Then everything written to .kodi would actually end up on the SD card.

EDIT: if you also want to store media on it, then you should mount it to /home/osmc. If you only want media on it then it’s best to just let it automount and add the source in Kodi.

Ok, I am not an idiot. I’ve been working with Linux/Unix systems for over 20 years. So, yes, I want to do exactly that. Especially since it is a brand new card.

I get that and I know how to format a card to ext4. I don’t even need parted to do it. I was asking why you are creating 2 partitions instead of one. I even stated a few theories.

I know that you just want to help and that your explanation is perfectly valid. But this was also not my question. I know all of these things. What I do not know is, if this is the preferred way to do it or if there are other options that are more the “kodi way” like changing settings in the advanced settings file to write resources somewhere else.

Without being mean or unappreciative I kindly ask you to please look at my previous comment and look at the sentences with a question mark. I need answers to these questions, not some comments directed to the rest of the text I posted.

The card is being mounted as it’s already formatted. You need to reformat it if you want ext4. We are not writing any partition information to the card.

I’m sorry, I try it once again:

@grahamh wrote in this very topic the following command (in this comment) :

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

It creates an ext4 partition that does not start at the beginning of the storage. And I am asking why he’s doing that. So maybe I have to wait for @grahamh to answer that question.

1 Like

That’s why. I personally just reformat anything with one partition. But I don’t use SD cards much. There is a lot of voodoo with SD cards.

I think you are missing the entire discussion here. We might be talking past each other.

That’s not why. He meant that people sometimes also use an extra partition to align the real partition to the AUs. Naturally you don’t have to do that if you create a partition so that it is aligned right away.

I want to know about the background of the reasoning for aligning the filesystem with the AUs on the storage. And if it is a performance thing or a method to extend the lifetime of a card.

As for SD card if you want a fun read…

As for the moving of Kodi files I think you would need to explain exactly what you were wanting to move and why.

That’s far beyond the scope of this forum why people do this. These kinds of questions are probably better asked on a linux forum. He do have several people here knowledgeable on linux, but this type of question is very in-depth.

BTW, I have been using *nix since 1981, and I learn new things almost every day.

4 posts were split to a new topic: Moving Kodi Folder/Database to SD Card

It might have been, if not the owner and a moderator had started a discussion about it in this very topic.

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.