Logging %pre during kickstart – logfile doesn’t exist after boot

kickstartlogsrhel

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.

Best Answer

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.

Related Question