lima
lima copied to clipboard
alpine, virtiofs: `/etc/fstab` contains `timezone: Asia/Tokyo`
$ limactl -v
limactl version 0.20.1
$ limactl start --vm-type=vz --mount-type=virtiofs template://alpine
$ limactl shell alpine cat /etc/fstab
# /etc/fstab
#LIMA-START
mount0 /Users/suda virtiofs ro,nofail 0 0
mount1 /tmp/lima virtiofs rw,nofail 0 0
timezone: Asia/Tokyo
#LIMA-END
Seems specific to alpine + virtiofs
This is truly bizarre:
$ limactl shell alpine cat /etc/fstab
# /etc/fstab
#LIMA-START
mount0 /Users/suda virtiofs ro,nofail 0 0
mount1 /tmp/lima virtiofs rw,nofail 0 0
timezone: Asia/Tokyo
#LIMA-END
The only place we use the #LIMA-START marker is in /etc/environment.
There is no code in lima-init that writes to /etc/fstab, and the only place in the boot scripts is 05-lima-mounts, but it is only executed for selinux, and doesn't add these markers.
And as far as I can tell the only place timezone: Asia/Tokyo would be in user-data, and I don't see where that would be copied to /etc/fstab either.
I'll try to repro later.
I'll try to repro later.
Happens to me too:
$ limactl shell alpine cat /etc/fstab
# /etc/fstab
#LIMA-START
mount0 /Users/jan virtiofs ro,nofail 0 0
mount1 /tmp/lima virtiofs rw,nofail 0 0
timezone: America/Vancouver
#LIMA-END
Still don't understand how this is even possible.
I figured it out. My confusion comes from the fact that the Rancher Desktop fork of alpine-lima has a PR Create a mount script instead of editing /etc/fstab #15 that is not in the upstream repo.
This PR replaced the code that edited /etc/fstab and added the #LIMA-* markers with a separate mount script (to support mounting filenames with spaces in them).
I see the responsible code in upstream at https://github.com/lima-vm/alpine-lima/blob/main/lima-init.sh#L48-L68.
And it explains the timezone: line because there was supposed to be a newline after the mounts block, but timezome: appears directly behind it:
mounts:
- [mount0, /Users/jan, virtiofs, "ro,nofail", "0", "0"]
- [mount1, /tmp/lima, virtiofs, "rw,nofail", "0", "0"]
timezone: America/Vancouver
Since the mounts are modified via regular expressions, that just don't match on the timezone: line, it is copied verbatim.
Now the question is if the Rancher Desktop PR is appropriate for the Lima repo, or if we should fix the lima-init.sh script to break the block as soon as a line doesn't start with a -.
I have no idea why the PR never made it into the upstream repo; I guess I should audit the whole diff to see if anything else was dropped accidentally.
The same thing happens with QEMU and 9p:
lima-alpine:~# cat /etc/fstab
# /etc/fstab
#LIMA-START
mount0 /Users/jan 9p ro,trans=virtio,version=9p2000.L,msize=131072,cache=fscache,nofail 0 0
mount1 /tmp/lima 9p rw,trans=virtio,version=9p2000.L,msize=131072,cache=mmap,nofail 0 0
timezone: America/Vancouver
#LIMA-END
It doesn't happen for reverse-sshfs because the user-data template omits the mounts: section:
{{- if or (eq .MountType "9p") (eq .MountType "virtiofs") }}
{{- if .Mounts }}
mounts:
{{- range $m := $.Mounts}}
- [{{$m.Tag}}, {{$m.MountPoint}}, {{$m.Type}}, "{{$m.Options}}", "0", "0"]
{{- end }}
{{- end }}
{{- end }}
The simplest fix would be to insert a blank line before the timezone (because the {{- … } part eats the newline before the template block):
--- pkg/cidata/cidata.TEMPLATE.d/user-data
+++ pkg/cidata/cidata.TEMPLATE.d/user-data
@@ -21,6 +21,7 @@ mounts:
{{- end }}
{{- if .TimeZone }}
+
timezone: {{.TimeZone}}
{{- end }}
the question is if the Rancher Desktop PR is appropriate for the Lima repo
Yes, it is needed to successfully mount directories whose names contain spaces. I'll create a PR.
I believe this is fixed:
$ limactl shell alpine cat /etc/fstab
# /etc/fstab
$ limactl shell alpine cat /etc/timezone
America/Vancouver