Skip to content

Commit 4481eb7

Browse files
authored
incus: sync size of the default pool on startup (#1415)
* incus: sync size of the default pool on startup Signed-off-by: Abiola Ibrahim <git@abiosoft.com> * chore: incus: reword print output Signed-off-by: Abiola Ibrahim <git@abiosoft.com> --------- Signed-off-by: Abiola Ibrahim <git@abiosoft.com>
1 parent 814d3c2 commit 4481eb7

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

environment/container/incus/incus.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ func (c *incusRuntime) Start(ctx context.Context) error {
156156
})
157157
}
158158

159+
// sync disk size for the default pool
160+
if conf.Disk > 0 {
161+
a.Add(func() error {
162+
// this can fail silently
163+
_ = c.guest.RunQuiet("sudo", "incus", "storage", "set", "default", "size="+config.Disk(conf.Disk).GiB())
164+
return nil
165+
})
166+
}
167+
159168
a.Add(func() error {
160169
// attempt to set remote
161170
if err := c.setRemote(conf.AutoActivate()); err == nil {
@@ -382,7 +391,7 @@ func (c *incusRuntime) recoverDisk(ctx context.Context) error {
382391
log.Println()
383392
log.Println("Running 'incus admin recover' ...")
384393
log.Println()
385-
log.Println(fmt.Sprintf("Found %d storage pool sources:", len(disks)))
394+
log.Println(fmt.Sprintf("Found %d storage pool source(s):", len(disks)))
386395
for _, disk := range disks {
387396
log.Println(" " + poolDisksDir + "/" + disk)
388397
}

environment/vm/lima/yaml.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,33 @@ func newConf(ctx context.Context, conf config.Config) (l limaconfig.Config, err
330330
}
331331
}
332332

333+
/*
334+
provision scripts for disk actions
335+
*/
336+
337+
// ensure all volumes are mounted.
333338
l.Provision = append(l.Provision, limaconfig.Provision{
334339
Mode: limaconfig.ProvisionModeSystem,
335340
Script: "mount -a",
336341
})
337342

338343
// trim mounted drive to recover disk space
344+
// however problematic for incus
339345
if conf.Runtime != incus.Name {
340346
l.Provision = append(l.Provision, limaconfig.Provision{
341347
Mode: limaconfig.ProvisionModeSystem,
342348
Script: `readlink /usr/sbin/fstrim || fstrim -a`,
343349
})
344350
}
345351

352+
// grow partition in case disk size has increased
353+
l.Provision = append(l.Provision, limaconfig.Provision{
354+
Mode: limaconfig.ProvisionModeSystem,
355+
Script: "resize2fs " + diskByLabelPath(config.CurrentProfile().ID) + " || true",
356+
})
357+
358+
/* end */
359+
346360
if len(conf.Mounts) == 0 {
347361
l.Mounts = append(l.Mounts,
348362
limaconfig.Mount{Location: "~", Writable: true},
@@ -443,3 +457,14 @@ func ingressDisabled(disableFlags []string) bool {
443457
}
444458
return false
445459
}
460+
461+
const diskLabelMaxLength = 16 // https://tldp.org/HOWTO/Partition/labels.html
462+
463+
func diskByLabelPath(instanceId string) string {
464+
name := "lima-" + instanceId
465+
if len(name) > diskLabelMaxLength {
466+
name = name[:diskLabelMaxLength]
467+
}
468+
469+
return "/dev/disk/by-label/" + name
470+
}

0 commit comments

Comments
 (0)