Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Enable remote access in initramfs
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  
Author Message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3626
Location: Rasi, Finland

PostPosted: Tue Mar 30, 2021 7:57 pm    Post subject: Enable remote access in initramfs Reply with quote

As some of you know I've been in custom initramfs frenzy lately.
Now I'm planning one for my server. It's mostly headless. Meaning I don't usually have any monitor attached to it.

So if an error occurs while on initramfs phase I have set an emergency shell to be spawned. But before that I'd like to start some simple remote login daemon. busybox has telnet, but I'd like avoid it. Then there's tinysshd and dropbear.

I'm now gathering opinions and ideas on how to implement it. Anyone of you have experience on setting such thing up?
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
erm67
l33t
l33t


Joined: 01 Nov 2005
Posts: 653
Location: EU

PostPosted: Tue Mar 30, 2021 9:19 pm    Post subject: Reply with quote

It would be nice to have something like ead from openwrt in the initrd:
https://openwrt.org/docs/guide-user/troubleshooting/ead
https://git.openwrt.org/?p=openwrt/openwrt.git;a=tree;f=package/network/services/ead
_________________
Ok boomer
True ignorance is not the absence of knowledge, but the refusal to acquire it.
Ab esse ad posse valet, a posse ad esse non valet consequentia

My fediverse account: @erm67@erm67.dynu.net
Back to top
View user's profile Send private message
sdauth
l33t
l33t


Joined: 19 Sep 2018
Posts: 636
Location: Ásgarðr

PostPosted: Tue Mar 30, 2021 9:40 pm    Post subject: Reply with quote

I was trying to achieve the same thing (with LUKS unlocking in initramfs via dropbear) a few months ago, see https://forums.gentoo.org/viewtopic-p-8532466-highlight-.html
I say "was trying" because SlashBeast's initramfs (https://github.com/slashbeast/better-initramfs/tree/devel ) is just so good that I gave up trying to cook my own. I have been using it since then, with little modification. (added kexec and a little script to be able to kexec the kernel with new option if needed) Rock solid.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3343

PostPosted: Tue Mar 30, 2021 11:33 pm    Post subject: Reply with quote

Quote:
I'm now gathering opinions and ideas on how to implement it. Anyone of you have experience on setting such thing up?
Dunno. Maybe _just_ do it? :lol:
I went the lazy, tried and true way and simply dropped full blown openssh in there, along with glibc, and a bunch of other tools that allow me to install a brand new system starting with a piece of nothing, as long as the network connection comes up.
Handy thing. Did a few hundred automated installations already, and I'm going to bump that number by another ~300 very soon.

Some tricks used:
* Kernel boot command line is a great way to configure the init script. If you use key=value format, kernel will even convert those tokens to directly accessible variables. You can use it configure network, insert a public key for ssh login.
* Sshd generates its keys during startup. This requires quite a bit of entropy, which you don't have yet, since you're just booting up. Rumor says that you can write something to /dev/random or /dev/urandom to increase the entropy available, but that trick never worked for me. Haveged didn't work for me either. Flooding the default GW with 500 pings over a few seconds did. As a bonus, you're updating gw's ARP table, which is good in some corner cases. This will probably apply to dropbear too
* Give the whole thing some distinct name. It will help you notice some types of failures early, since it's a part of the standard prompt (and can be easily queried by applications, should you wish to run destructive commands unsupervised)
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3626
Location: Rasi, Finland

PostPosted: Wed Mar 31, 2021 8:39 am    Post subject: Reply with quote

szatox wrote:
* Kernel boot command line is a great way to configure the init script. If you use key=value format, kernel will even convert those tokens to directly accessible variables. You can use it configure network, insert a public key for ssh login.
Guess who just wrote a short parser for /proc/cmdline? Anyways. So kernel actually exports those variables to the environment? Nice!

szatox wrote:
* Sshd generates its keys during startup. This requires quite a bit of entropy, which you don't have yet, since you're just booting up. Rumor says that you can write something to /dev/random or /dev/urandom to increase the entropy available, but that trick never worked for me. Haveged didn't work for me either. Flooding the default GW with 500 pings over a few seconds did. As a bonus, you're updating gw's ARP table, which is good in some corner cases. This will probably apply to dropbear too
Yeah. I need to come up something which generates entropy...

Thanks for the tips!
As for the laziness... I'm too. I'm not gonna make a seperate environment for musl libc and friends just to build slightly smaller initramfs. In fact I think it might be safer to take the parts of a currenly running system, which works. Basically the initramfs then becomes a subset of the running system. ;)
Currently if I seek for faster boot times I'd need to look at the kernel. That's what's bloated if any. ;P
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2121

PostPosted: Wed Mar 31, 2021 11:09 am    Post subject: Reply with quote

Zucca wrote:
...Yeah. I need to come up something which generates entropy...

I recently noticed my kernel config omitted CONFIG_CRYPTO_JITTERENTROPY - not sure if it's a new one, but it's another source.
I decided to trust my cpu's hardware random number generator. Plenty of entropy to add to the pool. If GCHQ or the NSA wish to invade my machine, I'm sure they're already listening. (Hi Cheltenham!)
_________________
Greybeard
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3343

PostPosted: Fri Apr 02, 2021 11:29 am    Post subject: Reply with quote

Zucca wrote:
szatox wrote:
* Kernel boot command line is a great way to configure the init script. If you use key=value format, kernel will even convert those tokens to directly accessible variables. You can use it configure network, insert a public key for ssh login.
Guess who just wrote a short parser for /proc/cmdline? Anyways. So kernel actually exports those variables to the environment? Nice!

Why, me, of course. Just a few years ago :lol:
And then I couldn't make it work the same way somewhere else.
And then I realized it didn't work in the first script either... And yet I could access all the variables I required.....
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3626
Location: Rasi, Finland

PostPosted: Fri Apr 02, 2021 12:29 pm    Post subject: Reply with quote

I wonder if you just set something on the kernel command line without "="... Then does kernel set said variable on the environment but with null/empty value. I guess I'll test it out soon and report back.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9768
Location: almost Mile High in the USA

PostPosted: Fri Apr 02, 2021 2:28 pm    Post subject: Reply with quote

As far as I can tell, anything typed in the grub command line is copied straight into cmdline. Whether your initramfs deals with that is the question.

I end up going old school and parsing the cmdline manually and having a
Code:
linux root=/dev/sda1 wtfbbqrescuemode init=/bin/bash

detects in the initramfs and can be acted upon.
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum