open.itworld.com
  Search  
Security Home Page Security Webcasts Security White Papers Security Newsletters Security News Open Topics Careers ITworld Voices ITwhirled The Security site of ITworld.com

Unix Tip: Creating CDs for Unix or Windows

ITworld.com 11/22/2006

Sandra Henry-Stocker, ITworld.com

Send in your Unix questions today! | See additional Unix tips and tricks

Preparing a CD that displays proper file names whether it is mounted on a Unix system or on a Windows box requires little more than the proper set of arguments to the mkisofs command and software that knows how to work with ISO images. In this week's column, we look at a script that prepares a multi-use ISO image from files in a selected directory.

To understand this script, assume that we have a directory that contains a series of subdirectories, each of which contains the files associated with a particular software product that we might want to write to a CD for distribution to our customers.

We will use the select command to create a menu of the subdirectories from which the user will select the product that he wants to write to CD. Each subdirectory is named after the product that it contains. Once the user has selected a particular product, the script uses the mkisofs command with a particular set of options to create an ISO image that can subsequently be written to a CD. The options used in this particular script are explained below:

-r sets the uid and gid to 0
-U allows "untranslated" filenames, violating the ISO9660 standards, but providing the flexibility that we need to accommodate filenames with more than one dot
-iso-level specifies the particular ISO level that we want to use
-A specifies text to be written into the volume header
-V specifies volume ID to be written into the master block
-o specifies the name of our output file (i.e., the ISO file we are creating)
-copyright specifies the name of the file containing the copyright

Numerous other options are available with the mkisofs command. You will have to read the man page to learn about all the possibilities. The completed script looks like this:

#!/bin/bash
#
# mkCD

# identify location of product directories
prodDir=/data/delivery

cd $prodDir

# ask user to select product install files to burn to CD
echo
echo "Select product for ISO image:"
select PRODUCT in `ls`; do
    break
done

# Move to product directory
cd $PRODUCT 2>/dev/null || (echo "ERROR: Not a directory $dir"; exit 1)
APPLID=`head -1 Copyright`

# Have user verify files to be written to ISO image
ls -l

ans=`ckyorn -p "Files OK?"`

case $ans in
[Yy]*)  echo;;
[Nn]*)  echo "Exiting."
        exit 1
        ;;
    *)  echo "Exiting.  Please try again."
        exit 1
        ;;
esac

# remove previous iso files from /tmp
if [ -f /tmp/$PRODUCT.iso ]; then
    ans=`ckyorn -p "remove existing iso file?> "`
    case $ans in
      [Yy]*) rm /tmp/$PRODUCT.iso;;
      [Nn]*) mv /tmp/$PRODUCT.iso /tmp/$PRODUCT.iso$$;;
    esac
fi

# create the ISO image
mkisofs -r -U -iso-level 2 -A "$APPLID" -sysid "Boson Ltd" \
  -V "$PRODUCT" -o /tmp/$PRODUCT.iso *

# show user the file that was created
ls -l /tmp/$PRODUCT.iso
Here's the output from a sample running of the script:
# ./mkCD

Select product for ISO image:
1) Product1
2) Product2
3) Product3
#? 2
total 52396
-rw-r--r--   1 root     other        121 Nov 20 16:45 Copyright
-rw-r--r--   1 root     other        918 Nov 20 16:44 Manifest
-rw-r--r--   1 root     other        186 Nov 20 16:46 config
-rwxr-xr-x   1 root     other    18129064 Nov 20 16:52 config.new.tar.Z
-rwxr-xr-x   1 root     other    8644824 Nov 20 16:51 install.full.tar.Z
-rw-r--r--   1 root     other         92 Nov 20 16:46 parms
-rw-r--r--   1 root     other         92 Nov 20 16:46 readme
-rw-r--r--   1 root     other        296 Nov 20 16:46 registration.txt

Files OK? [y,n,?,q] y

remove existing iso file?>  [y,n,?,q] y
Warning: creating filesystem that does not conform to ISO-9660.
 38.09% done, estimate finish Mon Nov 20 16:55:16 2006
 76.13% done, estimate finish Mon Nov 20 16:55:16 2006
Total translation table size: 0
Total rockridge attributes bytes: 829
Total directory bytes: 0
Path table size(bytes): 10
Max brk space used 8000
13136 extents written (25 Mb)

