Bug#867677: initramfs-tools: [patch] feature request: provide hook to set host name in InitRAMFS config dynamically

2017-07-11 Thread M. Buecher
And if you remove the extension .sh, then it is also backwards 
compatible with Debian 4.0 "Etch" :)
# Define your network setup for the InitRAMFS via IP variable
#
# Still a kernel ip parameter will override any InitRAMFS config
# setting (see script /usr/share/initramfs-tools/init).
#
# Additional information:
# * https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt
#   In Debian as kernel command via /etc/default/grub
# * The "variable" ${hostname} (case-sensitive) will be replaced on InitRAMFS 
creation
#   with the current host name through the hook `set_hostname_in_network_config`
#   This allows the machine to be registered with its name in DNS.

IP=${hostname}
#!/bin/sh

#
# This InitRAMFS hook provides:
# Simple script to set IP parameter in InitRAMFS config with current
# hostname, instead of manually maintaining InitRAMFS config.

PREREQ=""

prereqs()
{
	echo "${PREREQ}"
}

case "${1}" in
 prereqs)
	prereqs
	exit 0
	;;
esac

. /usr/share/initramfs-tools/hook-functions

#
# Begin real processing
#
[ ! -f "${DESTDIR}/conf/initramfs.conf" ] || sed -i -e "s#\${hostname}#$(hostname)#" "${DESTDIR}/conf/initramfs.conf"
[ ! -f "${DESTDIR}/conf/conf.d/network" ] || sed -i -e "s#\${hostname}#$(hostname)#" "${DESTDIR}/conf/conf.d/network"


Bug#867677: initramfs-tools: [patch] feature request: provide hook to set host name in InitRAMFS config dynamically

2017-07-08 Thread M. Buecher

Updated script, more clean and also processes conf/initramfs.conf#!/bin/sh

#
# This InitRAMFS hook provides:
# Simple script to set IP parameter in InitRAMFS config with current
# hostname, instead of manually maintaining InitRAMFS config.

PREREQ=""

prereqs()
{
	echo "${PREREQ}"
}

case "${1}" in
 prereqs)
	prereqs
	exit 0
	;;
esac

. /usr/share/initramfs-tools/hook-functions

#
# Begin real processing
#
[ ! -f "${DESTDIR}/conf/initramfs.conf" ] || sed -i -e "s#\${hostname}#$(hostname)#" "${DESTDIR}/conf/initramfs.conf"
[ ! -f "${DESTDIR}/conf/conf.d/network" ] || sed -i -e "s#\${hostname}#$(hostname)#" "${DESTDIR}/conf/conf.d/network"


Bug#867677: initramfs-tools: [patch] feature request: provide hook to set host name in InitRAMFS config dynamically

2017-07-08 Thread M. Buecher
Package: initramfs-tools
Version: 0.130
Severity: wishlist
Tags: patch

Dear Maintainer,

when connecting to the InitRAMFS via network (e.g. encrypted root fs), then it 
is
helpful if the machine can be registered by its name in the DNS, making it 
possible
to connect to it via its DNS name. Otherwise you have to look up the assigned 
ip in
the DHCP server log.
Therefore please provide a config and hook that dynamically sets the host name
on InitRAMFS creation.

My current workaround consists of a simple config file and a simple hook script:
/etc/initramfs-tools/conf.d/network
/etc/initramfs-tools/hooks/set_hostname_in_network_config.sh

This workaround is easy to use on any machine without manually editing the host 
name
on installation or whenever it changes. Also avoiding typos of the host name.
Additionally it gives an explicit point where to define your network 
configuration
for InitRAMFS-only (not as a kernel command line).

Would be great if you could consider adding this to the package.

Kind regards
Maddes

-- Package-specific info:
-- initramfs sizes
-rw--- 1 root root 18M Jul  8 13:51 /boot/initrd.img-4.9.0-3-amd64
-- /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-4.9.0-3-amd64 root=/dev/sda1 ro quiet

-- resume
RESUME=UUID=6c849bd6-03b5-4464-9ffe-6a8601f3f23e
-- /proc/filesystems
ext3
ext2
ext4

-- lsmod
Module  Size  Used by
crct10dif_pclmul   16384  0
crc32_pclmul   16384  0
ghash_clmulni_intel16384  0
ppdev  20480  0
pcspkr 16384  0
vmw_balloon20480  0
intel_rapl_perf16384  0
joydev 20480  0
evdev  24576  1
serio_raw  16384  0
sg 32768  0
parport_pc 28672  0
vmwgfx237568  1
battery20480  0
shpchp 36864  0
parport49152  2 parport_pc,ppdev
acpi_cpufreq   20480  0
ttm98304  1 vmwgfx
drm_kms_helper155648  1 vmwgfx
vmw_vmci   69632  1 vmw_balloon
drm   360448  4 vmwgfx,ttm,drm_kms_helper
ac 16384  0
button 16384  0
ip_tables  24576  0
x_tables   36864  1 ip_tables
autofs440960  2
ext4  585728  1
crc16  16384  1 ext4
jbd2  106496  1 ext4
crc32c_generic 16384  0
fscrypto   28672  1 ext4
ecb16384  0
mbcache16384  2 ext4
hid_generic16384  0
usbhid 53248  0
hid   122880  2 hid_generic,usbhid
sr_mod 24576  0
cdrom  61440  1 sr_mod
sd_mod 45056  3
ata_generic16384  0
crc32c_intel   24576  2
aesni_intel   167936  1
aes_x86_64 20480  1 aesni_intel
glue_helper16384  1 aesni_intel
lrw16384  1 aesni_intel
gf128mul   16384  1 lrw
ablk_helper16384  1 aesni_intel
cryptd 24576  3 ablk_helper,ghash_clmulni_intel,aesni_intel
psmouse   135168  0
xhci_pci   16384  0
xhci_hcd  188416  1 xhci_pci
usbcore   249856  3 usbhid,xhci_pci,xhci_hcd
usb_common 16384  1 usbcore
vmxnet357344  0
vmw_pvscsi 24576  2
ahci   36864  0
libahci32768  1 ahci
i2c_piix4  24576  0
ata_piix   36864  0
libata249856  4 ahci,ata_piix,libahci,ata_generic
scsi_mod  225280  5 sd_mod,libata,sr_mod,sg,vmw_pvscsi

-- /etc/initramfs-tools/modules

-- /etc/kernel-img.conf
# Kernel image management overrides
# See kernel-img.conf(5) for details
do_symlinks = yes
do_bootloader = no
do_initrd = yes
link_in_boot = no

-- /etc/initramfs-tools/initramfs.conf
MODULES=most
BUSYBOX=auto
KEYMAP=n
COMPRESS=gzip
DEVICE=
NFSROOT=auto

-- /etc/initramfs-tools/update-initramfs.conf
update_initramfs=yes
backup_initramfs=no

-- /etc/crypttab
# 

-- mkinitramfs hooks
/etc/initramfs-tools/hooks/:
set_hostname_in_network_config.sh

/usr/share/initramfs-tools/hooks:
cryptgnupg
cryptkeyctl
cryptopenct
cryptopensc
cryptpassdev
cryptroot
cryptroot-unlock
dmsetup
dropbear
fsck
keymap
klibc-utils
kmod
resume
thermal
udev
zz-busybox


-- System Information:
Debian Release: 9.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 4.9.0-3-amd64 (SMP w/1 CPU core)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_US:en (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages initramfs-tools depends on:
ii  initramfs-tools-core  0.130
ii  linux-base4.5

initramfs-tools recommends no packages.

Versions of packages initramfs-tools suggests:
ii  bash-completion  1:2.1-4.3

-- no