I have a very light/occasional use computer which recently had boot problems following a power cut, resulting in a day's work fiddling around trying to fix it and eventually needing a re-install.
Are there any settings I can adjust to make (k)ubuntu more tolerant of power cuts? I am thinking of less disk write buffering at the expense of performance, no background cleanup tasks, things like that. My aim would be to be able to cut the power harmlessly if the computer has been sitting showing the desktop but doing "nothing" for 10 mins. (I realise it is not really nothing!)
I can't justify the expense of a UPS in this situation, it is just an old computer displaying the output of a USB microscope.
kubuntu 18.04.
No. A power cut is what it is.
Unless there is an actual hardware related problem (like a broken disk, or fried connectors) this should not have been needed. Without the actual notices you got it is going to be impossible to actually tell you where you went wrong. Sometimes a filesystem check is needed after a loss of power but that is incorporated into the boot process to happen automatically.
That is the default: turning off the power of a machine is a hardware thing not software. Only issue you can have is that some things did not get saved to disk but that is no reason for the OS to need to be reinstalled.
I would suggest to take a little risk and cutting the power of that machine and see what happens, and then report the issues you face.
In theory, if your linux is properly configured you should not have boot problems after a power cut. The worst case is you will have lost data but the OS image and services should not be affected.
However, this only works if you use a journaled filesystem such as Ext3/Ext4, ReiserFS, Btrfs, JFS, XFS etc. The first thing I'd do is check to make sure you're not loading your boot partition as Ext2. Note that Ext2 and Ext3 uses exactly the same on-disk data structure so to migrate from Ext2 to Ext3 all you need to do is change the filesystem driver.
Theory, meet reality
However, theory and reality sometimes don't agree. There are a bunch of corner cases that theory don't handle.
Some magnetic hard disks can be damaged if power is abruptly cut off. Normally modern hard disks (after 1990s) are manufactured to avoid this condition but then again in theory they do but in practice theory don't always work.
If you're using SSD then some SSD firmware are known to cause disk corruption in some corner cases when power is abruptly lost. It is rare to see this happen in the PC world but is a not uncommon complaint of expensive Red camera users. In fact Red memory cartridges come with a data recovery service by Red because of this issue - which has not been necessary in the PC world. Then again, if it can happen then it can happen no matter how unlikely.
You can mitigate boot corruption issues by doing one or someof the following:
Boot from a solid-state disk. It is far less likely for a solid state disk to be corrupt than a magnetic disk (no fast spinning disk reduces a lot of risk). You don't need to go the expensive route and get an SSD. A thumb drive will do just fine. The additional advantage of booting from a thumb drive is you can clone the drive and keep a backup copy of your boot disk in case anything goes wrong.
Boot from a read-only disk. If you have a CD or DVD drive you can burn your OS on a CD/DVD and boot from that. It's hard to damage something you cannot write to.
Use a Linux distro that doesn't write to disk. There's quite a few distros out there that run completely in RAM and avoid writing to disk. Some were created to make it possible to boot form CD. Some were created for embedded systems that don't have a lot of storage. Because the OS itself don't write to disk it is less likely that stopping the disk will damage the OS. You can still mount your disk and read and write to it for your own data. It's just the OS itself by default will minimize its own disk I/O
Get an "Uninterruptible Power Supply" or "UPS", like this.
This is basically a large battery, you plug your computer into. When a power outage, brownout, blackout or spike happens, the battery takes over and supplies your compute with good quality electricity for (depending how large of a UPS you buy) up to 15 minutes or more. This allows your computer to stay powered during a temporary outage, or give you time to do a proper shutdown.
Some UPS systems even have the ability to trigger an automatic safe shutdown of your computer once they kick in.
Use Ext4 and
rootflags=data=journal
boot parameter.This journals the DATA too (normally only the metadata is journaled, but data can be corrupted).
Enabling this flag makes your write performance slower as data has to be written to disk twice. But it's a good tradeoff.
Depends on your filesystem, but you can use the
sync
flag when mounting (beware, this will kill your performance!). Lighter, and actually usable alternative isdirsync
. Typingsync
when you know you are going away for a few minutes (thus hibernating the computer is cumbersome) won't hurt, either.Other options include using
busybox-syslogd
instead of regular syslog (keeps the log in memory), moving/tmp
and/var/tmp
totmpfs
(if you have enough RAM), moving/home
to separate partition (and mounting at least/
with thesync
flag), disabling disk cache in your browser.Use following partition scheme (either use GPT or extended msdos partitions):
/
4GiB/boot/
512MiB/boot/efi/
512MiB (if needed)/home/
whatever you need, otherwise at least 2GiB/opt/
whatever you need, otherwise at least 1GiB/srv/
whatever you need, otherwise at least 1GiB/tmp/
minimum 2GiB/usr/
minimum 8GiB/usr/local/
minimum 8GiB/var/
minimum 6GiB/var/log/
1GiB - 2GiB/var/tmp/
minimum 2GiBAll partitions are ext4 filesystems (
/boot/efi/
is vfat) and mounted with noatime mount-option./tmp/
and/var/tmp/
may be mounted with relatime mount-option instead./boot/efi/
should be mounted with flush (vfat) mount-option./
,/boot/
and/boot/efi/
should get fsck priority1
in your fstab, all other should get2
.Use following command to move the ugly
/snap
to where it belongs (it belongs into/usr/local/
).This should give you a robust Linux filesystem. The root-fs
/
will be only round about 100MiB big (without root-homedir/root/
), easy to backup.PS a SWAP partition is also always nice to have