-rw-r--r--   1 root     other    26902528 Nov 20 16:55 /tmp/Product2.iso
You can verify the labels you used during the creation of the ISO file by using the labelit command. Notice that we use the -F hsfs parameter to specify the type of file we are asking about.
# labelit -F hsfs /tmp/Product2.iso
CD-ROM is in ISO 9660 format
System id: Boson Ltd
Volume id: Product2
Volume set id:
Publisher id:
Data preparer id:
Application id: Boson Ltd Product 2
Copyright File id: Copyright
Abstract File id:
Bibliographic File id:
Volume set size is 1
Volume set sequence number is 1
Logical block size is 2048
Volume size is 13136
The warning about ISSO 9660 is generated due to our use of the -U flag. The ISO Level 2 option allows filename with up to 31 characters. The * in the mkisofs command says which files (i.e., all in the current directory) are to be incorporated into the ISO image.

Verifying the content of the CD

Once the CD has been created (I used ImgBurn freeware), you can verify that the contents of the CD look proper on both Unix and Windows systems.

Checking on Windows, my CD contents looked like this:
> dir D:
 Volume in drive D is Product2
 Volume Serial Number is 2ACA-4CE6

 Directory of D:\

11/20/2006  04:45 PM               121 Copyright
11/20/2006  04:44 PM               918 Manifest
11/20/2006  04:46 PM               186 config
11/20/2006  04:52 PM        18,129,064 config.new.tar.Z
11/20/2006  04:51 PM         8,644,824 install.full.tar.Z
11/20/2006  04:46 PM                92 parms
11/20/2006  04:46 PM                92 readme
11/20/2006  04:46 PM               296 registration.txt
               8 File(s)     26,775,593 bytes
               0 Dir(s)               0 bytes free
Checking on Solaris, the files look basically the same:

bash-2.03# ls -l /cdrom/product2
total 52301
-r--r--r--   1 root     root         121 Nov 20 16:45 Copyright
-r--r--r--   1 root     root         918 Nov 20 16:44 Manifest
-r--r--r--   1 root     root         186 Nov 20 16:46 config
-r-xr-xr-x   1 root     root     18129064 Nov 20 16:52 config.new.tar.Z
-r-xr-xr-x   1 root     root     8644824 Nov 20 16:51 install.full.tar.Z
-r--r--r--   1 root     root          92 Nov 20 16:46 parms
-r--r--r--   1 root     root          92 Nov 20 16:46 readme
-r--r--r--   1 root     root         296 Nov 20 16:46 registration.txt
Creating CDs that look proper whether they are mounted on a Unix or Windows system is easy, but I like to use a script so that I don't have to remember which options to use with the mkisofs command.

 

Sandra Henry-Stocker has been administering Unix systems for more than 18 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She currently works for TeleCommunication Systems, a wireless communications company, in Annapolis, Maryland, where no one else necessarily shares any of her opinions. She lives with her second family on a small farm on Maryland's Eastern Shore. Send comments and suggestions to bugfarm@gmail.com.




Sponsored Links

Sign up for a Microsoft Dynamics® CRM WEBCAST
Hear globally recognized leaders in customer strategy discuss the importance and evolution of CRM.
TRY NEW SUN SERVERS FREE for 60 Days!
Test The Latest Sun Servers In Your Environment BEFORE YOU BUY. Pay Nothing, Not Even Shipping.
Workflow Enabled Help Desk & IT Service Management
Automate service desk activities and integrate processes across IT. Learn more here.
Sign up for a FREE NETWORK RISK ASSESSMENT!
MORE THAN 70% OF NETWORKS ARE INFECTED by hidden Malware. Find out if your network is infected now!
Enterprise IP Goes Mobile
To maximize full productivity, companies must integrate their mobile applications with the IP network.
» Buy a link now

Advertisements
Sponsored links
Top 5 Reasons to Combine App Performance and Security
Locate Hidden Software on business PCs with this free tool
KODAK i1400 Series Scanners stand up to the challenge
Bring harmony to your mix of UNIX-Linux-Windows computing environments
 Home   Open source  Operating systems  Unix
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   IDG Connect   IDG World Expo   Infoworld   ITworld   JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.