Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4146

Advanced users • cloud-init script to resize partitions / file systems

$
0
0
Hi,

I would like to change the default behavior of the pi ubuntu image (23.10) to not resize the partition/filesystem to take up my entire SD card with the root partition. After a bunch of browsing around, I discovered that you can stop the auto-expansion of the root partition from happening via the cloud-init script 'user-data' on the boot partition that you can access directly after writing the ubuntu pi image to the SD Card.

Simply add:

Code:

growpart:  mode: off 
Now you can manually edit the partition table for the root partition to make it the size you want and add additional ones

Having no experience using cloud-init and hoping to avoid it, I am wondering if anyone has a recipe for cloud-init to:
- set the root partition size and grow the file system to X size
- create additional partitions/filesystems (asking too much but setting the remainder of the disk into lvm would be sweet)

What I have done to nearly accomplish that but is neither elegant and abstracted properly to cloud-init nor fully automated is to run sgdisk and make a new partition 32G into the disk and then run growpart manually after cloud-init runs. Growpart takes up all the space from its starting block to the beginning of the new partition block. Stolen idea from this bright person: https://www.brightbox.com/blog/2020/03/ ... d-server/

So add this to user-data along with turning growpart off above

Code:

bootcmd:  - [cloud-init-per, once, addpartition, sgdisk, /dev/mmcblk0, "-g", "-e", "-n=0:32G:0", -t, "0:8e00"]
and then run growpart & resize2fs

Code:

sudo growpart /dev/mmcblk0 2sudo resize2fs /dev/mmcblk0p2
Note! The bootcmd changes the partition table from MBR to GPT! If I knew how to do the above in fdisk then this wouldn't be necessary but I don't think (?) the pi/ubuntu cares.

Is there someone who knows how to do the above in cloud-init with the built in modules for partitions and file systems? And gets it to run before the raspberrypi growpart happens? I don't really want to spend much more time on this but it would be nice to have a more elegant / community re-usable recipe.

James

Statistics: Posted by chasejam — Tue Feb 27, 2024 3:33 pm



Viewing all articles
Browse latest Browse all 4146

Trending Articles