意外的關機怎麼會對linux計算機造成傷害?

意外關閉對Linux的危害是否和對其他作業系統的危害一樣大?請繼續閱讀,我們將研究災難性系統關閉對Linux檔案系統的影響。...

意外的關機怎麼會對linux計算機造成傷害?

意外關閉對Linux的危害是否和對其他作業系統的危害一樣大?請繼續閱讀,我們將研究災難性系統關閉對Linux檔案系統的影響。

今天的問答環節是由SuperUser提供的,SuperUser是Stack Exchange的一個分支,是一個由社群驅動的問答網站分組。

問題

超級使用者讀者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?

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.

判決結果如何?

答案

SuperUser contributor l0b0提供了對日誌/非日誌檔案系統的一些見解:

This would depend on

  1. whether you’re using a journaling file system and
  2. how well the applicati*** are able to handle aborted processing.

C***ider 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.

斯圖建議將作業系統和資料分離,並增加一個備用電池:

To help minimise the possibility of OS corruption, it’s probably best to have separate “system” and “data” partiti*** on the SD card. That way you can mount the “system” partition read-only and use a highly-resilient FS on the “data” partition.

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.

最後,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 ********* info that l0b0 linked, you may be interested in Do Journaling Filesystems Guarantee Against Corruption After a Power Failure as well.

You as a programmer obviously need to c***ider 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.


有什麼要補充的解釋嗎?在評論中發出聲音。想從其他精通技術的Stack Exchange使用者那裡瞭解更多答案嗎?在這裡檢視完整的討論主題。

 

  • 發表於 2021-04-11 17:49
  • 閱讀 ( 39 )
  • 分類:網際網路

你可能感興趣的文章

虛擬機器(virtual machine)和伺服器(server)的區別

...服器、web伺服器、資料庫伺服器等等。虛擬機器和伺服器的關鍵區別在於,虛擬機器是一種類似於物理計算機的軟體,可以執行作業系統和相關應用程式,而伺服器是一種裝置或軟體,可以提供網路中其他計算機或客戶機請求的...

  • 發佈於 2020-10-19 14:47
  • 閲讀 ( 49 )

雙引導作業系統的10個風險

... 2意外覆蓋資料/os ...

  • 發佈於 2021-03-11 01:07
  • 閲讀 ( 59 )

每個作業系統如何保證您的安全

...樣做的。RAM是一種臨時儲存器(任何發生在其中的事情在關機時都會被擦除),它可以讓資料非常快速地被寫入和讀取。當應用程式啟動時,作業系統允許它訪問此資源的一部分以執行。 ...

  • 發佈於 2021-03-12 11:26
  • 閲讀 ( 42 )

不,linux不需要防病毒或防火牆

...的所有者組可以對此檔案做什麼? 其他人怎麼處理這個檔案? ...

  • 發佈於 2021-03-12 20:15
  • 閲讀 ( 51 )

如何關閉windows10:7提示和技巧

... 如果您需要更多的關機建議,請檢視我們的文章,瞭解Windows可以在關機時自動清除的內容。 ...

  • 發佈於 2021-03-13 03:25
  • 閲讀 ( 43 )

電源迴圈之謎:硬重啟危險嗎?

...啟)是當你按下電源按鈕,這將耗盡主機板某些部分儲存的關鍵電力。當電力完全耗盡時,主機板會失去電源,其所有元件都會關閉。當您釋放電源按鈕,關鍵的電力充電和主機板恢復其功能,在這一點上,您可以按電源按鈕再...

  • 發佈於 2021-03-14 15:31
  • 閲讀 ( 45 )

從命令列關閉linux計算機的5種方法

... 透過輸入-c cancel命令可以取消任何計劃的關閉或重新啟動: ...

  • 發佈於 2021-03-14 17:35
  • 閲讀 ( 44 )

為什麼windows會崩潰?故障排除指南

... 本文將重點討論什麼是意外的計算機崩潰以及如何識別問題。計算機崩潰的發生有多種原因。對於普通的PC使用者來說,PC崩潰通常被視為PC損壞或損壞的跡象。在現實中,PC機的關閉很少值得擔...

  • 發佈於 2021-03-17 13:14
  • 閲讀 ( 57 )

你的mac電腦一直隨機關機?這是你能做的

...但如果你面對的是一臺習慣性地在沒有任何警告的情況下關機的電腦,你可能會遇到更大的問題。下面是一些故障排除技巧和工具,幫助您修復Mac。 ...

  • 發佈於 2021-03-22 13:46
  • 閲讀 ( 55 )

什麼是linux beta版,您應該試試嗎?

...於損壞硬碟上資料的錯誤,或者系統崩潰導致程式無法在關機前儲存資料。 ...

  • 發佈於 2021-03-23 09:59
  • 閲讀 ( 43 )