automated installations (6)
17 Feb 2006 The bugreports and patches are on their way to bugs.debian.org.I've been looking at the whole hostname thing again.
The code in the base-config package is executed after the first reboot. That means the hostname is already set at that point (by the netcfg package :( )
Some things to keep in mind when altering base-config udeb:
- it has an md5sums file you need to regenerate
- the Packages file is somewhere else
- the Packages file contains a "Size:" field you need to modify
I've attached the scripts to pack and unpack the base-config package.
By inserting a "sleep 1800" into the script to set the hostname, I was able to view what files existed before the script ran. My idea is that I can maybe alter those files with the real hostname and then continue the installation.
These files contain the hostname right before the base-config script:
/etc/hostname
/etc/hosts
/etc/motd
/etc/exim4/update-exim4.conf.conf
/etc/mailname
/var/lib/exim4/config.autogenerated
/var/cache/debconf/config.dat
/var/cache/debconf/config.dat-old
/var/log/syslog
/var/log/auth.log
/var/log/debian-installer/cdebconf/questions.dat
/var/log/kern.log
/var/log/user.log
/var/log/debug
/var/log/messages
Notice how /var/log/user.log exists but seems to be erased after the installation completes ?
These files are created after the base-config script:
/etc/ssh/ssh_host_rsa_key.pub
/etc/ssh/ssh_host_dsa_key.pub
/var/log/exim4/mainlog
/var/log/daemon.log
/var/log/lpr.log
/var/spool/mail/mail
/var/mail/mail
OK, So from all the files that already exist, I decide that these are important:
/etc/hostname
/etc/hosts
/etc/motd
/etc/mailname
/var/cache/debconf/config.dat
/var/cache/debconf/config.dat-old
And these are not:
/etc/exim4/update-exim4.conf.conf
/var/lib/exim4/config.autogenerated
/var/log/syslog
/var/log/auth.log
/var/log/debian-installer/cdebconf/questions.dat
/var/log/kern.log
/var/log/user.log
/var/log/debug
/var/log/messages
The reason why exim4 config is not important is because exim will be removed in favor of postfix anyway. The rest of the unimportant files are just logs.
Let's review the files that need to be changed:
- /etc/hostname
- This file contains the hostname and is generated by the netcfg package. This is one we need to change.
- /etc/hosts
- This file contains IP to hostname mappings and is also generated by the netcfg package. We will need our own custom version of this file anyway, so maybe it can be generated by a custom package later on.
- /etc/motd
- This file contains the message of the day and is generated at boot by /etc/init.d/bootmisc.sh from whatever uname returns. Could not care less about it :)
- /etc/mailname
- This file seems to be generated by the exim4 package. Since we will remove exim4 and install postfix on all machines, we can have postfix regenerate it.
- /var/cache/debconf/config.dat
- /var/cache/debconf/config.dat-old
- These files are used by debconf and contain the answers to the questions asked by debconf. The hostname variable can be changed with the db_set function
By changing in the file "/usr/lib/base-config/menu/hostname"
# Prompt for the hostname, using the current name, if any, as the default.
hostname=
LOOPCOUNT=2
while [ -z "$hostname" ]; do
into
# Prompt for the hostname, using the current name, if any, as the default.
hostname=myhostname
LOOPCOUNT=2
while [ -z "$hostname" ]; do
I'm able to change both /etc/hostname and uname.
But, it would be even better if I could use the debconf value stored in base-config/get_hostname
And yet even better if I could ask this question at the start of the installation.
For this, I remembered that when I installed dashslashdash (and of course looked under the hood), a script was installed that messes with the order questions are asked.
...
After looking through the scripts that make up the installer, I came to the conclusion that working my way around patching netcfg will be more complex than modifying netcfg itself.
After all, all I need to do in netcfg is change the priority of 1 question (I hope!)
The question now becomes: how do I compile netcfg ? Because it seems to use an old libc version and some libraries that only exist in the installer environment.
At first glance, I see no easy way to recompile the netcfg udeb. Maybe I could recompile the entire debian installer, but thats too much work and too much could go wrong.
I found the code I need to modify (netcfg-common.c line 520, function netcfg_get_hostname())
debconf_input(client, "high", template);
That "high" should be "critical"...
I'm considering a binary patch...
According to IDE, the instruction I want to modify is located at 0x8049d1d and I have to change 0x804ca63 ("high") to 0x804cada ("critical")
So, whipping up xxd:
(deepstar/tachyon) /tmp/udebtest/data/bin$ mv netcfg netcfg.old
(deepstar/tachyon) /tmp/udebtest/data/bin$ xxd netcfg.old | sed 's/0001d10: 740a c705 8cec 0408 0000 0000 5368 63ca/0001d10: 740a c705 8cec 0408 0000 0000 5368 daca/' | xxd -r > netcfg
Well, it still doesn't work.
I'm getting tired of this...
I did a preliminary test on a real system with 2 disks and 4 networkcards and saw the following problems:
- netcfg had problems getting online because the wrong networkcard was plugged in. Since each networkcard is connected to another network, netcfg needs to pick the correct networkcard to use. A value of "auto" is not good enough :( Furthermore, since I don't know which order the networkcards are detected, I can't tell in advance which networkcard should be used
- When installing grub, it did not know which disk to install to. Maybe this is some preseed variable ?
I'm getting more and more convinced that ditching netcfg and writing my own version is the way to go. The postinst script of netcfg just does "exec netcfg". I can replace that with my own code :)
I checked what is available in the initrd and found: ifconfig, route, iproute and netcat.
That should be enough to do some network configuration magic.
After the testsystem was setup, my collegue set it some more and sent me the list of changes.
They will be documented on our internal wiki.
One thing I should look at, is setting the timezone with tzconfig. Apparently, this is set to a wrong value. I hope there is a debconf variable for this.