You are not logged in.

#1 2020-04-08 14:08:58

blochl
Member
Registered: 2018-08-31
Posts: 77

[Solved-ish] Set time in initramfs

Hi,

In my custom initramfs I need to set system time according to some calculation to be different from the hardware RTC time.
(I need it for a very particular usage scenario, not everyday usage - so *this* is the problem I'm trying to solve, and I'm not trying to solve some other problem with it smile )

In the default initramfs there is no `date` utility.

So my question is: do I have to include the `date` binary with a build hook, or is there some other way to set the system time, with more basic utilities: through sysfs, or something?

The time which I'm trying to set is in a "seconds since epoch" format, so just a single string/integer.

Last edited by blochl (2020-04-08 15:46:29)

Offline

#2 2020-04-08 14:51:52

Ropid
Member
Registered: 2015-03-09
Posts: 1,069

Re: [Solved-ish] Set time in initramfs

The "busybox" binary is (probably?) in your initramfs, and it contains a 'date' command. You can run "busybox --help" to check things out, there might be some other commands you'd like to have and busybox contains a lot of stuff.

You can get to that 'date' that's inside busybox by running "busybox date ...". Check out "busybox date --help" to see what that special 'date' can do.

If you want an actual 'date' command inside your initramfs, instead of adding the date binary, you can also try to find out how to create a link inside /usr/bin named 'date' that points to the busybox binary.

Last edited by Ropid (2020-04-08 14:52:27)

Offline

#3 2020-04-08 14:56:12

loqs
Member
Registered: 2014-03-06
Posts: 18,928

Re: [Solved-ish] Set time in initramfs

mkinitcpio-busybox is not currently built with date support https://bugs.archlinux.org/task/62163.

Offline

#4 2020-04-08 14:58:49

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,462
Website

Re: [Solved-ish] Set time in initramfs

Further, busybox's date does not allow you to set time with a seconds-since-epoch input.  And unless I'm missing something, neither does gnu-coreutil's date.  You can get the current time as seconds since epoch, but not set it.

EDIT: oops, I was missing something, the seconds string needs to be prefaced by an '@' symbol.  And this works with my version of busybox's date as well.  But that's still not included in mkinitcpio's busybox.

Last edited by Trilby (2020-04-08 15:00:13)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2020-04-08 15:47:06

blochl
Member
Registered: 2018-08-31
Posts: 77

Re: [Solved-ish] Set time in initramfs

Thanks for your replies. Eventually I just included `date`, and it works fine.

Offline

Board footer

Powered by FluxBB