简体   繁体   English

复制Linux liveUSB会导致init.d脚本出错

[英]Copy Linux liveUSB causes errors with init.d scripts


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. 当我安装一个编写为通过/etc/init.d/在后台启动时运行的简单Java应用程序时,它可以在我明确安装了该应用程序的liveUSB上运行。 When I make a copy of that stick, it never boot successfully. 当我复制该记忆棒时,它永远无法成功启动。 When booting the liveUSB copy the Java application will always hang when the liveUSB boot process reaches my script. 当启动liveUSB复制时,当liveUSB启动过程到达我的脚本时,Java应用程序将始终挂起。 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. 我的脚本,即使每5分钟也能完全执行一次应做的工作,并且会一直运行直到您关闭计算机电源为止。

  1. My script is blocking everything else 我的脚本阻止了其他所有内容
  2. Nothing loads beyond my script 除了我的脚本外,什么都没有
  3. You cannot cancel my script 你不能取消我的剧本
  4. There is no GUI 没有GUI
  5. 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. 我有一个带有3个分区的Linux liveUSB。 Simple standard Xubuntu image is loaded. 简单的标准Xubuntu图像已加载。

  • sda1 > 2gb stoage sda1> 2GB存储
  • sda2 > 2gb system sda2> 2GB系统
  • sda3 > remaining gb for casper sda3>卡斯伯剩余的gb

I have created a simple Java application that runs in the background on start up. 我创建了一个简单的Java应用程序,该应用程序在启动时在后台运行。 To get this far, I followed these steps: 为了做到这一点,我遵循以下步骤:

  1. Compiled java application into classes 将Java应用程序编译成类
  2. Placed class files in /home/user/folder/ 将类文件放在/ home / user / folder /
  3. Copied my startup.sh script into /etc/init.d/ 将我的startup.sh脚本复制到/etc/init.d/
  4. While inside /etc/init.d/ 在/etc/init.d/中
    • Typed "update-rc.d startup.sh start 20 2 5 . stop 20 0 1 6 ." 键入“ update-rc.d startup.sh start 20 2 5。stop 20 0 1 6。”
    • This updated run levels successfully 此更新的运行级别成功
  5. 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: 创建此棍子的副本时,请按照以下步骤操作:

  1. Mount sda2 装载sda2
    • copy everything from that folder to /home/user/Desktop/tmp-system/ 将所有内容从该文件​​夹复制到/ home / user / Desktop / tmp-system /
  2. Mount sda3 装载sda3
    • copy everything from that folder to /home/user/Desktop/tmp-casper/ 将所有内容从该文件​​夹复制到/ home / user / Desktop / tmp-casper /
  3. Go into /home/user/Desktop/tmp-system/ 进入/ home / user / Desktop / tmp-system /
    • Type "tar -cvf system.tar ." 键入“ tar -cvf system.tar”。
  4. Go into /home/user/Desktop/tmp-casper/ 进入/ home / user / Desktop / tmp-casper /
    • Type "tar -cvf casper.tar ." 键入“ tar -cvf casper.tar”。
  5. Umount 数量
    • sda2 sda2
    • sda3 sda3
  6. Plug in empty USB (sdb for example) 插入空的USB(例如sdb)
    • Set up partitions (Same as the stick you are copying from) 设置分区(与要复制的存储棒相同)
    • Untar into partitions 解压到分区
      • tar -xvf system.tar ... into sdb2 tar -xvf system.tar ...进入sdb2
      • tar -xvf casper.tar ... into sdb3 tar -xvf casper.tar ...进入sdb3

Testing - Here's where everything goes wrong! 测试 -这就是所有出错的地方!


  1. Plug in newly created liveUSB into a computer 将新创建的liveUSB插入计算机
  2. Boot from USB 从USB启动
  3. Everything starts to boot fine 一切开始正常
  4. Java application that I wrote gets triggered 我编写的Java应用程序被触发
    • Boot process hangs forever 引导过程永远挂起
    • No cmd prompt available 没有可用的cmd提示
    • NO GUI available 没有可用的GUI
    • 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) 就像线程正在运行一样(而且是这样!每5分钟可以查看一次输出-正是这种方式)

Solution Attempts & Gotchas 解决方案尝试和陷阱


1 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?). 我可以挂载复制的liveUSB,然后编辑startup.sh以不启动我的Java应用程序,并且它仍然不会启动(就像我怀疑的那样?)。


2 2

If I use "dd if=sda of=sdb" the copy of the liveUSB will work perfectly fine. 如果我使用“ dd if = sda of = sdb”,则liveUSB的副本将正常运行。 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. 如果我将带有dd的16GB记忆棒复制到64GB记忆棒,那会将64GB记忆棒变成16GB。


3 3

Tested many variations of startup.sh and the Java application itself. 测试了startup.sh和Java应用程序本身的许多变体。 All of which produce the same error. 所有这些都会产生相同的错误。


4 4

The method I am using to copy works for every other form of application, file or anything else. 我用来复制的方法适用于其他形式的应用程序,文件或其他任何形式。


5 5

I would also like to try and avoid using any additional libraries or programs to help run the Java application. 我也想尝试避免使用任何其他库或程序来帮助运行Java应用程序。

What you might better do is to use a method to quickly create a liveUSB Linux stick, then add the Java program settings and directories. 您最好做的是使用一种方法快速创建一个liveUSB Linux记忆棒,然后添加Java程序设置和目录。 Here is some help - Bootable pendrive as live cd 这是一些帮助- 可将Pendrive启动为Live CD

I definitely like point number 1 that you mention. 我绝对喜欢您提到的第一点。 Copy liveUSB even without the Java program does not work. 即使没有Java程序,也无法复制liveUSB。 You have spent quite some time to debug that program. 您已经花了很多时间来调试该程序。 I have the feeling that you are interested in making many liveUSB with the Java program installed. 我觉得您对安装Java程序制作许多liveUSB感兴趣。 Since dd is not an option, my guess is that it's more meaningful to somehow use a Kickstart procedure for quick LiveUSB installations and then copy the Java things. 由于dd不是一个选项,因此我想对于以某种方式使用Kickstart过程进行快速LiveUSB安装并复制Java东西更有意义。 Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM