4

I am kickstarting several EL6 systems and I want to log the actions taken in my %pre section.

I know that I can log the %post section per the hints provided by centos.org: Tips and tricks for anaconda and kickstart using one of these two methods:

%post --log=/root/my-post-log
echo 'Hello, World!'

Or:

%post
exec < /dev/tty3 > /dev/tty3
chvt 3
echo
echo "################################"
echo "# Running Post Configuration   #"
echo "################################"
(
echo 'Hello, World!'
) 2>&1 | /usr/bin/tee /var/log/post_install.log
chvt 1

However I can't get this to work with the %pre section. Here is what I'm using:

%pre --log=/var/log/my-pre-log
echo 'Hello, World!'

When I am finally allowed to use the Virtual Consoles, the logfile is not to be found anywhere on the system.

This works fine for the %post section because at the time %post is executed, Anaconda switches to the new disks using chroot-- /var/log/ actually exists on the new system, and thus the logfile will exist after a reboot.

The problem with doing this with the %pre section is that the only filesystems available at the time is the memory-only filesystem. If I write the file to /tmp/, /root/pre_install.log or /var/log the filesystem disappears as soon as I shut down the machine.

The debugging shell is not available until midway through the installation, which makes debugging difficult.

Stefan Lasiewski
  • 19,264
  • 24
  • 70
  • 85
  • I can't verify this in my current environment, but would **syslog=[:] Once installation is up and running, send log messages to the syslog process on , and optionally, on port . Requires the remote syslog process to accept connections (the -r option). ** suffice? – tink Jun 05 '13 at 23:24
  • That might be a reasonable workaround as we do have a syslog server. Will kickstart send both STDERR & STDOUT to syslog, because I'd want both for debugging. – Stefan Lasiewski Jun 05 '13 at 23:54
  • What if you write the file to `/tmp/my-pre-log` in `%pre`, and then when you're in the `%post` write the file to `/root/my-pre-log`? – slm Jun 06 '13 at 00:53

1 Answers1

4

I had exactly the same need as you, to capture the %pre log for later analysis. You're right, by the time you're in %post Anaconda has already chrooted you to the newly-built filesystem, so it's not possible to access the %pre log. You could run %post with --nochroot, but IMO that makes paths in %post a pain.

I managed to get what I wanted by using %include inside the %post section. First, log your %pre output:

%pre --log /tmp/pre-install.log
echo "Starting Kickstart Pre-Installation..."

Then %include the %pre log during %post, sending it to a file with a bash here document :

%post --log /root/post-install.log
cat >> /root/pre-install.log << "EOF"
%include /tmp/pre-install.log
EOF

I believe this works because the %pre section gets evaluated by Anaconda first, which allows you to create files to be used by %include... then Anaconda evaluates the rest of the file, replacing each %include with the named file. I'm also capturing the Anaconda log the same way, just replaces pre-install with anaconda in the two %post section lines.