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?

  • Where are you downloading this image from? Is it this one?
    – Hydraxan14
    Commented Jul 18, 2017 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
    Commented Jul 18, 2017 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
    Commented Jul 19, 2017 at 5: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
    Commented Jul 19, 2017 at 16:09
  • The growpart answer from @fskj should be marked correct.
    – Xalorous
    Commented Apr 9, 2022 at 9:07

2 Answers 2


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:

  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.

  • I would like to add that adding resize_rootfs: false does NOT work. But this does. Thanks! Commented Jun 22, 2021 at 20:22


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
 - 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.


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.
  • thanks for the research Hydraxan14... I will test out the cloud-init=disabled and report back asap.
    – sith
    Commented Jul 21, 2017 at 5: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
    Commented Jul 21, 2017 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
    Commented Jul 21, 2017 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
    Commented Nov 22, 2021 at 0: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
    Commented Apr 9, 2022 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.