Копирование Linux liveUSB вызывает ошибки в скриптах init.d - Невозможно ..?
492
Mr. H. Dumpty
Пожалуйста, опубликуйте свои мысли, идеи или что-нибудь, что вы можете придумать. Мне было бы очень интересно посмотреть, что кто-нибудь еще думает.
Общая проблема
Когда я устанавливаю простое Java-приложение (которое я написал) для запуска при загрузке (в фоновом режиме) через /etc/init.d/, оно работает на liveUSB, на котором я его явно устанавливаю. Когда я делаю копию этой флешки, она никогда не загружается успешно. При загрузке копии liveUSB приложение Java всегда будет зависать, когда процесс загрузки liveUSB достигает моего сценария. Мой сценарий, который делает именно то, что он должен делать, даже каждые 5 минут и будет работать вечно, пока вы не выключите машину.
Мой сценарий блокирует все остальное
Ничто не загружается за пределы моего сценария
Вы не можете отменить мой скрипт
Нет графического интерфейса
Единственный текст, который вы видите, это вывод командной строки из моего скрипта
Настройка и тестирование - все идет хорошо :)
У меня Linux liveUSB с 3 разделами. Простое стандартное изображение Xubuntu загружается.
sda1> 2 Гб хранения
sda2> 2 Гб система
sda3> Осталось гб за каспера
Я создал простое Java-приложение, которое запускается в фоновом режиме при запуске. Чтобы получить это далеко, я следовал за этими шагами:
Скомпилированное Java-приложение в классы
Размещенные файлы классов в / home / user / folder /
Теперь я могу перезапустить / перезагрузить / выключить любую операцию, и все работает отлично!
Копия - вот где это становится сложно!
При создании копии этой флешки я выполняю следующие шаги:
Гора sda2
скопируйте все из этой папки в / home / user / Desktop / tmp-system /
Гора sda3
скопируйте все из этой папки в / home / user / Desktop / tmp-casper /
Зайдите в / home / user / Desktop / tmp-system /
Введите "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.
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.
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...
2 ответа на вопрос
2
Nanzikambe
Given your description of the problem I suspect something other than you describe is happening. In any case, try this:
# sda2 mount /dev/sda2 /mnt/tmp tar -C /mnt/tmp -cf ~/Desktop/sda2.tar . umount /dev/sda2 # ... repeat for sda3 ... # do your create partition shenanigans mount /dev/newsda2 /mnt/tmp tar -C /mnt/tmp -xpf ~/Desktop/sda2.tar umount /dev/newsda2 # repeat ... # test ..
If that works then chances are your /home is mounted noexec or is some fubar'ed filesystem because the problem was the execute bit being removed.
If it doesn't work, edit your start up script to give you debug info such as the output of mount, content of syslog etc and look for help there.
You could also generate checksums for every file and compare copy vs original with:
find . -type f -exec sha1sum {} ';' > /tmp/sda2_checksums.txt
for each mounted partition & diff the /tmp/*_checksums.txt files
Это было очень полезно для тестирования. Большое спасибо! Я буду обновлять информацию о достигнутом прогрессе и результатах сравнений контрольных сумм. Еще раз спасибо
Mr. H. Dumpty 11 лет назад
0
Новый метод tar, похоже, делает свое дело. Я до сих пор удивляюсь, почему мой старый метод выдает эту ошибку. Я заглянул в папку / home и не могу найти никакой разницы. Я буду продолжать искать и держать всех в курсе.
Mr. H. Dumpty 11 лет назад
0
0
Tom
In response to Solution Attempts & Gotchas #2 regarding the use of the dd command:
Using the dd command to clone the original Live USB does not permanently turn the 64gb stick into a 16gb stick. It will do that only if you choose not to repartition the 64gb stick after using the dd command. You can resize the parition to recover all of the remaining free (unallocated) space left on the 64gb stick after using the dd commmand.
You can revise the partitions by using one of either GParted or Parted Magic partition editors to recover any amount of free space from 16GB to 64GB on the cloned USB flash drive after using the dd command.
The net effect is that the dd command does not permanently turn the 64gb stick into a 16gb stick by using either GParted or Parted Magic after launching the dd command to reclaim the remainder of the 64gb stick.
Use the Linux Disk Utility program for your Linux distribution to verify the partition space as free or allocated.
Information about Parted Magic can be found at: https://en.wikipedia.org/wiki/PartedMagic but in my experience I would recommend GParted as Parted Magic was a full distribution of tools unless you prefer the later approach from what you find out about it.
In short, you have already discovered the easiest solution to your problem, which is just a resized partition away if none of the tests you planned at the end of your posts work.