1

Can any one tell me how to execute bash scripts via pxe boot. What I am trying to do is when Raw Server boots up I want to deploy cloned image over hard disk via PXE boot. I am aware that there are some tools like Fog which does similar thing. But I am trying to do this by dd as part of university project. Any kind of help is appreciated.

Edit:

I followed following procedure.
1. Copied vmlinuz and initrd to tftp directory
2. Unpacked initrd (Using https://www.novell.com/documentation/zenworks7/dm7admin/data/b2cdjzb.html)

3. Added following lines in init script

echo "Deploying image of an ESXi Hypervisor"
echo "Downloading image"
wget http://192.168.1.250/backup/esxi -O /bin/esxi
echo "Deploying image"
sudo dd if=~/bin/esxi of=/dev/rdisk2 bs=1m
echo "Process Complete"

4. Repacked initrd

5. Added both files initrd and vmlinuz under boot folder /tftpboot/boot

6. Added following lines in pxe default file

label VMware ESXi (Last Backup 1)
        KERNEL boot/vmlinuz
        APPEND initrd=boot/initrd 
But it still gives error "mountinng /sys on /root/sys failed"

What I am missing here?

5
  • You boot up an OS that has bash installed.
    – user143703
    Commented Aug 17, 2015 at 17:36
  • Hi Yoonix there is no OS as its raw machine. So technically when bios configueration is done I want to execute bash script whhen bios setting are completed and there is no OS in Hard disk
    – Kapil
    Commented Aug 17, 2015 at 18:41
  • 1
    Bash is an interpreted language. You need an interpreter that understands it. That interpreter is usually the bash shell. You simply cannot do what you want. You boot an OS via the network that has bash installed and have that OS run the script.
    – user143703
    Commented Aug 17, 2015 at 18:52
  • Ok, I am relatively new to this. But if I use centos linux light weight OS here and deploy it via pxe and if I put my script in initrd will this work?
    – Kapil
    Commented Aug 17, 2015 at 19:54
  • You could probably unpack the initramfs from the current debian netinst installer, that is already pxe-capable, add your script, repack, and deploy via PXE. Commented Aug 17, 2015 at 21:04

2 Answers 2

1

Get a kernel and initrd.gz from any PXE capable distro i.e. Ubuntu. Every initrd has an init script that usually loads net drivers, maps disks, etc etc. you could very well create a complementary initrd redefining init adding your code. When you pxeboot your client using i.e. pxelinux you can load both initrd consecutively separated by a comma. The content of the the second initrd will overwrite the content within the original one. This method has several advantages: you do not need to touch the original initrd. Assembling the secondary initrd is easy/fast because it is a very small file, etc,etc..

EDIT:

init is usually a complex script invoking several modules. As I've said before it loads net drivers, it maps disks, etc etc. In order to PXE boot your kernel/initrd set you will surely need to pass additional parameters in the append line; please see how Serva PXE boot/install several Linux distributions (you can take the necessary parameters from there). Please consider an initrd might end up presenting a particular installation menu or thing like that; you have to follow init's code and insert "your" code right before this happens. This task requires good knowledge of Bash, and Linux in general. Please do not expect a 5 minutes job.

5
  • Hello Pat please have a look at the edit.
    – Kapil
    Commented Aug 17, 2015 at 23:54
  • See my edit ...
    – Pat
    Commented Aug 18, 2015 at 6:57
  • Thanks a lot pat. I did it successfully. Only issue I am facing is till now I was packing entire image in initrd so that it will be available in file system when I will deploy it over host using dd over hard disk. Since this is not viable approach as it loads entire image in RAM, now I am trying to mount nfs which resides on pxe server in initrd. But pxe server is not reachable from host when I try to ping. I tried to check root cause and I guess eth0 is not configured. One of the way is to modify initramfs but is there any simpler way to do this?
    – Kapil
    Commented Aug 20, 2015 at 0:03
  • if you PXE booted => some NIC "must' be available then you could use NFS or even HTTP (wget) to retrieve your image then you could still use cc; yes you are moving the file into RAM and that's not so bad if the RAM is enough, most of the Live distros out there do something like that...
    – Pat
    Commented Aug 20, 2015 at 7:52
  • Actually image size which I was using here is around 2 GB (As its image of ESXI hypervisor) So after I got eth0 interface configured I just mounted NFS which resides in pxe server and got image from there. Thanks for your help.
    – Kapil
    Commented Aug 21, 2015 at 14:06
1

Heres a walkthrough on making a custom bootable live cd, that you could theoretically build to do whatever you wanted.

This would allow you to create an environment that would boot and execute what you need it to.

http://ubuntuforums.org/showthread.php?t=688872

Then you just boot that iso from the pxe server.

https://help.ubuntu.com/community/PXEInstallServer

I only listed ubuntu as the operating system because its very well documented.

Good luck!

Not the answer you're looking for? Browse other questions tagged .