LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bootable USB with two partition (https://www.linuxquestions.org/questions/linux-newbie-8/bootable-usb-with-two-partition-4175410767/)

ciclonite 06-10-2012 04:54 PM

Bootable USB with two partition
 
Hi all,
I have an USB stick with two partiton (called for semplicity P1 and P2).
I need to create bootable usb with this constrain:
1. The bootloader stay on P1
2. The Linux OS stay on P2
3. Before the Bootloader load the root Partition on P2, I NEED TO CALL A BASH SCRIPT. (this is the most important thing).
I've try to doing this with SYSLINUX + initrd without success.

My idea was SYSLINUX boot initrd, call the script and after load the root partition.

Have any idea or tutorial?
Thanks a lot.

pan64 06-11-2012 05:32 AM

how do you want to execute a bash script without an os? what is in that script?

ciclonite 06-11-2012 05:50 AM

Using INITRD teorically im able to execute command. The script call a binary executable.

allend 06-11-2012 06:29 AM

Theoretically you cannot use the initrd to execute a command. From http://www.ibm.com/developerworks/li...y/l-linuxboot/
Quote:

Init

After the kernel is booted and initialized, the kernel starts the first user-space application. This is the first program invoked that is compiled with the standard C library. Prior to this point in the process, no standard C applications have been executed.

In a desktop Linux system, the first application started is commonly /sbin/init. But it need not be. Rarely do embedded systems require the extensive initialization provided by init (as configured through /etc/inittab). In many cases, you can invoke a simple shell script that starts the necessary embedded applications.
If you are looking to run a script after the kernel is loaded but before the root partition is mounted, then you will need to look at the init process.

ciclonite 06-11-2012 07:58 AM

Thanks for quick reply.
I dont understand where is /sbin/init.
I've no access on P2 (the root partition) before invoking the binary executable.

allend 06-11-2012 11:22 AM

The /sbin/init executable is included in the initrd. As I do not use Ubuntu, I cannot really help you much further with this.

abdul_ahad 06-11-2012 01:08 PM

after the kernel is loaded, if an initrd is present, the kernel looks for a file named linuxrc in the root directory of the initrd and executes it. then the actual root is mounted and /sbin/init is executed.

if you want to run a bash script before the root filesystem is mounted, put it in the root directory of the initrd, make it executable and name it linuxrc

ciclonite 06-12-2012 04:36 PM

Thanks for reply.
I'm able to boot the initrd and execute the relative command using init. But now i need a method to found the root partition and boot it.. Any ideas?
Thanks a lot.

abdul_ahad 06-13-2012 06:29 AM

the normal procedure for the kernel, if an initrd is found is to execute linuxrc or init from it and then proceed to mount the root filesystem from the device given in the kernel command line at boot time, and then run /sbin/init from the actual rootfs. there is generally no need to run any special commands for mounting the actual root from the initrd.

Quote:

Originally Posted by ciclonite (Post 4701731)
Thanks for reply.
I'm able to boot the initrd and execute the relative command using init. But now i need a method to found the root partition and boot it.. Any ideas?
Thanks a lot.

are you referring to a shell script you have named as init in the initrd. if so, can you post its contents here so that we can have some idea of what goes on after loading the initrd and then work from there.


All times are GMT -5. The time now is 12:56 PM.