slashbeast / better-initramfs

Small and reliable initramfs solution supporting (remote) rescue shell, lvm, dmcrypt luks, software raid, tuxonice, uswsusp and more.
BSD 3-Clause "New" or "Revised" License
318 stars 54 forks source link

Add support for DHCP configuration #46

Closed mgarstecki closed 6 years ago

mgarstecki commented 6 years ago

Hello,

It would be nice if the binitnet* network configuration supported DHCP configuration as an alternative to a static address.

I have a headless server configured with a static DHCP config, but currently I have to set the IP statically in better-initramfs to get the SSH console (for LUKS-unlocking).

Seems like busybox already has a built-in dhcp client, and a script (https://git.busybox.net/busybox/plain/examples/udhcp/simple.script) to react to events + some functions.sh code could do it.

Willing to contribute that, if you're interested in pulling it in.

slashbeast commented 6 years ago

That's pretty awesome feature. I will do it. I already did a major rework on devel branch, and I am about to release new version since january, so I will add this feature prior to doing so. Will ping you in this issue once I do it.

mgarstecki commented 6 years ago

Thanks, looking forward to that :)

slashbeast commented 6 years ago

It is done on devel branch. Would you be so kind and test it?

FWIW devel branch is far ahead, and uses new sysroot, so I would highly recommend you building it in fresh checkout, or after wiping sourceroot/ from local changes (binaries).

Tested it inside qemu with qemu-system-x86_64 -machine accel=kvm -curses -netdev 'tap,id=if0,helper=/usr/libexec/qemu-bridge-helper --br=br-virt0' -device virtio-net,netdev=if0,mac=de:b2:b8:bf:03:f1,romfile= -kernel /boot/bzImage-4.16.8 -initrd output/initramfs.cpio.gz -append 'binit_net_if=eth0 binit_net_addr=dhcp rescueshell'

>>> better-initramfs devel-9fa9856-2018-05-13. Linux kernel 4.16.8.

>>> Mounting /proc...
>>> Mounting /sys...
>>> Create all the symlinks to /bin/busybox.
>>> Mounting /dev (devtmpfs)...
>>> Bringing up eth0 interface ...
>>> Using DHCP on eth0 ...
udhcpc: started, v1.27.2
udhcpc: sending discover
udhcpc: sending select for 172.30.0.100
udhcpc: lease of 172.30.0.100 obtained, lease time 86400
>>> Setting 172.30.0.100/24 on eth0 ...
>>> Setting default routing via '172.30.0.1' ...
>>> Populating /dev/disk/by-{uuid,label} ...
>>> Rescue Shell (busybox's /bin/sh)
>>> To reboot, press 'control-alt-delete'.
>>> If you wish resume booting process, run 'resume-boot'.
rescueshell / #

The support is limited to setting the address and gateway, I am not sure if it's viable to add anything else, like hostname, name servers etc. Let me know.

mgarstecki commented 6 years ago

Thank you for your work :) It will be my pleasure to test it, I'll do it this week-end.

mgarstecki commented 6 years ago

Just tested it, it works perfectly for me.

I don't think adding hostname/DNS etc. support would be that useful, or someone would have already requested it for the static configuration mode. I certainly don't see a need for my use case.

Thank you again for your work !