Cybersecurity
DevOps Cloud
IT Operations Cloud
The ZENworks Imaging Boot CD includes the "initrd" file which contains the whole Linux operating system that loads when you boot from the CD.
To edit the ZENworks Imaging OS compressed inside the "initrd", it is not enough to just uncompress the file; you must also mount the file system to be able to make changes to anything within the file system.
The following article is designed to explain how to
Things you will need:
The following scripts will uncompress the "initrd" file to the "/home/<username>/Desktop/cdinitimg/point" directory.
If you are using a "bootcd.iso" from a ZDM7.0 or later then the "initrd" file has been created as a CPIO archive. For more information on this, see (http://en.wikipedia.org/wiki/Cpio).
If you are using a "bootcd.iso" from a ZDM6.5 SP2 or earlier then you simply mount the "initrd".
Due to this difference, I have included two slightly different scripts. Please use whichever is appropriate for you.
#!/bin/bash
# EXTRACT and EDIT "INITRD" (The Linux Filesystem)
cd /
# uncompress the initrd file
gunzip -c /home/<username>/Desktop/original_initrd/initrd > /home/<username>/Desktop/cdinitimg/initrd
# believe it or not the image is compressed
mkdir /home/<username>/Desktop/cdinitimg/point
cd /home/<username>/Desktop/cdinitimg/point
cpio -idm < /home/<username>/Desktop/cdinitimg/initrd
# make any changes you need to the initrd in "/home/<username>/Desktop/cdinitimg/point"
Note: Must run as root
#!/bin/bash
# EXTRACT and EDIT "INITRD" (The Linux Filesystem)
cd /
gunzip -c /home/<username>/Desktop/original_initrd/initrd > /home/<username>/Desktop/cdinitimg/initrd
# believe it or not the image is compressed
cd /home/<username>/Desktop/cdinitimg
mkdir point
mount initrd point -o loop
You should now find that the entire ZEN imaging OS has been extracted to the "/home/<username>/Desktop/cdinitimg/point" directory.
Add your scripts to "/home/<username>/Desktop/cdinitimg/point/bin" directory.
Note: if you have used a v6.5 or earlier "initrd", then you require root privileges to modify files within "/home/<username>/Desktop/cdinitimg/point".
One thing I have found in the past is that I often have to modify scripts as new images become available or other unforeseen changes occur. Saving my scripts to the CD meant that every time I changed a script I had to re-burn 7 CDs for the other technicians in the office. It also meant I had to complete this process over and over again.
I have since added only one additional script to the CD, (humanities.sh) which asks the user to authenticate to the ZEN server via eDirectory authentication, at which point it maps a scripts directory on the server where I store and run all my scripts.
This means no more re-burning CD's and I can easily modify and add scripts without repeating this process. Also if the CD goes missing, there is no confidential data stored on the CD.
This is the only script I store on the CD itself (humanities.sh):
#!/bin/bash
clear
echo ===================== Please select an option to 1-9: ======================
echo
echo 1. Install ZENimage Partition
echo
echo 2. Set static IP address
echo
echo 3. Connect to ZEN Server
echo
echo x. Exit to bash prompt
echo
echo===================================================================
read SELECTION
echo
#Common Variables
IP=<Insert Server IP address here>
SERVER=<Insert the name of the Server here>
MOUNTPOINT=/mnt/$SERVER/zen
IMGDIR=/mnt/$SERVER/zen/imaging
SCRIPTDIR=/mnt/$SERVER/zen/imaging/ZENboot_scripts
if [ $SELECTION = 1 ]
then
install.s
fi
if [ $SELECTION = 2 ]
then
echo Please follow the prompts to set a temporary static IP address.
echo Available addresses are:
echo "xxx Network (Building xxx)"
echo IP: xxx.xxx.xxx.xxx, subnet mask: xxx.xxx.xxx.xxx, Default Gateway: xxx.xxx.xxx.xxx
echo "xxx Network (Rollout Room)"
echo IP: xxx.xxx.xxx.xxx, subnet mask: xxx.xxx.xxx.xxx, Default Gateway: xxx.xxx.xxx.xxx
echo
echo
echo Please Enter the IP address:
read STATICIP
echo Please enter the subnet mask:
read SUBNETMASK
echo Please enter the default gateway:
read DEFAULTGW
ifconfig eth0 $STATICIP netmask $SUBNETMASK
route add default gw $DEFAULTGW dev eth0
echo
echo Please try pinging a local server to test network connection, then type humanities.sh to launch Humanities Imaging script again.
exit
fi
if [ $SELECTION = 3 ]
then
test -d $IMGDIR && echo Already connected to $SERVER && $SCRIPTDIR/select_task.sh && $SCRIPTDIR/select_task.sh && exit
echo Connecting to $SERVER...
echo
echo
test ! -d /mnt/$SERVER && mkdir /mnt/$SERVER
test ! -d $MOUNTPOINT && mkdir $MOUNTPOINT
echo Please enter a $SERVER username:
echo
echo
read USERNAME
mount -o username=$USERNAME //$IP/zen $MOUNTPOINT
test -d $IMGDIR && echo Successfully connected to $SERVER as: $USERNAME && $SCRIPTDIR/select_task.sh && exit
echo
echo
echo Invalid username or password. Please try again.
fi
if [ $SELECTION = x ]
then
echo Please type humanities.sh to launch Humanities Imaging script again.
exit
fi
exit
Now that you have stored your script within the bin directory (and have made sure it has appropriate executable rights), you can unmount your "/home/<username>/Desktop/cdinitimg/point" directory and recompress your "initrd".
The above process has now given you the ability to launch your script from the bash prompt once the CD has loaded.
You can also modify the ZENworks Imaging menu screen that automatically loads on boot.
I have changed our menu to give me an additional "Humanities Script" option which has also been set to load automatically after the specified time-out period.
This part of the process is very easy; only two files need to be modified.
if [ $mode = '2' ] ; then
# auto (2)
/bin/bash -rcfile /bin/bashrc -c "/bin/imaging.s boot"
elif [ $mode = '3' ] ; then
# lilo (3) - enable - disable
/bin/bash -rcfile /bin/bashrc -c "/bin/lilo.s boot"
elif [ $mode = '5' ] ; then
# manual (5)
/bin/bash -rcfile /bin/bashrc -c "/bin/prompt.s boot"
elif [ $mode = '6' ] ; then
# Humanities (6)
/bin/bash -rcfile /bin/bashrc -c "/bin/humanities.sh boot"
elif [ $mode = '4' ] ; then
# install (4)
/bin/bash -rcfile /bin/bashrc -c "/bin/install.s boot"
else
# config (7)
/bin/bash -rcfile /bin/bashrc -c "/bin/config.s boot"
fi
/bin/bash -rcfile /bin/bashrc
elif [ $mode = '6' ] ; then
# Humanities (6)
/bin/bash -rcfile /bin/bashrc -c "/bin/humanities.sh boot"
Now that the CD knows how to boot your script, we must edit the menu file that allows you to select your script from the ZEN imaging menu.
This file is found back in:
"/home/<username>/Desktop/ZENimagingCD/boot/i386/loader/isolinux.cfg"
default linux
label Humanites
kernel linux
append initrd=initrd ramdisk_size=67584 vga=0x0314 splash=silent mode=6 CDBOOT=YES showopts
label linux
kernel linux
append initrd=initrd ramdisk_size=67584 vga=0x0314 splash=silent mode=2 CDBOOT=YES showopts
label manual
kernel linux
append initrd=initrd ramdisk_size=67584 vga=0x0314 splash=silent mode=5 CDBOOT=YES showopts
label config
kernel linux
append initrd=initrd ramdisk_size=67584 vga=0x0314 splash=silent mode=7 CDBOOT=YES showopts
label install
kernel linux
append initrd=initrd ramdisk_size=67584 vga=0x0314 splash=silent mode=4 CDBOOT=YES showopts
label lilo
kernel linux
append initrd=initrd ramdisk_size=67584 vga=0x0314 splash=silent mode=3 CDBOOT=YES showopts
label disable
kernel linux
append initrd=initrd ramdisk_size=67584 vga=0x0314 splash=silent mode=3 DISABLEZEN=1 CDBOOT=YES showopts
label enable
kernel linux
append initrd=initrd ramdisk_size=67584 vga=0x0314 splash=silent mode=3 ENABLEZEN=1 CDBOOT=YES showopts
implicit 1
gfxboot bootlogo
display message
prompt 1
timeout 200
readinfo 2
framebuffer 1
Unmount and re-compress initrd script for initrd ZDMv7.0:
#!/bin/bash
# Remake modified "initrd"
cd /
find /home/<username>/Desktop/cdinitimg/point/ | cpio -o > /home/<username>/Desktop/cdinitimg/initrd
gzip --best /home/<username>/Desktop/cdinitimg/initrd
mv /home/<username>/Desktop/cdinitimg/initrd.gz /home/<username>/Desktop/final_initrd/initrd
chmod 777 /home/<username>/Desktop/final_initrd/initrd
Unmount and re-compress initrd script for initrd ZDM6.5 SP2 and earlier:
Note: Must run as root
#!/bin/bash
# Remake modified "initrd"
cd /
mkdir /home/<username>/Desktop/cdinitrd
dd if=/dev/zero of=initrd bs=1k count=60960
mke2fs -i 1024 -b 1024 -m 5 -F -v initrd
mount initrd /home/<username>/Desktop/cdinitrd -t ext2 -o loop
cp -av /home/<username>/Desktop/cdinitimg/point/* /home/<username>/Desktop/cdinitrd
umount /home/<username>/Desktop/cdinitrd
gzip --best initrd
mv initrd.gz /home/<username>/Desktop/final_initrd/initrd
chmod 777 /home/<username>/Desktop/final_initrd/initrd
Now you should have the updated and re-compressed "initrd" file in the "/home/<username>/Desktop/final_initrd" directory.
Copy this file back to the ""bootcd.iso"" into the "/boot/i386/loader/" directory replacing the older version.
Also replace the:
ZDM v7.0: "\boot\i386\loader\isolinux.cfg"
ZDM6.5 SP2 or earlier: "\boot\loader\isolinux.cfg"
with "/home/<username>/Desktop/ZENimagingCD/boot/i386/loader/isolinux.cfg"
You are now ready to burn your CD and start using the new scripts.
Correction: Leon's article worked just fine, with one exception.
When I used his tip for re-creating the cpio archive version of initrd, PXE booting would crash with a VFS error message.
I ran "file initrd" on the re-created initrd and compared the output to the unmodified initrd, and found that the cpio format is different (the unmodified version was in ASCII format and did not have CRC checking).
I found that if instead of using "cpio -o" you use "cpio -o -c" it works fine.