linux 关机 关机_意外关机如何危害Linux计算机?
linux 关机 关机
Are unexpected shutdowns as harmful to Linux as they are to other operating systems? Read on as we investigate the effects of catastrophic system shutdowns on Linux file systems.
意外关闭是否对Linux和对其他操作系统一样有害? 在我们研究灾难性系统关闭对Linux文件系统的影响时,请继续阅读。
Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.
今天的“问答”环节由SuperUser提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。
问题 (The Question)
SuperUser reader User208554 is curious about Linux file structures and concerned about an app/installation he’s working on:
超级用户阅读器User208554对Linux文件结构感到好奇,并担心他正在从事的应用/安装:
I am developing an application on a Linux embedded board (runs Debian) e.g. Raspberry Pi, Beagle Board/Bone, or olimex. The boards works on an environment that the electricity is cut unexpectedly (it is far too complicated to place PSU, etc.) and it would happen every day a couple times. I wonder if the unexpected power cuts would cause problem on the Linux Operation System? If it is something that I should worry about, what would you suggest to prevent the damages on OS against the unexpected power cuts?
我正在Linux嵌入式板上(运行Debian)开发应用程序,例如Raspberry Pi,Beagle Board / Bone或olimex。 这些板的工作环境是意外断电(放置PSU等过于复杂),并且每天都会发生几次。 我想知道意外的断电是否会导致Linux操作系统出现问题? 如果这是我应该担心的事情,您将建议采取什么措施来防止意外停电对操作系统造成损害?
PS. The application needs to writes some data to the storage medium (SD card), I think it would not be suitable to mount it as read-only.
PS。 该应用程序需要将一些数据写入存储介质(SD卡),我认为将其安装为只读状态不适合。
So what’s the verdict?
那么判决是什么?
答案 (The Answer)
SuperUser contributor l0b0 offers some insight into journaling/non-journaling file systems:
超级用户贡献者l0b0提供了一些有关日志记录/非日志记录文件系统的见解:
This would depend on
这取决于
whether you’re using a journaling file system and
是否使用日记文件系统以及
- how well the applications are able to handle aborted processing.应用程序处理中止处理的能力。
Consider for example an application which processes a file and writes the results as they are computed (one output line per input line) to another file. If the power is cut during processing, and the same application is run after restarting, it can’t just restart processing from the start of the input file – that would mean the output file would contain duplicate information.
例如,考虑一个应用程序,该应用程序处理文件并将计算结果(每条输入行一个输出行)写入到另一个文件中。 如果在处理过程中断电,并且在重新启动后运行同一应用程序,则它不能只是从输入文件的开头重新开始处理–这意味着输出文件将包含重复的信息。
It could be very difficult to say anything definite about a hypothetical complex system, but most stable Linux software seems to be able to handle crashes quite nicely.
很难说出一个假设的复杂系统的任何东西,但是大多数稳定Linux软件似乎都能很好地处理崩溃。
Stu suggests separating the operating system and data, as well as adding a battery backup:
Stu建议分离操作系统和数据,并添加备用电池:
To help minimise the possibility of OS corruption, it’s probably best to have separate “system” and “data” partitions on the SD card. That way you can mount the “system” partition read-only and use a highly-resilient FS on the “data” partition.
为了最大程度地减少操作系统损坏的可能性,最好在SD卡上具有单独的“系统”和“数据”分区。 这样,您可以以只读方式挂载“系统”分区,并在“数据”分区上使用高弹性的FS。
Additionally, most of those boards have very low power requirements, so a battery backup is possible. The “LiPo rider” board for the Raspberry Pi can be used as a basic UPS to provide a clean shutdown on power loss.
此外,大多数这些板的电源需求非常低,因此可以备用电池。 Raspberry Pi的“ LiPo rider”板可用作基本UPS,以提供干净的断电关机功能。
Finally, Jenny D expands on the journaling file system suggestion:
最后,Jenny D扩展了日记文件系统的建议:
Unexpected power cuts may cause corruption of file system data – e.g. if a process has started writing to a file, but not yet finished writing it, the file may end up only half written. Now imagine if the power cut happens when you’re half way through a kernel upgrade…
意外的断电可能会导致文件系统数据损坏–例如,如果某个进程已开始写入文件,但尚未完成写入,则该文件可能只写入一半。 现在想象一下,在您完成内核升级一半时是否发生了断电……
As l0b0 wrote, using a journaling file system will help, since it will be able to keep track of what has actually gotten done. In addition to the wikipedia info that l0b0 linked, you may be interested in Do Journaling Filesystems Guarantee Against Corruption After a Power Failure as well.
正如l0b0所写,使用日记文件系统将有所帮助,因为它将能够跟踪实际完成的工作。 除了l0b0链接的Wikipedia信息之外,您可能还会对“日志文件系统在电源故障后保证不会损坏”感兴趣。
You as a programmer obviously need to consider carefully how to handle writing to files so that it becomes an atomic process (i.e. it’s either fully done or not done at all, but never ever half done). It’s a fairly complex issue.
作为程序员,您显然需要仔细考虑如何处理对文件的写入,以使其成为一个原子过程(即,它要么完全完成,要么根本没有完成,但永远不会完成)。 这是一个相当复杂的问题。
Have something to add to the explanation? Sound off in the the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.
有什么补充说明吗? 在评论中听起来不对。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程。
翻译自: https://www.howtogeek.com/166808/how-can-unexpected-shutdowns-harm-a-linux-computer/
linux 关机 关机