My Linux Bash Script Fails to run when automated with OS Startup
Hi,
I'm pulling my hair out over this (literally). I have a program that i have written which effectively builds up a new HDD for a new computer system. The program is run from a linux OS like SLAX (but my own) that resides on a USB drive. The idea is that i plug my USB drive into a new computer and my OS automatically builds up the HDD in the new computer system. This process includes partitioning, formatting and copying the OS onto the drive. My program works perfectly every time I manually run it from the prompt. However, if i try to automate the running of the program with the startup scripts of the linux (USB) OS it fails. The error is that fdisk cannot update the partition image because the kernel is still using it. This is what i have tried: 1) S99 script in rc.5 (5 because its unused in this system) 2) autologin script and .bash_profile 3) & to launch the program as new process 4) sleep 100 command to make the process wait for minute before commencing i have tried many variations, but its as if the program is running in a completely different environment. Any ideas? really could do with a good hint here :| Cheers, Andy |
Attach the script for people to look at?
|
Quote:
Quote:
put this at the start of your script: Code:
set -x Code:
S99yourotherscript Code:
/path/to/original/script &> path/to/logfile Oh and of course what Unspawn said about attaching the script... jlinkels |
Hi jlinkels,
thanks for the time you have taken, Quote:
"Re-reading the partition table failed with error 16: Device or resource busy. The Kernel still uses the old table. The new table will be used at the next reboot." Quote:
Also, an interesting point. When i invoke runlevel 5 with 'init 5', the script works fine (but to re-iterate, if this is done from bootup it fails) Quote:
Code that fails: Code:
# Delete last partition Quote:
Quote:
Quote:
Code:
#!/bin/bash ---------------------------- my current thoughts on this problem is that the script when being invoked by the system is somehow being run with different privileges. I only have a root account on this system (its a specialist system with no regard to its own safety :p) and so when I run the script manually, it is being run from a root account. Am I on the right lines? |
Quote:
Quote:
Considering what you already did for debugging a whole number of trivial tests can be skipped. There is one big difference between running your script manually and running it during boot time. When you run it during boot time your script is called as a child of init or sysinit. That means that init is still executing while your script is called, and I don't know what init does more before handing over the control to ...uhm ... actually what? While init is still executing, it might keep the drive locked for some reason. Your idea to put a pause in your script was good, but then again we don't know if init waits for all child processes to be terminated before it terminates itself. You could echo the output of ps -aux or pstree to a log file while running your script during boot time to discover this. What if you switch manually to runlevel 5 once the system is booted? Is your script being executed correctly? I think that switching runlevels is also performed by init, isn't it? If not, for sure init blocks something during execution. Have you tried to do a umount -f /dev/yourdisk in your script before calling fdisk? Have you tried to perform the boot-up on a completely empty disk (dd put 512 zeroes in the mbr?) jlinkels |
Quote:
Quote:
Quote:
Quote:
I am sure that you are correct that init is performing the task whether manually invoked or not Quote:
Quote:
I have a suspicion that this is just one of those things and that maybe the script is being run fine in both occurrences. I am thinking that if I script in a reboot for when the 'drive or resource' is busy that this may solve the problem. At first, the script always worked when run manually, however with all the testing I have been doing lately, I have seen it fail manually quite often. Perhaps this situation is more likely to happen early in the booting process? It would be nice to know why the kernel is locking the drive out, and how to get around it without a reboot. but at present, its the only solution i can think of. Again, thank you for your time and direction on this. |
All times are GMT -5. The time now is 03:14 PM. |