[cloud-init] Fix image resizing on Ubuntu Core images#4663
[cloud-init] Fix image resizing on Ubuntu Core images#4663
Conversation
4be8a72 to
509b232
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4663 +/- ##
==========================================
- Coverage 87.64% 87.60% -0.04%
==========================================
Files 254 254
Lines 14157 14165 +8
==========================================
+ Hits 12407 12408 +1
- Misses 1750 1757 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
sharder996
left a comment
There was a problem hiding this comment.
scott@Scotts-MacBook-Pro build-gui % multipass stop core
scott@Scotts-MacBook-Pro build-gui % multipass set local.core.disk=10G
scott@Scotts-MacBook-Pro build-gui % multipass start core
scott@Scotts-MacBook-Pro build-gui % multipass info
Name: core
State: Running
Snapshots: 0
IPv4: 192.168.2.206
Release: Ubuntu Core 24
Image hash: 29d2791cdce3 (Ubuntu Core 24)
CPU(s): 1
Load: 0.77 0.18 0.06
Disk usage: 957.9MiB out of 4.8GiB
Memory usage: 181.6MiB out of 953.2MiB
Mounts: --
scott@Scotts-MacBook-Pro build-gui % multipass exec core -- df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda4 3.0G 442M 2.4G 16% /writable
tmpfs 191M 5.9M 185M 4% /run
tmpfs 477M 0 477M 0% /dev/shm
efivarfs 256K 2.4K 254K 1% /sys/firmware/efi/efivars
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 721M 84M 585M 13% /run/mnt/ubuntu-boot
/dev/sda1 1.2G 433M 749M 37% /boot/efi
/dev/sda3 26M 49K 23M 1% /var/lib/snapd/save
tmpfs 477M 0 477M 0% /mnt
tmpfs 477M 0 477M 0% /media
tmpfs 477M 0 477M 0% /tmp
/dev/sda4 3.0G 442M 2.4G 16% /var/log
tmpfs 477M 0 477M 0% /var/lib/sudo
tmpfs 96M 4.0K 96M 1% /run/user/1000
scott@Scotts-MacBook-Pro build-gui % multipass info core
Name: core
State: Running
Snapshots: 0
IPv4: 192.168.2.206
Release: Ubuntu Core 24
Image hash: 29d2791cdce3 (Ubuntu Core 24)
CPU(s): 1
Load: 0.47 0.16 0.06
Disk usage: 957.9MiB out of 4.8GiB
Memory usage: 173.0MiB out of 953.2MiB
Mounts: --
scott@Scotts-MacBook-Pro build-gui % multipass get local.core.disk
10.0GiB
Best of luck on your debugging journey 😄
509b232 to
4d5f9b3
Compare
|
Now it should work. Apparently resize2fs only runs on the root partition and cannot be changed like growpart. Launching a new core image and resizing will work, although it is not instant, it relies on the script running on boot. |
eb34cf4 to
76a09f3
Compare
|
Still no luck after resizing to 10G: |
|
Did you create a new core VM? The fix only works in instances created with the new version. |
|
To see if it is another issue, create this file in your instance: (with 0755 permissions) |
76a09f3 to
cf5eb65
Compare
|
Turns out Onto the per-boot location and restart or run it manually with Fix works in all |
af249dc to
f7b9cec
Compare
sharder996
left a comment
There was a problem hiding this comment.
This does work properly and resizes the disk on Ubuntu Core images, but I'm unsure whether or not its the right approach.
Here's a couple thoughts I had which drive my reasoning:
- This is only necessary for Ubuntu Core and in all other cases I think it would be better to rely on the tooling that drives
growpart. Having the resize script/function be a part of the VirtualMachine class goes against this. - Proceeding the previous point, I feel like there is a better way or achitecturing this. Here's one idea I had:
- We could have the VM keep track when its disk was resized and it could apply the resize function itself. The daemon wouldn't have to get involved.
I'd love to here what @jimporter thinks, too.
|
On the first point, I would add that there are cases outside of Ubuntu Core where this matters: whenever the user disables cloud init themselves (I tested this on 24.04). In those cases multipass can not resize the images properly either. I am unsure if this responsibility should fall on multipass though. On the second point, I originally implemented it as per your suggestion. I later went back for two reasons: first, the operation, even when needed, takes negligible time on the start operation, and second, it would need an extra field in the persistent json to avoid inconsistencies across daemon restarts. An elegant solution would be to set the boolean to true on initialization, since a single resize is cheap, WDYT? If it is the best option, we can go for said implementation, having to run that small script either way does feel like there should be a better option, but the auto-disable of cloud-init does limit possible solutions. |
I agree with @sharder996 that this seems like an architecturally-cleaner solution, and would make it easier to support a wider variety of guest images one day. However, I haven't thought this through far enough to have a clear idea of what exactly that other architecture would look like; for example, how do we tell the VM to do that, and does it work with custom images? To help answer this question, here's a thought experiment: are there any other things that a user could change that require the guest to run some script to update things? Maybe changing the bridge subnet? (We might want to do this if the host OS's network configuration changes and we end up having a conflict, e.g. as in #3147.) If changing the bridge subnet, we might need for the guest OS to handle this itself, or maybe this isn't even a problem. I haven't started work on a fix for #3147, so I'm not sure yet. Ultimately, my decision would come down to a couple things. First, whether there's a clear example of some change-synchronization action like this that needs to be done in either the host or the guest. If there's no example like that, then whether one or the other option is significantly simpler to implement. As much as clean architecture is important for making future changes easier, it's even more important not to overcomplicate an architecture for hypothetical changes we can't even clearly define. I know none of that is really a definite answer one way or the other on this PR though. Would this be a useful topic for us to discuss at one of the team meetings? |
I put it in the discussion list. |
|
I have applied the change you suggested Scott. It still does not resolve the daemon vs vm encapsulation. The daemon seems to still be involved, since when starting a VM all functions are called from the daemon (like wait_for_cloud_init). We can discuss this further if you would prefer a different approach. |
|
I chanced upon the cloud-init while looking at other stuff. Did you try adding |
|
Yes, that was one of the first solutions ( |
97f311b to
ef7c8a5
Compare
|
The new approach has been implemented. Tagging @amylily1011 for discussion about the returned message to the user to prompt them to take action (run |
f4f19d0 to
333ea22
Compare
jimporter
left a comment
There was a problem hiding this comment.
This looks good to me, except for a minor naming comment I have about the new exception.
| } | ||
| }; | ||
|
|
||
| class ResizingUbuntuCoreInstance : public SettingsException |
There was a problem hiding this comment.
At first glance, this name sounds like it's describing a successful resize operation that's in-progress. Since there might be other cases like this in the future (the user changes some setting, and it only partially succeeds), how about naming it something like this?
| class ResizingUbuntuCoreInstance : public SettingsException | |
| class SettingsChangeWarning : public SettingsException |
Or any other variation on this, like SettingsChangePartialSuccess.
There was a problem hiding this comment.
Agreed, SettingsChangePartialSuccess is perfect I think
|
Additional context: Another possible approach is to have the daemon write on the VMDescription whether the image is core or not from the query, instead of depending on |
333ea22 to
b3ca7e4
Compare
|
@tobe2098 @jimporter What would be the best way for me to check what are the current messages right now and the current outputs? Are there any edge cases that I should look into or think about? |
|
When successfully setting a property we do not have an output. In the case the user resizes an Ubuntu Core image the message is: |
|
@tobe2098 can multipass determine the device path and partition number at runtime (and substitute them in )?
Optional implementation:
An alternative option, where their can be a repeat resize, we might want to show the output as below: ( I don't think this is necessary, but I want to point out that this can be the case.)
If device path can't be determined, add: ( to the bottom)
|
|
Multipass could determine the partition number, but the partition is predictable ( The repeat resizes is not something we keep track of. The resize either fails completely (other error message) or succeeds partially (message above). WDYT? On the resize2fs output, did you mean that multipass should output an additional message after running it? |
|
@tobe2098 Brilliant! We can disregard the repeatable one. As for the |
|
Getting output after running a shell command within multipass is outside the scope of what we are doing unless I am mistaken. Running commands within |
|
My understanding is that multipass can't detect the |
|
After some discussion, and due to limitations of how we handle RPC status messaging (set failed is required for message printing), this is the current output message: |
b3ca7e4 to
eb4bcf9
Compare
Description
ubuntu-datapartition receives the increased disk size, which is where the home directory sits and the last partition in the partition table by sector.Related Issue(s)
Closes #3229
Testing
Unit tests
Manual testing steps:
multipass launch -n a core:core22multipass stop amultipass set local.a.disk=7Gmultipass exec a -- sudo fdisk -l /dev/sdaIn the branch
mainthere should be an error message and the data partition (/dev/sda5 or ubuntu-data) should not have been extended. This PR fixes the issue, where the error should not be present and the data partition of the core snap should be adequately increased.Checklist
MULTI-2227