5

I am attempting to get a sub-4gb image to retain its image size on my rpi regardless of the sdcard size. I am looking at using the ubuntu server image built by Ryan Finnie ubuntu-16.04-preinstalled-server-armhf+raspi3.img from the ubuntu wiki

The suggestion in Temporarily disable expand filesystem during first boot by goldilocks of disabling of init=/usr/lib/raspi-config/init_resize.sh from /boot/cmdline.txt works on Ubuntu Mate.

But the server image does not have the init=/usr/lib/raspi-config/init_resize.sh in /boot/cmdline.txt - but first boot expands the image to the max capacity of the card.

Does anyone know where the partition resize is triggered on this ubuntu server image?

sith
  • 223
  • 1
  • 8

2 Answers2

3

The expansion of the partition is done by the growpart module of cloud-init.

Preventing cloud-init from extending the partition size can be done by adding the following lines to a user-data cloud-config YAML file:

growpart:
  mode: false

For the Ubuntu Server 21.04 Raspberry pi images, the lines above should be added to the user-data file on the boot partition.

fskj
  • 146
  • 2
2

cloud-init

The usual raspi-config script that resizes the root filesystem on boot isn't in this Ubuntu image.

The only init-related resize program I could find was /usr/lib/python3/dist-packages/cloudinit/config/cc_resizefs.py. This is apparently part of the Ubuntu cloud-init package, and has a function that will resize the root filesystem on boot.

The cloud-init package has a configuration file in /etc/cloud/cloud.cfg which contains:

# The modules that run in the 'init' stage
cloud_init_modules:
 - migrator
 - ubuntu-init-switch
 - seed_random
 - bootcmd
 - write-files
 - growpart
 - resizefs
 - set_hostname
 - update_hostname
 - update_etc_hosts
 - ca-certs
 - rsyslog
 - users-groups
 - ssh

Notice resizefs? That's probably what's triggering the resize.


Disabling

Removing resizefs from that config file might be sufficient, or you can just disable cloud-init.

The installed version of cloud-init (0.7.7) was the first version to include an easy way to completely disable it:

 This is fix-committed now with systemd.
2 ways to disable cloud-init and stop any bottlenecks it would put in place during boot:
 a.) touch /etc/cloud/cloud-init.disabled
 b.) boot with cloud-init=disabled on kernel command line.
Hydraxan14
  • 1,876
  • 1
  • 13
  • 23