Limit partition size before first boot Topic is solved

Having issues with your DietPi installation or found a bug? Post it here.
vonloschz
Posts: 34
Joined: Wed Apr 21, 2021 4:30 pm

Re: Limit partition size before first boot

Post by vonloschz »

here is my successful test over a MicroSD card.

* Disk info

Code: Select all

sudo fdisk -l /dev/sda
Disk /dev/sda: 59.5 GiB, 63864569856 bytes, 124735488 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: 0xe8af6eb2

# Image

Code: Select all

PImage=DietPi_RPi-ARMv6-Buster.img
sudo dd if=${PImage} of=/dev/sda bs=4M conv=fsync
sudo sync

# Partitions

Code: Select all

sudo parted -a optimal /dev/sda resizepart 2 67697654s      # 67697654 sector should bring the partition to 32GiB
sudo resize2fs /dev/sda2
sudo fsck.ext4 -fy /dev/sda2

sudo parted -a optimal /dev/sda mkpart primary 67698688s 124735487s

# Validation

Code: Select all

sudo fdisk -l /dev/sda
0 error

Code: Select all

sudo parted /dev/sda align-check opt
Partition number? 1
1 aligned

sudo parted /dev/sda align-check opt
Partition number? 2
2 aligned

sudo parted /dev/sda align-check opt
Partition number? 3
3 aligned
vonloschz
Posts: 34
Joined: Wed Apr 21, 2021 4:30 pm

Re: Limit partition size before first boot

Post by vonloschz »

Then my tests errors over a SSD disk

* Disk info

Code: Select all

sudo fdisk -l /dev/sdb
Disk /dev/sdb: 232.9 GiB, 250059350016 bytes, 488397168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 4096 bytes / 33553920 bytes                                 <-- is it the problem ???
Disklabel type: dos
Disk identifier: 0x8f4dbd00

# Image

Code: Select all

PImage=DietPi_RPi-ARMv8-Buster.img
sudo dd if=${PImage} of=/dev/sdb bs=4M conv=fsync
sudo sync

# Partitions

Code: Select all

sudo parted -a optimal /dev/sdb resizepart 2 67697654s      # 67697654 sector should bring the partition to 32GiB
sudo resize2fs /dev/sdb2
sudo fsck.ext4 -fy /dev/sdb2

sudo parted -a optimal /dev/sdb mkpart primary 67698688s 488397167s
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel
# Partitions ... also in error..

Code: Select all

sudo parted -a optimal /dev/sdb mkpart primary 68877285s 488397167s
sudo parted -a optimal /dev/sdb mkpart primary 67698688s 488397167s
sudo parted -a optimal /dev/sdb mkpart primary 68942820s 488397167s
sudo parted -a optimal /dev/sdb mkpart primary 68943872s 488397167s
vonloschz
Posts: 34
Joined: Wed Apr 21, 2021 4:30 pm

Re: Limit partition size before first boot

Post by vonloschz »

SSD disk solution ...

Code: Select all

sudo fdisk -l /dev/sdb
...
I/O size (minimum/optimal): 4096 bytes / 33553920 bytes             4096 bytes = parted min alignment
                                                                33553920 bytes = parted opt alignment
...
# Partitions

Code: Select all

sudo parted -a optimal /dev/sdb resizepart 2 68870143s      # 67697654s = 32GiB / 68870143s = 32.6Gib
sudo resize2fs /dev/sdb2
sudo fsck.ext4 -fy /dev/sdb2

sudo parted -a min /dev/sdb mkpart primary 68870144s 488397167s

# Validation

Code: Select all

sudo fdisk -l /dev/sdb
0 error

sudo parted /dev/sdb align-check min
Partition number? 1
1 aligned

sudo parted /dev/sdb align-check min
Partition number? 2
2 aligned

sudo parted /dev/sdb align-check min
Partition number? 3
3 aligned

Sorry about this thread.... learning alone is so boring.
User avatar
Joulinar
Posts: 4504
Joined: Sat Nov 16, 2019 12:49 am

Re: Limit partition size before first boot

Post by Joulinar »

nothing to be sorry about, it's good learning and might be interesting for others as well :)
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
User avatar
MichaIng
Site Admin
Posts: 2917
Joined: Sat Nov 18, 2017 6:21 pm

Re: Limit partition size before first boot

Post by MichaIng »

Interesting actually, thanks for sharing!

Interesting is that for my HDDs minimal and optimal alignment always leads to the same result. Everything is 512 bytes (like on your SD card). Probably my HDDs are too old :D, or it is more common on SSDs.

I wonder how 33553920 bytes is optimal, as it's 32767.5 KiB or 31.99951171875 MiB :?, at least a multiple of 512 bytes. Obviously this is very disk specific.

And then I wonder how the original boot and root partitions are aligned correctly. The first still starts at 4 MiB and the second at 260 MiB (4 + 256), which both is not a multiple of 33553920 bytes :?. Or did I get something wrong?
Post Reply