2 January 2008 - 1:22More pxelinux tricks: GParted LivePXE and PXE-booting DOS CDs
Well, it’s been a while since my last post because I’ve been busy writing a bunch and didn’t feel much like writing a blog entry in addition. Anyway, since my last post, LUG@GT held another InstallFest. This time I decided to add a PXE bootable GParted live distro so we could also repartition without involving extra optical media. In order to do that, I started from the base of the GParted LiveCD (which is also suitable for a LiveUSB version). The GParted LiveCD is based on Gentoo, so preparing a PXE bootable image is similar to how I must prepare the Gentoo installer for PXE booting. Since this is the most complicated image to prepare for PXE booting (relative to Ubuntu, Debian, Fedora, RHEL, OpenSUSE and Mandriva, which are the other distros we offer), I will first start with the instructions on making a Gentoo install PXE-bootable.
Gentoo PXE Install
- Grab a minimal install ISO. For this example, I’ll use install-x86-minimal-2007.0-r1.iso.
- Mount the iso and copy the following files: image.squashfs, isolinux/gentoo, isolinux/gentoo.igz (and isolinux/isolinux.cfg for reference)
- Make a temporary directory and unpack gentoo.igz:
mkdir tmp; cd tmp; zcat ../gentoo.igz | cpio -idv - Make a mnt/cdrom subdirectory (mkdir -p mnt/cdrom) and copy the image.squashfs into it
- Patch the init script so that it looks for the squashfs image in the right place. Here’s my gentoo_init.patch.
- Repack the gentoo.igz file:
find * | cpio --quiet --dereference -o -H newc | gzip -9 > ../gentoo.igz
Now, add Gentoo entries to your pxelinux config following the isolinux.cfg for reference, but add real_root=/ to the kernel parameters (the append=) line (assuming you are using my patch).
GParted Live PXE
So the process for making the GParted LiveCD PXE bootable is similar. Once I have performed the above modifications on the .igz file (to pack the squashfs right into the initrd), I could take the iso/syslinux entries for the GParted boot options and add them directly to my pxelinux boot menu. Instead, I decided to make a two-level menu with a self-contained GParted disk image. In other words, you select GParted from the PXE boot options and it loads a disk image which itself boots into syslinux, prompting for GParted-specific options. This is slightly more complicated, but it separates the maintenance of GParted-specific options from the pxelinux.cfg file. One could accomplish this kind of two-level separation in other ways, too, but I’ll describe what I did.
- Using syslinux’s mkdiskimage tool, make a disk image to contain the files:
mkdiskimage disk.img 7 255 63(make sure it is big enough to hold everything) - Mount the FAT filesystem part of the disk image:
mount -o loop,offset=32256 disk.img files - Copy the appropriate files from the LiveUSB stuff to the image (gparted kernel, gparted.igz, properly edited syslinux.cfg, options.msg, boot.msg, splash.lss, etc.)
- Unmount the loopback image:
umount disk.img - Run syslinux on the filesystem:
syslinux -o 32256 disk.img
Now I can copy this disk image somewhere and add an entry to my pxelinux.cfg similar to this:
label gparted kernel memdisk append initrd=gparted.img c=7 h=255 s=63 noedd
If it doesn’t work, make sure after copying the files to the loopback image that you don’t have errors due to going “out of bounds” on the image. I’ve found that when the size of the files are close to the size of the filesystem, and I copy and recopy certain files, I’ll get error messages like the following:
kernel: loop1: rw=1, want=112452, limit=112392
kernel: lost page write due to I/O error on loop1
I find starting over with a fresh filesystem and copying the files once only fixes this.
Bootable DOS CD
Finally, I also wanted to make a bootable DOS CD PXE bootable, so I tried a couple of methods before finding one that worked well. I won’t name the CD because it is probably against the terms of the license to do something like this, but it’s just convenient to not have to have media handy for personal uses. I used some utilities from the mtools suite as well as the geteltorito tool which is included in Debian’s genisoimage package.
- Extract the El Torito bootable image from the CD:
geteltorito -o eltorito.img cd.iso - Grab the DOS boot block from the El Torito image:
dd if=eltorito.img of=bootblock.img count=512 bs=1 - Set up mtools to create a loopback disk image. For this, I edited my ~/.mtoolsrc to contain
drive x: file="/tmp/floppyimage" - Use mformat to format the disk image that can hold the relevant files and give it the boot block:
mformat -C -t 160 -s 36 -h 2 -B bootblock.img x: - After that, I had to edit the autoexec.bat and other pieces of the CD startup files so it referred to files in the right places. This is the non-automatic part of the process. Previously, the system would boot with A: being the El Torito image, load mscdex.exe and then refer to Y: for files on the CD. When PXE booting, all of the relevant files will be on A: and mscdex won’t need to be loaded.
- After editing the proper files, copy them to the disk image:
mcopy -s * x:
In the last case, make sure to get the relevant DOS system and startup files. For the CD I was modifying, it was PC-DOS, so I needed ibmio.com, ibmdos.com, command.com as well as startup files like autoexec.bat and config.sys. After the disk image is made, I could simply add an entry to pxelinux.cfg like the following:
label dosboot kernel memdisk append initrd=dosimage.img.gz c=160 h=2 s=36 floppy noedd
In this case, I gzipped the image. For gparted, I didn’t gzip the outer image because the contents were already mostly compressed (e.g. the igz and kernel image).
14 Comments | Tags: PXE-related
21 Feb 2008 - 4:53
hey, i’m trying to make a pxe bootable live cd image. If I follow what you did for the gentoo image, I get some errors.
>>Determining root device…
mknod: /newroot/dev/console: no such file or dir
mknod: /newroot/dev/tty1: no such file or dir
>>booting (initramfs)..switch_root: bad newroot /newroot
Kernel panic – not syncing: attempted to kill init!
I think I must have some options wrong in the pxe config file for the boot string. Any ideas on what is going wrong?
22 Feb 2008 - 1:51
Are you encountering that problem with the Gentoo LiveCD or the GParted image? If it is the latter, and you were following my instructions (making a disk image), the options in the PXE configuration file don’t affect the boot parameters directly because it boots using disk emulation and then loads syslinux from the disk image. In that case it is syslinux.cfg in the disk image you need to fix up.
For the Gentoo image, my pxelinux config file looks something like this:
label gentoo_2007.0_x86kernel gentoo/2007.0/x86/gentoo
append root=/dev/ram0 init=/linuxrc dokeymap looptype=squashfs loop=/image.squashfs cdroot initrd=gentoo/2007.0/x86/gentoo.igz vga=791 splash=silent,theme:livecd-2007.0 CONSOLE=/dev/tty1 quiet real_root=/
22 Feb 2008 - 3:01
I am using the gentoo minimum install iso. The file name is the same as yours. Now with everything set up like that, I get a different error.
>>Determining root device…
!! Block device / is not a valid root device…
!! The root block device is unspecified or not detected.
Please specify a device to boot, or “shell” for a shell…
boot()::
I used /dev/ram0 and then it says invalid loop location: /image.squashfs
then it drops into a limited shell
Am I using the wrong image or am I missing some file?
23 Feb 2008 - 16:27
Are you sure you’ve applied the changes to init? I tried again from scratch following my instructions and ended up with a working image. Here’s the exact sequence of commands I used:
mkdir gentoo ; cd gentoowget http://www.gtlib.gatech.edu/pub/gentoo/releases/x86/2007.0/installcd/install-x86-minimal-2007.0-r1.iso
mkdir isomount -o loop,ro,uid=davidhi install-x86-minimal-2007.0-r1.iso isocp iso/image.squashfs .cp iso/isolinux/gentoo .cp iso/isolinux/gentoo.igz .cp iso/isolinux/isolinux.cfg .mkdir tmp; cd tmp#unpack igzzcat ../gentoo.igz | cpio -idv
mkdir -p mnt/cdrommv ../image.squashfs mnt/cdrom# patch initwget http://www.thegibson.org/blog/files/gentoo/gentoo_init.patch -O- | patch -p0
# repack igzfind * | cpio --quiet --dereference -o -H newc | gzip -9 > ../gentoo.igz
# extract entries from isolinux config and add real_rootgrep -A10000 "label" isolinux.cfg |
sed -e 's%\(append.*\)%\1 real_root=/%g' >> pxe_boot_entries
26 Mar 2008 - 19:11
Great tutorial, worked like a charm. You should post the gentoo instructions on the gentoo forums as it is the best I’ve seen so far. It could even get into the handbook instructions as an alternative to pxegrub which didn’t work for me.
Mike, make sure the config file is like he said and it should work. I had the same problem but after updating the config file it worked.
Thanks for the tutorial
06 Aug 2008 - 8:02
hi,
thanks for thanking the time to document this.
I am trying to follow your instructions but im having some problems, i am installing this on a redhat based firewall namely smoothwall 3, before you run away because of lack of medule support i have foolowed most of your instructions on my debian machine with the intension of moving the files to /tftpboot/ – /tftpboot/pxelinux.conf /mnt/dcrom
i have done all of this it has taken some brian power !!
i pxe boot, select gentoo it boots the gentoo.igz and gentoo then ask’s me to choose a keymap i hit enter to accept the default (us)
ok
then it displays
keeping default key
determining root device / is not a vaild device
the root block device is unspecified or not detected
please specify a davice to boot, or shell for a shell
i have tryed typing in / and cdrom but it display’s the same error.
in which file do i need to specifie the root device also i am booting from pxelinux.conf from tftpboot folder is this correct.
thanks
11 Sep 2008 - 2:13
Hello!
Thanks for a fantastic short-guide to PXE Gentoo!
I have done this with the minimal 2008 release, and I just want to share my diff-file (to be used as a patch?) of the init-file, as this differs slightly from the 2007 version.
Keep up the good work, we need more tips like this!
Cheers
diff-file:
323c323
while false
376a377,378
> REAL_ROOT=/image.squashfs
> REAL_ROOT_TYPE=squashfs
436c438
# cache_cd_contents
472c474
mount -t squashfs -o loop,ro “/mnt/cdrom/${LOOPEXT}${LOOP}” “${NEW_ROOT}/mnt/livecd”
01 May 2009 - 0:30
hey men,
you solved right now my life. I was working since several days (the third time this year) with fucking Gentoo PXE boot and every time I got shit result in fact of wrong squasfs or wrong / or any other shit after testing like 500.000 different versions, cds, or any other hints.
I don’t know why we can find 1.000.000 actual howto’s and actual patches for the INIT file and even not one will work up to that time I have read your patch file. Now it works fine
I guess nobody had run the PXE sucessfully with Gentoo since more than 1 year and maybe this is a big BUG and nobody knows it that the “mount” command in the INIT for squasfs is wrong declared.
thx a lot men, alex
25 May 2009 - 9:08
Hey guys,
Im stuck with the PXE gentoo 2008.0 livecd booting thing for a while now.
Currently the status can be described as:
>> Mounting squashfs filesystem
mount: /newroot/mnt/cdrom.squashfs /newroot/mnt/livecd failed: No such file or directory
!! Failed to $1; failing back to the shell
while booting on remote machine. Please help…
Couple questions:
Where should I place /mnt/cdrom ? In the /tftpboot directory or maybe in / ?
What else can be wrong ?
Thanks for help
Dan
25 May 2009 - 16:16
dental,
/mnt/cdrom doesn’t go in the /tftpboot directory on the PXE server, it goes in the initrd image (gentoo.igz) as a directory.
The way this is set up, the stuff on the TFTP server (in /tftpboot) is irrelevant once the Linux image has started booting. As part of the PXE boot process, the PXE client fetches gentoo (the kernel image) and gentoo.igz (the initrd). Once Linux booting starts, everything is self-contained within the initrd. Preparing the directory hierarchy in the initrd image is totally separate from the TFTP server stuff.
In principle it doesn’t matter where you put image.squashfs, as long as you change the mount command in the init script to mount the right thing. From the error message you’re getting, it looks like you didn’t modify that line of the init script properly (it’s looking in ${NEW_ROOT}/mnt/ for the image, rather than /mnt/ or /mnt/cdrom).
BTW, if you’re using 2008.0, here’s an updated patch (my original was from 2007.0; I know backfan provided a 2008.0 patch in a comment, but I thought I’d put one as a file):
http://www.thegibson.org/blog/files/gentoo/gentoo_init_2008.patch
26 May 2009 - 5:35
Hey,
Thanks for the help davidhi
Everything works now except that the livecd image gives me
“not enough memory to load specified image” error
and I’m only able to load the minimal version of gentoo.
My machine has 8gb RAM so I guess that should be a problem… ?
26 May 2009 - 18:41
How big of an image are we talking here? My 2008.0 images are 60MB and 63MB for x86 and amd64, respectively. You’re hitting a size limit in syslinux’s pxelinux (you can find that error message in the loadhigh.inc assembly source). You might be able to get around that, but PXE isn’t really made for encapsulating a whole full-featured live CD image. Two ways to handle that:
* People PXE-boot Knoppix by make a small PXE boot image and then using NFS to mount the (much larger) root filesystem. NFS root filesystems are pretty well supported these days.
* GParted’s current “Live PXE” images have a small PXE bootstrap image which boots up Linux and then uses HTTP get the squashfs root filesystem image from a web server after you’re already booted partially into Linux (and thus are less limited in what you can do). Poking at the initrd files in GParted’s image, it seems to use fuse’s httpfs, which can download pieces of the image on demand. It also looks like it uses the “live-initramfs” package to generate most of the init stuff, and live-initramfs supports the “fetch=” parameter which is designed to support “downloading a squashfs image from a given url, copying to ram and booting it” (according to the manpage). I’m not sure how much of GParted’s Live PXE image is customized and how much is provided by live-initramfs, but it’s worth looking into.
02 Sep 2009 - 16:11
Thanks David, this is exactly what I was looking for and saved me a lot of time. I successfully started the 2008 image after applying the patch file you provided!
10 Nov 2009 - 19:41
[...] modify the primary reference to the following two articles: http://blog.dastrup. com /? p = 12 http://www.thegibson.org / blog/archives/13 This step requires three documents gentoo, gentoo.igz, image.squashfs from the [...]