Please post your thoughts ideas or anything you may come up with. I would be very interested to see what anybody else is thinking.
The Overall Problem
When I install a simple Java application (that I wrote) to run on boot (in the background) through /etc/init.d/, it works on the liveUSB that I explicitly install it on. When I make a copy of that stick, it never boots successfully. When booting the liveUSB copy the Java application will always hang when the liveUSB boot process reaches my script. My script, which does do exactly what it is supposed to do, even every 5 minutes and will continue running forever until you power down the machine.
- My script is blocking everything else
- Nothing loads beyond my script
- You cannot cancel my script
- There is no GUI
- The only text you can see is the command line output from my script
Setup & Test - Everything goes well :)
I have a Linux liveUSB with 3 partitions. Simple standard Xubuntu image is loaded.
- sda1 > 2gb stoage
- sda2 > 2gb system
- sda3 > remaining gb for casper
I have created a simple Java application that runs in the background on start up. To get this far, I followed these steps:
- Compiled java application into classes
- Placed class files in /home/user/folder/
- Copied my startup.sh script into /etc/init.d/
- While inside /etc/init.d/
- Typed "update-rc.d startup.sh start 20 2 5 . stop 20 0 1 6 ."
- This updated run levels successfully
- Now I can restart / reboot / shutdown whatever operation and everything runs perfectly!
The Copy - Here's where it gets tricky!
When creating a copy of this stick, I follow these steps:
- Mount sda2
- copy everything from that folder to /home/user/Desktop/tmp-system/
- Mount sda3
- copy everything from that folder to /home/user/Desktop/tmp-casper/
- Go into /home/user/Desktop/tmp-system/
- Type "tar -cvf system.tar ."
- Go into /home/user/Desktop/tmp-casper/
- Type "tar -cvf casper.tar ."
- Umount
- sda2
- sda3
- Plug in empty USB (sdb for example)
- Set up partitions (Same as the stick you are copying from)
- Untar into partitions
- tar -xvf system.tar ... into sdb2
- tar -xvf casper.tar ... into sdb3
Testing - Here's where everything goes wrong!
- Plug in newly created liveUSB into a computer
- Boot from USB
- Everything starts to boot fine
- Java application that I wrote gets triggered
- Boot process hangs forever
- No cmd prompt available
- NO GUI available
- It is as if the thread is running (and it is! The output can be viewed every 5 minutes - which is exactly the way it should be)
Solution Attempts & Gotchas
1
I can mount the copied liveUSB, edit the startup.sh to not start my Java application and it will still not boot (just as I suspected?).
2
If I use "dd if=sda of=sdb" the copy of the liveUSB will work perfectly fine. However this is not an acceptable solution. If I were to copy a 16gb stick with dd to a 64gb stick, that would turn the 64gb stick into a 16gb. It would also make it much more difficult to change the values that need to be changed in each partition.
3
Tested many variations of startup.sh and the Java application itself. All of which produce the same error.
4
The method I am using to copy works for every other form of application, file or anything else.
5
I would also like to try and avoid using any additional libraries or programs to help run the Java application.
6
I have also mounted sda2 & sdb2 used cp to copy everything directly from one to the other, then followed the same for sda3 & sdb3. This produces the same error.
ADDITIONAL POINTS
- The sda3 partition is encrypted with cryptsetup
- There are 2 files in the system.tar (which will be sdb2, came from sda2) that will have a value changed after it has been written to the USB.
- These two values have not caused any problems in the past and have always been changed every time a new liveUSB is created
- There is 1 file in the casper.tar (which will be sdb3, came from sda3) that will have a value changed after it has been written to the USB.
- This value has not caused any problems in the past and has always been changed with every new liveUSB created.
Checksum Testing Process
Orignial liveUSB image
Working liveUSB > sda empty usb > sdb
Steps:
- Mount, copy & checksum sda2
- Typed "mount /dev/sda2 /media/sda2"
- Typed "tar -C /media/sda2 -cvf ~/Desktop/system.tar ."
- Typed "find . -type f -exec sha1sum {} ';' > /tmp/sda2_checksum.txt"
- Typed "umount /media/sda2"
- Mount, copy & checksum sda3
- Typed "mount /dev/sda3 /media/sda3"
- Typed "tar -C /media/sda3 -cvf ~/Desktop/casper.tar ."
- Typed "find . -type f -exec sha1sum {} ';' > /tmp/sda3_checksum.txt"
- Typed "umount /media/sda3"
- Create partitions for sdb
- Mount, write & checksum sdb2
- Typed "mount /dev/sdb2 /media/sdb2"
- Typed "tar -C /media/sdb2 -xvf ~/Desktop/system.tar"
- Typed "find . -type f -exec sha1sum {} ';' > /tmp/sdb2_checksum.txt"
- Typed "umount /media/sdb2"
- Mount, write & checksum sdb3
- Typed "mount /dev/sdb3 /media/sdb3"
- Typed "tar -C /media/sdb3 -xvf ~/Desktop/casper.tar"
- Typed "find . -type f -exec sha1sum {} ';' > /tmp/sdb3_checksum.txt"
- Typed "umount /media/sdb3"
- Compare checksums
- sort /tmp/sda2_checksum.txt -o /tmp/sda2_checksum.txt.sort
- sort /tmp/sda3_checksum.txt -o /tmp/sda3_checksum.txt.sort
- sort /tmp/sdb2_checksum.txt -o /tmp/sdb2_checksum.txt.sort
- sort /tmp/sdb3_checksum.txt -o /tmp/sdb3_checksum.txt.sort
- Results
sda2 & sdb2
Typed "diff sda2_checksum.txt.sort sdb2_checksum.txt.sort"
45d44
< 2ddf9802c9c15ac6e4575cc9de32e3530eae6b7d ./efi/boot/grub.cfg
82d80
< 59bb2775a8e7e499e0590b7b8c2492eb250fb7d8 ./syslinux/txt.cfg
154a153
> ae6c127713e01fc5fb4a2e4e28f6bbddc6bd6af5 ./efi/boot/grub.cfg
158a158
> b78090b66b4e3fa04ca9d466ee78c9060adf744e ./syslinux/txt.cfg
These 2 files contain 1 value in each that gets changed. Everything else is the same. The results are exactly what they should be.
sda3 & sdb3
Typed "diff sda3_checksum.txt.sort sdb3_checksum.txt.sort"
Identical - Keep in mind this is the original liveUSB image.
I will post further comparison results as I work through the next section.
NEXT STEPS - aka Action Plan
Starting from liveUSB image without the scripts that need to be run.
Step 1 - Success / Fail ?
SUCCESS - checksums match as they should
- Update java on liveUSB from 6 to 7
- Recreate tar's
- Create new liveUSB from tar's
- Test liveUSB
Step 2 - Success / Fail ?
SUCCESS - checksums match as they should
- Create /home/user/folder/
- Copy class files for java application into /home/user/folder/
- Recreate tar's
- Create new liveUSB from tar's
- Test liveUSB
Step 3 - Success / Fail ?
SUCCESS - checksums match as they should
- Add startup.sh into /etc/init.d/
- Without calling update-rc.d
- Recreate tar's
- Create new liveUSB from tar's
- Test liveUSB
Step 4 - Success / Fail ?
SUCCESS - checksums match as they should
(I have never made it this far successfully before) - however the value that needs to written has not been inserted into the casper (sda3) partition yet.
- Type "update-rc.d startup.sh start 21 2 5 ."
- Recreate tar's
- Create new liveUSB from tar's
- Test liveUSB
Step 5 - Success / Fail ?
SUCCESS - checksums match as they should
I can't believe this worked! Which brings me to... (To word this in a nice way) Why the world was it not working before?
-coincidently it was Version-13 that worked.
- Boot liveUSB
- Insert value to be over-written in casper (sda3) before creating tar
- While running from liveUSB
- Edit config file in /home/user/folder/config.properties
- Shutdown liveUSB
- Recreate tar's
- Create new liveUSB from tar's
- Test liveUSB
IMAGE COMPLETE!!
I'm not finished with this just yet!
*The process of writing to the usb has never changed.
Why did it not work before?
- Tar method? - Only a slight change...
- From "tar -cvf casper.tar ."
- TO "tar -C /media/sda3/ -cvf ~/Desktop/casper.tar .
- Are these lines not accomplishing the same thing?
- I will be testing this out shortly down the road. - I suspect no difference.
- Cut up the procedure into individual steps?
- Before:
- Under the NEXT STEPS - aka Action Plan I would complete all of these steps before making a new image.
- After:
- The NEXT STEPS - aka Action Plan was followed exactly
- Could this be the difference?
- I will be testing this out shortly down the road.
- Before:
- Can deleting large (or small) files from the /home/ directory in the casper (sda3) partition cause some sort of corruption?
- I have no idea..?
- I will be testing this out shortly down the road.
Further Testing - I want my answer!
Starting from the original liveUSB image.
- Update java on liveUSB from 6 to 7
- Create /home/user/folder/
- Copy class files for java application into /home/user/folder/
- Add startup.sh into /etc/init.d/
- Type "update-rc.d startup.sh start 21 2 5 ."
- Edit config file in /home/user/folder/config.properties
All at once step this time. - Will it work?
Test 1 - Success / Fail ?
FAIL!
- Old tar method
Test 2 - Success / Fail ?
- Old tar method
- Deleted generated file in /boot/
- This file is created by my script when the casper (sda3) partition gets written, contains only an id for verification has no effect on the boot process.
Test 3 - Success / Fail ?
- New tar method
Test 4 - Success / Fail ?
- New tar method
- Deleted generated file in /boot/
- This file is created by my script when the casper (sda3) partition gets written, contains only an id for verification has no effect on the boot process.
Results
I will be testing in this order:
Test 1 -> Test 3 -> Test 4 -> Test 2
If Test 1 works... I will go jump out of the window! - I will have no idea why it would be working now as I have tested this many times and every time has yielded unsuccessful boots. - Perhaps the cp or tar process was corrupted somehow.
When test 1 fails: If Test 3 works... - The tar method was causing the error. - I don't understand what would be wrong with the old tar method vs the new tar method.
TBC...