Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alpine, virtiofs: /etc/fstab contains timezone: Asia/Tokyo #2235

Closed
AkihiroSuda opened this issue Mar 8, 2024 · 6 comments
Closed

alpine, virtiofs: /etc/fstab contains timezone: Asia/Tokyo #2235

AkihiroSuda opened this issue Mar 8, 2024 · 6 comments
Labels
bug Something isn't working guest/alpine Guest: Alpine

Comments

@AkihiroSuda
Copy link
Member

$ 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

@AkihiroSuda AkihiroSuda added bug Something isn't working guest/alpine Guest: Alpine labels Mar 8, 2024
@jandubois
Copy link
Member

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.

@jandubois
Copy link
Member

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.

@jandubois
Copy link
Member

jandubois commented Mar 8, 2024

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.

@jandubois
Copy link
Member

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

@jandubois
Copy link
Member

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.

@jandubois
Copy link
Member

I believe this is fixed:

$ limactl shell alpine cat /etc/fstab
# /etc/fstab
$ limactl shell alpine cat /etc/timezone
America/Vancouver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working guest/alpine Guest: Alpine
Projects
None yet
Development

No branches or pull requests

2 participants