# microSD card "partition not aligned" warning



## Ignacio (Mar 28, 2021)

I have 2 identical arm devices running FreeBSD 11.4 from a 64 GB microSD card that is mounted read-only most of the time, whenever I mount it read-write and then back to read-only with these commands: 

```
mount -u -w /
mount -u -r /
```
It will take between 10 and 40 seconds to mount it read-only again, freezing disk access during that time, and in dmesg it appears these messages:

```
Mar 27 07:56:00 bl12-247-99 kernel: GEOM_PART: partition 1 on (diskid/DISK-E89ADB97, MBR) is not aligned on 4194304 bytes
Mar 27 07:56:00 bl12-247-99 kernel: GEOM_PART: partition 2 on (diskid/DISK-E89ADB97, MBR) is not aligned on 4194304 bytes
Mar 27 07:56:00 bl12-247-99 kernel: GEOM_PART: partition 1 on (ufsid/5e37468114d819f1, BSD) is not aligned on 4194304 bytes
Mar 27 07:56:00 bl12-247-99 kernel: GEOM_PART: partition 1 on (diskid/DISK-E89ADB97s2, BSD) is not aligned on 4194304 bytes
```
The partitions of both cards look like this:

```
# gpart show mmcsd0
=>       63  124735425  mmcsd0  MBR  (59G)
         63       2016          - free -  (1.0M)
       2079      65520       1  !12  [active]  (32M)
      67599       1009          - free -  (505K)
      68608  121533440       2  freebsd  (58G)
  121602048    3133440          - free -  (1.5G)
```
Is this a driver related problem? or maybe I should partition the cards in a different way to keep partitions aligned somewhat?


----------



## SirDice (Mar 28, 2021)

2079 and 68608 is not a 4K boundary. How did you create these slices?


----------



## Ignacio (Mar 28, 2021)

I made a custom image with crochet, then copied it with dd to the microSD card  and in the first boot it made a growfs to use all the space available, maybe there is some crochet config that I overlooked.

Anyway, how can you tell that those numbers are not 4K boundaries? I understand that they should be a multiple of 8 as we are talking about 512 bytes sectors, isn't it? so 2079 wouldn't do but 2080 would do? but then 68608 is a multiple of 8.


----------



## SirDice (Mar 28, 2021)

Ignacio said:


> I understand that they should be a multiple of 8 as we are talking about 512 bytes sectors, isn't it? so 2079 wouldn't do but 2080 would do?


Correct.


Ignacio said:


> but then 68608 is a multiple of 8.


It's a slice, there are partitions inside that slice. The partitions inside the slice aren't aligned.

If I recall correctly gpart(8) already uses 4K boundaries by default but you can always add `-a 4K` to make sure it does.


----------



## VladiBG (Mar 28, 2021)

What is the sector size of your SD card?


----------



## Ignacio (Mar 29, 2021)

VladiBG said:


> What is the sector size of your SD card?


I understand it's 512 bytes:

```
# diskinfo -c mmcsd0
mmcsd0
        512             # sectorsize
        63864569856     # mediasize in bytes (59G)
        124735488       # mediasize in sectors
        4194304         # stripesize
        0               # stripeoffset
        SDHC SB64G 8.0 SN E89ADB97 MFG 05/2019 by 3 SD  # Disk descr.
        E89ADB97        # Disk ident.
        Yes             # TRIM/UNMAP support
        0               # Rotation rate in RPM

I/O command overhead:
        time to read 10MB block      1.737557 sec       =    0.085 msec/sector
        time to read 20480 sectors   7.293083 sec       =    0.356 msec/sector
        calculated command overhead                     =    0.271 msec/sector
```
Almost 2 seconds to read 10MB looks very poor, it may be caused by the partitions misalignment, isn't it? it could also make the card fail much sooner?


----------



## VladiBG (Mar 29, 2021)

Your SD card is with Stripesize of 4K and your partition is not aligned.
68608 / 4096 = 16.75

The read speed is against the entire card, so it may be worst when you read from not aligned partition.


----------

