Skip to content

File /etc/localtime missing #89

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

Closed
afbjorklund opened this issue Oct 16, 2022 · 6 comments · Fixed by #115
Closed

File /etc/localtime missing #89

afbjorklund opened this issue Oct 16, 2022 · 6 comments · Fixed by #115

Comments

@afbjorklund
Copy link
Member

Some runtimes expect /etc/localtime to be present...

Maybe it can be created, to match the output of date ?

Something similar to this workaround:

echo UTC | sudo tee /etc/localtime

@jandubois
Copy link
Member

Some runtimes expect /etc/localtime to be present...

Did you mean /etc/timezone? The content for /etc/localtime for UTC is normally

TZif2UTCTZif2UTC
UTC0

Regular setup:

lima-alpine:~# apk add tzdata
(1/1) Installing tzdata (2022c-r0)
Executing busybox-1.35.0-r17.trigger
OK: 49 MiB in 81 packages
lima-alpine:~# setup-timezone -z UTC
lima-alpine:~# ls -l /etc/localtime
lrwxrwxrwx    1 root     root            17 Oct 17 01:44 /etc/localtime -> /etc/zoneinfo/UTC
lima-alpine:~# cat /etc/localtime
TZif2UTCTZif2UTC
UTC0

But which command needs this; the default for date is UTC anyways, so creating the file with default content makes no difference.

@jandubois
Copy link
Member

I just realized that zoneinfo files are binary files, so we would actually need to copy it from the tzdata package:

lima-alpine:~# hexdump -C /etc/localtime
00000000  54 5a 69 66 32 00 00 00  00 00 00 00 00 00 00 00  |TZif2...........|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 01  00 00 00 04 00 00 00 00  |................|
00000030  00 00 55 54 43 00 54 5a  69 66 32 00 00 00 00 00  |..UTC.TZif2.....|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 01 00 00  |................|
00000060  00 04 00 00 00 00 00 00  55 54 43 00 0a 55 54 43  |........UTC..UTC|
00000070  30 0a                                             |0.|
00000072

@afbjorklund
Copy link
Member Author

afbjorklund commented Oct 17, 2022

Did you mean /etc/timezone? The content for /etc/localtime for UTC is normally

Good catch! I will make sure to adjust the workaround then.... (it was for apptainer)

https://github.com/apptainer/apptainer/blob/v1.1.2/pkg/util/apptainerconf/config.go#L107

In the Fedora VM, it is a symlink: /etc/localtime -> ../usr/share/zoneinfo/Etc/UTC
There is no /etc/timezone, only a /etc/adjtime. zoneinfo was from tzdata-2022a-1.fc36

Your approach with adding tzdata package etc to alpine-lima, seems like the best one.
The symlink is resolved automatically, so the end result is a 114-byte binary /etc/localtime.

lima-alpine-apptainer:~$ apptainer run docker://busybox
INFO:    Using cached SIF image
INFO:    fuse2fs not found, will not be able to mount EXT3 filesystems
Apptainer> ls -l /etc/localtime 
-rw-r--r--    1 nobody   nobody         114 Oct 17 08:24 /etc/localtime
Apptainer> exit
lima-alpine-apptainer:~$ ls -l /etc/localtime 
lrwxrwxrwx    1 root     root            17 Oct 17 08:24 /etc/localtime -> /etc/zoneinfo/UTC

@jandubois
Copy link
Member

Your approach with adding tzdata package etc to alpine-lima, seems like the best one.
The symlink is resolved automatically, so the end result is a 114-byte binary /etc/localtime.

I would not install all of tzdata into the ISO; I would just copy the single UTC file over after including it on the mkimage.

But first I wanted to make sure we are talking about the right thing; and I want a comment explaining why we are doing this.

@afbjorklund
Copy link
Member Author

afbjorklund commented Oct 17, 2022

You don't have to keep tzdata installed, the generated /etc/localtime and /etc/zoneinfo would be fine.

Here is what alpine-conf is actually doing:

+ rm -r //etc/zoneinfo
+ mkdir -p /etc/zoneinfo/
+ cp //usr/share/zoneinfo/UTC /etc/zoneinfo//
+ zonepath=/etc/zoneinfo/UTC
+ rm -f /etc/localtime
+ ln -s /etc/zoneinfo/UTC /etc/localtime

/bin/sh -x /sbin/setup-timezone -z UTC

@jandubois
Copy link
Member

I would not install all of tzdata into the ISO;

I'm not sure why I wrote this, but tools are supposed to treat a missing zoneinfo database the same as if it was configured for UTC. So there wouldn't be a good reason to just copy the UTC data (unless we are dealing with a broken tool).

The whole of tzdata is 3MB, so I think we can just include it completely. Most people don't seem to care about image size anymore (within reason).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants