View previous topic :: View next topic |
Author |
Message |
ParsEmAll n00b
Joined: 14 Oct 2003 Posts: 6 Location: Switzerland
|
Posted: Sun Jun 18, 2006 9:03 pm Post subject: Howto: GNAP booting from initrd over pxe |
|
|
Hi @all
This is my first howto in this forum.
I was looking for a rescue system...
It has to boot via pxe, just in case that all harddisk are down on my server(s).
Some days ago I wrote a similar howto: http://www.sysresccd.org/forums/viewtopic.php?t=1157
The downside of the system rescue CD is, that I did not found a howto, how to customise the installed packages (remove and add).
I found GNAP:
http://www.gentoo.org/proj/en/base/embedded/gnap-userguide.xml
http://www.gentoo.org/proj/en/base/embedded/gnap-advancedguide.xml
I played around an added some extensions...
This weekend I hacked on the init-script so that GNAP boots from a pxe ramdisk.
Requirements for this project:
- a gentoo workstation to build a gnap iso
- a dhcp server
- a tftpd server (net-ftp/tftp-hpa)
- a lot of process time
Sidenotes
I putted my gnap scripts to /opt/gnap.
My overlay is under: /opt/gnap/myoverlay.
I have done a complete rebuild of gnap:
Code: |
# gnap_make -v 20060416 -p /usr/lib/gnap/gnap-portagesnapshot.tar.bz2 -t all
|
Also I added some extensions to gnap and remastered the gnap core:
Code: |
# gnap_remaster -d . -e mdadm-20060416 -e minicom-20060416 -e nmap-20060416 -e reiserfsprogs-20060416 -o mygnapcore.tar
|
These steps arn't required. But you have to take care! Please ajust the all scripts; they have to fit to your locations! In this howto, most scripts are executet to/from /opt/gnap!
This howto is a hack. It works for me. Follow on your own risk!
Overview
1. generate a current iso of gnap
2. mounting iso
3. copy needed files from the iso
4. recreation of the initrd
5. patching the init script
6. packing initrd
7. configuring tftp server
1. generate a current iso of gnap
I used this script to generate my iso file:
Code: |
# gnap_overlay -i /opt/gnap/gnap-image.iso -o /opt/gnap/myoverlay/
|
2. mounting iso
Code: |
# mkdir /opt/gnap/iso
# mount -o loop /opt/gnap/gnap-image.iso /opt/gnap/iso
|
3. copy needed files from the iso
copy the kernel to the tftproot. On my system its under /tftproot. All gnap relatet tftp boot files are under /tftproot/gnap.
My working directory for gnap is /opt/gnap.
Code: |
# cd /opt/gnap
# cp iso/isolinux/gentoo /tftproot/gnap
# cp iso/isolinux/gentoo.igz /opt/gnap
# cp iso/image.squashfs /opt/gnap
# cp iso/overlay.tgz /opt/gnap
|
We don't need the mountet iso anymore, so we can unmount it:
Code: |
# umount gnap-image.iso
|
4. recreation of the initrd
We need a working directory for our new initrd:
Now we can unpack the old initrd:
Code: |
# gunzip -c gentoo.igz > gentoo.img
|
For the next step we need a little perl script: unigz.pl
Code: |
#!/usr/bin/perl -w
#
use strict;
use File::Slurp qw(slurp);
my $ifile = slurp($ARGV[0], binmode=> ':raw');
my $newfile;
my $i=1;
my @newfiles = split(/TRAILER!!!/,$ifile);
`mkdir $ARGV[0].dir`;
foreach $newfile (@newfiles)
{
open F, "> ./$ARGV[0].dir/$i";
print F $newfile;
print F "TRAILER!!!\0";
close F;
`cd $ARGV[0].dir; cpio -i -H newc < $i; rm $i; cd ..`;
$i++;
}
|
Credit: This script is from this forum post: https://forums.gentoo.org/viewtopic-t-383198-highlight-unpack+igz.html
And we can use it like this:
Code: |
# ./unigz.pl gentoo.img
cpio: premature end of file
cpio: warning: skipped 88 bytes of junk
cpio: premature end of file
cpio: warning: skipped 360 bytes of junk
cpio: premature end of file
cpio: warning: skipped 304 bytes of junk
cpio: premature end of file
cpio: warning: skipped 44 bytes of junk
cpio: premature end of file
cpio: warning: skipped 320 bytes of junk
cpio: premature end of file
cpio: premature end of file
|
We can ignore the strange waring messages!
Now we have a directory: gentoo.img.dir
We can copy/move all needed files together:
Code: |
# cd /opt/gnap/img/
# cp -a ../gentoo.img.dir/* .
# mv ../image.squashfs .
# mv ../overlay.tgz .
|
5. patching the init script
We need to patch the init script in our new initrd! here is the complete diff file:
Code: |
# diff ../gentoo.img.dir/init init
78a79,82
> # ramroot options
> ramroot)
> RAMROOT=1
> ;;
247a252,312
> ##
> # ramboot
> if [ "${RAMROOT}" -eq '1' ]
> then
> good_msg "Making tmpfs for ${NEW_ROOT}"
> mount -t tmpfs tmpfs ${NEW_ROOT}
>
> for i in dev mnt mnt/cdrom mnt/livecd tmp tmp/.initrd mnt/gentoo sys
> do
> mkdir -p ${NEW_ROOT}/$i
> chmod 755 ${NEW_ROOT}/$i
> done
> cp /dev/null ${NEW_ROOT}/dev
> cp /dev/console ${NEW_ROOT}/dev
>
> # Required for gensplash to work. Not an issue with the initrd as this
> # device isnt created there and is not needed.
> if [ -e /dev/tty1 ]
> then
> cp /dev/tty1 ${NEW_ROOT}/dev
> fi
>
> good_msg 'Determining looptype ...'
> cd ${NEW_ROOT}
>
> good_msg 'Mounting squashfs filesystem'
> mount -t squashfs -o loop,ro /${LOOPEXT}${LOOP} ${NEW_ROOT}/mnt/livecd
>
> FS_LOCATION='mnt/livecd'
>
> good_msg "Copying read-write image contents to tmpfs"
> # Copy over stuff that should be writable
> (cd ${NEW_ROOT}/${FS_LOCATION}; cp -a ${ROOT_TREES} ${NEW_ROOT})
>
> good_msg "linking ${NEW_ROOT}"
> for x in bin sbin lib lib32 lib64 boot usr opt
> do
> ln -s mnt/livecd/${x} ${x}
> done
>
> # link the overlay file
> good_msg "copying ${NEW_ROOT}/mnt/cdrom/overlay"
> cp /overlay.tgz ${NEW_ROOT}/mnt/cdrom/
>
> mkdir initrd proc tmp sys 2>/dev/null
> chmod 1777 tmp
>
> mount -t tmpfs udev ${NEW_ROOT}/dev
> mkdir ${NEW_ROOT}/dev/pts
> mkdir ${NEW_ROOT}/dev/shm
> mount -t devpts devpts ${NEW_ROOT}/dev/pts
> mount -o bind /dev ${NEW_ROOT}/dev
>
> cd /newroot
>
> good_msg "chrooting ${NEW_ROOT}"
> exec /bin/busybox chroot . /sbin/init 2
>
> fi
>
>
|
6. packing initrd
Since the new inird is finished, we can repack it.
Code: |
# cd /opt/gnap/img/
# find * | cpio -o -H newc | gzip -9 -c > ../gentoo.my.igz
|
We also need to move this new initrd to the tftproot:
Code: |
# mv /opt/gnap/gentoo.my.igz /tftproot/gnap
|
7. configuring tftp server
My tftp root is under /tfproot so I needed to modify this file: /tftproot/pxelinux.cfg/default:
Code: |
LABEL gnap
KERNEL gnap/gentoo
APPEND append initrd=gnap/gentoo.my.igz root=/dev/ram0 acpi=off init=/linuxrc looptype=squashfs loop=/image.squashfs ramroot
|
So I hope this litte howto has any use to you.
Maybe it can be included to the official gnap.
Greetings from Switzerland. |
|
Back to top |
|
|
jmbsvicetto Moderator
Joined: 27 Apr 2005 Posts: 4734 Location: Angra do Heroísmo (PT)
|
Posted: Sun Jun 18, 2006 9:54 pm Post subject: |
|
|
Moved from Installing Gentoo to Documentation, Tips & Tricks.
This is not a support question, but an how-to, so I believe it belongs here. _________________ Jorge.
Your twisted, but hopefully friendly daemon.
AMD64 / x86 / Sparc Gentoo
Help answer || emwrap.sh
|
|
Back to top |
|
|
ParsEmAll n00b
Joined: 14 Oct 2003 Posts: 6 Location: Switzerland
|
Posted: Sun Jun 18, 2006 10:32 pm Post subject: this howto boots to runlevel 2: nonetwork |
|
|
if you like to boot to default (with network) runlevel, you have to cange the init script:
Code: |
exec /bin/busybox chroot . /sbin/init 3
|
@jmbsvicetto : np |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|