[syslinux] disk image creation, step by step

Pascal Vandeputte pascal.vandeputte at intec.ugent.be
Mon Apr 30 10:45:33 PDT 2007


Hi,

I am aware that it is impossible to netboot ISO files through 
pxelinux/memdisk
and that there are multiple reasons for not even attempting it (like the
operating system which will try to access a physical optical drive 
through its
own drivers anyway, BIOS issues etc.).

When people ask questions regarding ISO support in pxelinux/memdisk, they're
mostly told to convert the ISO into a "disk image" and boot it that way. We
usually don't hear back from these people. Either they find it obvious 
how to do
this and everything always works, or they don't even bother to try it.

Unfortunately I don't find it that obvious at all. As far as I know it 
should
be relatively straightforward if you can create a sufficiently large file,
partition it, create the right filesystem, modify some OS config files and
the bootloader. And create an MBR in that file while you're at it. Simple.

A few days ago I needed to convert an ISO for installing FreeBSD on a lot of
1U boxes without an optical drive. For many Linux distros you can find a PXE
version of the installer ready to download, but for FreeBSD converting 
the ISO
seemed to be the easiest way to get started, as these are my first BSD 
steps.

After a lot of googling and forum browsing, the only information I could 
find
which effectively got the job done was an e-mail by Shaun Reitan on this
mailing list: http://syslinux.zytor.com/archives/2005-October/006076.html
And even then it's a little hard to swallow if you're only used to Linux.

I thought it would be a good idea to rewrite Shauns command listing into
something which slightly resembles a howto and post it to this list. See 
below.
Maybe the SYSLINUX project home page isn't the right place for howtos 
like this,
but I feel that it should at least contain a pointer to a few examples.

Enthousiastic about this first success, I'm eager to try it another 
time, now
with a different ISO namely the "Ultimate Boot CD" which is even using 
ISOLINUX.
I'm stuck however. I create a file with dd, attach it to loop0 with losetup,
partition it (W95 FAT16 LBA?), re-attach it with the right offset for 
the first
partition, format it (mkdosfs/mkfs.vfat), mount it and copy all files. But
then I'm stuck. I need to write an MBR without ruining the partition 
table but
I don't know how, and I probably need to do something with the 
isolinux.cfg file
as well. But what?

Does a howto, similar to the one below, exist?

Another problem I get is that pxelinux doesn't find the disk image file 
as soon
as it's 94371840 bytes large. 94370816 bytes is fine. The amount of 
allocated
memory in VMWare doesn't seem to affect this.


Best regards,

Pascal Vandeputte




********************************************************************************

How to create a PXE-bootable disk image of the FreeBSD "bootonly" 
install ISO
=============================================================================
Based on an e-mail by Shaun Reitan on the SYSLINUX mailing list in 
October 2005.
http://syslinux.zytor.com/archives/2005-October/006076.html


The general idea:
-----------------
- transform the small "bootonly" ISO (which is intended to fetch all OS 
files
  over the network) into a PXE-bootable harddisk image
- make the first installation CD available on the network e.g. through NFS

This howto only explains how to create the PXE-bootable image.


- Download the "bootonly" installation ISO (about 25MB for FreeBSD 6.2)
  e.g. 
ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/6.2/6.2-RELEASE-i386-bootonly.iso

- If case you haven't got a FreeBSD system running already, install BSD
  somewhere temporarily using the first installation ISO (e.g. in VMWare).

- Copy the "bootonly" ISO to your BSD system, e.g. using scp or WinSCP.

- Find out how large you need to create your disk image:

    # ls -al *.iso
    -rw-r--r--  1 root  wheel  25444352 Apr 16 15:44 
6.2-RELEASE-i386-bootonly.iso

- Create a file of the appropriate size (make it a little larger to account
  for differences in block size, file system overhead etc.):

    # dd if=/dev/zero of=6.2-RELEASE-i386-bootonly.img bs=1k 
count=26000    
    26000+0 records in
    26000+0 records out
    26624000 bytes transferred in 1.404435 secs (18957091 bytes/sec)

    # ls -al *.iso *.img
    -rw-r--r--  1 root  wheel  26624000 Apr 27 03:28 
6.2-RELEASE-i386-bootonly.img
    -rw-r--r--  1 root  wheel  25444352 Apr 16 15:44 
6.2-RELEASE-i386-bootonly.iso

- Attach this image file as a memory disk:

    # mdconfig -a -t vnode -f 6.2-RELEASE-i386-bootonly.img -u 0

- Write a BSD label with boot code to it:

    # bsdlabel -w -B md0 auto

- And create a filesystem on it (BSD uses ufs):

    # newfs -m 0 md0a
    Warning: changing optimization to space because minfree is less than 8%
    /dev/md0a: 25.4MB (51984 sectors) block size 16384, fragment size 2048
            using 4 cylinder groups of 6.36MB, 407 blks, 832 inodes.
    super-block backups (for fsck -b #) at:
     160, 13184, 26208, 39232

- Create a mount point and mount this "memory disk" device (attached to the
  image file):

    # mkdir /tmp/img
    # mount /dev/md0a /tmp/img
    # df /tmp/img   
    Filesystem 1K-blocks Used Avail Capacity  Mounted on
    /dev/md0a      24950    4 24946     0%    /tmp/img

- Create another mount point and mount the ISO file on it through another md
  device:

    # mkdir /tmp/iso
    # mdconfig -a -t vnode -f 6.2-RELEASE-i386-bootonly.iso -u 1
    # mount_cd9660 /dev/md1 /tmp/iso
    # df /tmp/iso
    Filesystem 1K-blocks  Used Avail Capacity  Mounted on
    /dev/md1       24848 24848     0   100%    /tmp/iso

- Copy the ISO contents to the new disk image file:

    # cd /tmp/img/
    # cp -r /tmp/iso/* .
    # ls -al
    total 12
    drwxr-xr-x  4 root  wheel      512 Apr 27 03:40 .
    drwxrwxrwt  8 root  wheel      512 Apr 27 03:36 ..
    drwxrwxr-x  2 root  operator   512 Apr 27 03:35 .snap
    dr-xr-xr-x  5 root  wheel      512 Apr 27 03:40 boot
    -r--r--r--  1 root  wheel     2048 Apr 27 03:40 boot.catalog
    -r--r--r--  1 root  wheel       25 Apr 27 03:40 cdrom.inf

- Unmount and detach all md devices:

    # cd
    # umount /tmp/img /tmp/iso
    # mdconfig -d -u 0
    # mdconfig -d -u 1

- We're done. Copy the .img file to your tftp server.

    # ls -al *.img *.iso
    -rw-r--r--  1 root  wheel  26624000 Apr 27 03:41 
6.2-RELEASE-i386-bootonly.img
    -rw-r--r--  1 root  wheel  25444352 Apr 16 15:44 
6.2-RELEASE-i386-bootonly.iso

- And add something similar to this to your pxelinux.cfg/default file:

    label freebsd62
        kernel memdisk
        append initrd=images/freebsd/6.2-RELEASE-i386-bootonly.img harddisk




More information about the Syslinux mailing list