You are not logged in.

#1 2015-10-05 06:35:07

lilydjwg
Member
Registered: 2010-06-20
Posts: 56

[SOLVED] How can I get current boot ID?

Well, I can get a list of boot IDs from journalctl --list-boots. But what to do if I want only the current one without reading all the journals?

Last edited by lilydjwg (2015-10-05 08:32:43)

Offline

#2 2015-10-05 06:40:40

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [SOLVED] How can I get current boot ID?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2015-10-05 07:56:19

lilydjwg
Member
Registered: 2010-06-20
Posts: 56

Re: [SOLVED] How can I get current boot ID?

I don't see any mention about boot IDs on that wiki page. Also I've checked some related manpages on journald and systemd but didn't see a light way to get the current boot ID.

Offline

#4 2015-10-05 08:03:06

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [SOLVED] How can I get current boot ID?

lilydjwg wrote:

But what to do if I want only the current one without reading all the journals?

Wiki article wrote:

Show all messages from this boot:
# journalctl -b


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2015-10-05 08:28:16

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED] How can I get current boot ID?

@jasonwryan: that's assuming OP wants to obtain the boot ID only to pass it to -b.

lilydjwg wrote:

Well, I can get a list of boot IDs from journalctl --list-boots. But what to do if I want only the current one without reading all the journals?

This is a little confusing: you know how to get the boot IDs, why would you need to "read all the journals"? If you mean you have a long list of boots to scroll through, use `tail -1` or, for the ID without other fields:

$ journalctl --list-boots | awk 'END {print $2}'

Offline

#6 2015-10-05 08:29:14

lilydjwg
Member
Registered: 2010-06-20
Posts: 56

Re: [SOLVED] How can I get current boot ID?

I mean the boot ID that systemd assgins to each boot, not the logs.

I can get the machine ID by `cat /etc/machine-id`, but I'm curious how to get the boot ID.

Offline

#7 2015-10-05 08:32:14

lilydjwg
Member
Registered: 2010-06-20
Posts: 56

Re: [SOLVED] How can I get current boot ID?

OK, I've got it by reading the sources of journalctl. It's in /proc/sys/kernel/random/boot_id.

Offline

#8 2015-10-05 09:01:07

lilydjwg
Member
Registered: 2010-06-20
Posts: 56

Re: [SOLVED] How can I get current boot ID?

Raynman wrote:

@jasonwryan: that's assuming OP wants to obtain the boot ID only to pass it to -b.
This is a little confusing: you know how to get the boot IDs, why would you need to "read all the journals"? If you mean you have a long list of boots to scroll through, use `tail -1` or, for the ID without other fields:

$ journalctl --list-boots | awk 'END {print $2}'

I presume journalctl will read the journals to find out what boot IDs it has. Anyway, it takes relatively a lot of time to get 128bit data that the system surely stores somewhere. I thought it's done by systemd, but it turns out the kernel generates it at /proc/sys/kernel/random/boot_id, and it's been there at least ten years ago!

I'm not going to pass it to journalctl. I see systemd has used it in private /tmp mount points and I may find a similar use in the future.

Offline

Board footer

Powered by FluxBB