Friday, July 17, 2009

Mounting cdrom in %post on RHEL/CentOS 5.x

Problem: The anaconda tarball contains(ed) a change that causes RHEL/CentOS 5.x installs to prematurely eject the cdrom/dvd before %post is executed in custom installs. There is discussion of what is affected here. In addition to the eject issue, /dev/cdrom no longer exists during the 5.x install process.

Solution Part 1: To resolve the cdrom eject issue, you need to modify the /usr/lib/anaconda/dispatch.py script in the stage2.img file from your custom install media. In order to mount and edit the stage2.img file, I did the following (based upon Ansari Imtiyaz's post here):

Copy the existing stage2.img file to the /tmp directory
# cp /images/stage2.img /tmp/old_stage2.img
# mkdir /mnt/old_stage2

Mount the old image
# mount -o loop /tmp/old_stage2.img /mnt/old_stage2

The old image is non-writable at this point, so we tar the files to move them to a writable folder
# cd /mnt/old_stage2
# tar -cvf /tmp/temp_stage2.tar .
# mkdir /tmp/new_stage2
# cd /tmp/new_stage2
# tar -xvf /tmp/stage2.tar

Once the tar file has been expanded, edit the /tmp/new_stage2/usr/lib/anaconda/dispatch.py file by flip-flopping the "methodcomplete" and "dopostaction" lines, as described here. Once editted, the "methodcomplete" line should follow the "dopostaction" line.

Create the new image file
# cd /tmp
# mkfs.cramfs stage2/ stage2.img.new

Copy the new image file into place
# mv /images/stage2.img /images/stage2.img.old
# cp /tmp/stage2.img.new /images/stage2.img

Solution Part 2: To resolve the issue with /dev/cdrom not existing during the install process, follow the instructions provided here (comment #3). I had to adjust Micah's sed command to properly provide the drive alias and to mount in a location that matches what is already in my kickstart:

### Insert into kickstart ks.cfg file after %post
cdrom=`cat /proc/sys/dev/cdrom/info | grep "drive name:" | sed 's/^drive name:\W*//'`
echo "CD ROM device is $cdrom; making dev link..."
ln -s /dev/$cdrom /tmp/cdrom
mount -t iso9660 -o ro /tmp/cdrom /mnt/cdrom

No comments:

Post a Comment