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
  • 7
  • Where are you downloading this image from? Is it this one? – Hydraxan14 Jul 18 '17 at 22:50
  • That was latest official release, although it's for the rpi2. The Ubuntu wiki mentions an unofficial rpi3 port. Are you using that one? – Hydraxan14 Jul 18 '17 at 23:25
  • @Hydraxan14 Yes, that is the one I am using as unfortunately the official one doesnt boot up on rpi 3 yet. I have updated the question to reflect this now. – sith Jul 19 '17 at 05:55
  • /usr/lib/python3/dist-packages/cloudinit/config/cc_resizefs.py looks suspect. Now I just gotta figure out how it's getting called... – Hydraxan14 Jul 19 '17 at 16:09
  • The growpart answer from @fskj should be marked correct. – Xalorous Apr 09 '22 at 09:07
  • @xalorous - I moved on to dietpi for a compact <2G and zippy experience. Now I no longer need to have a small OS footprint so I am on stock raspbian and on RPI4-4G its not much different from dietpi. But based on your recommendation I will accept fskj answer - without testing/verifying though ;) – sith Apr 10 '22 at 10:29

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,836
  • 1
  • 11
  • 23
  • thanks for the research Hydraxan14... I will test out the cloud-init=disabled and report back asap. – sith Jul 21 '17 at 05:55
  • Strangely, after booting with cloud-init=disabled in the cmdline.txt I am unable to login with username "ubuntu", password "ubuntu" - here is the comdline.txt "net.ifnames=0 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline cloud-init=disabled rootwait" – sith Jul 21 '17 at 12:10
  • I think one of cloud-init's jobs is to set up a temporary 'ubuntu' user. So maybe completely disabling it isn't the best idea after all... – Hydraxan14 Jul 21 '17 at 13:53
  • @sith: yes, cloud-init creates the ubuntu user. If you want to just disable the partition resize, you can either comment the - resizefs line, or do as @fsjk suggested in his answer – MestreLion Nov 22 '21 at 00:32
  • growpart needs to be stopped. If the partition does not grow, the resizefs has nothing to do. Alternatively there would be a basic way to inject custom parameters for growpart. SO instead of expanding to the full size, I could force it to expand to x GB or y% instead. My understanding is that cloud-init can be used to do this, on systems installed from iso or kickstart style install. Just parameterize the desired final size and pop the customized file into the cloud-init config as teh deployment is started. But this is RPi deploying over MicroSD using a static image. – Xalorous Apr 09 '22 at 09:05