Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a question about something that always bothered me about Linux. On Windows, if any of the system files become damaged, you can just reinstall the system files, without having to re-format your disk,which is a great option. Is there anything similar on Linux?

I run a Raspbian Distro on my Raspberry Pi, and my system became damaged AGAIN, after another power cut. It was running a Netatalk server working as a TimeMachine for Mac. After a power cut, system would not boot, I had to run fsck.ext4 on the filesystem manually to fix it - and it had a LOT of errors to fix. After running that, the system would boot, but there are strange errors around - it does not know the name of the machine, so it appears as pi@(unknown), some basic system programs like ls or sudo give me "permission denied" errors, I have plugged in the card to another computer and manually set the right permissions on sudo, but now when I run it it gives me "Segmentation Fault" error, so the file is clearly damaged.

Now my point is - it would be a lot of pain to reinstall everything again. Is there an option to fix it by reinstalling all system files without breaking all of my custom setup for netatalk?

share|improve this question
In 12+ years of using linux in a variety of settings I can't say I've run into this such that fsck didn't fix it easily except when the disk was bad, so ask around on irc or an RPi forum if it is common there, maybe something to do with using an sdcard. – goldilocks Jan 20 '13 at 14:53
Since this is the second time exactly same thing happened - a power cut, resulting in a severe damage to the filesystem, I guess it's because there's some caching going on and not everything is written to the SD card when it should be. – gambiting Jan 20 '13 at 15:45
For sure there is caching by way of which you can lose information and end up with inconsistencies in application data, but not with an unbootable system or have the hostname screwed up; that implies genuine widespread corruption. ext4's journalling performance enhancements apparently make it more susceptible to errors on power failure than ext3 (see section 3.2: halfgaar.net/why-power-failures-are-bad-for-your-data) but I still don't think that should impact key parts of the system which are read from and not written to; I could be wrong. – goldilocks Jan 20 '13 at 16:02
Be careful with SD cards, flash memory can wear fast (limited amount of write cycles per cell), especially bad quality memory. Your corruption might come from your (old?) SD card. – Totor Mar 30 '13 at 15:06
Consider also: turning on journalling; separate partitions for OS, configuration and user data; mounting (as much as possible) readonly. – richard Jan 1 at 1:40

I'd give either apt or aptitude a try if the distro is Debian/Ubuntu based.

For Redhat based distros such as CentOS/Fedora/RHEL you can use RPM to verify and repair some aspects of the installed packages.

verify all pkgs

% rpm -qVav
.........    /usr/bin/rdesktop
.........    /usr/share/doc/rdesktop-1.6.0
.........  d /usr/share/doc/rdesktop-1.6.0/AUTHORS
.........  d /usr/share/doc/rdesktop-1.6.0/COPYING
.........  d /usr/share/doc/rdesktop-1.6.0/ChangeLog
.........  d /usr/share/doc/rdesktop-1.6.0/HACKING
.........  d /usr/share/doc/rdesktop-1.6.0/README
.........  d /usr/share/doc/rdesktop-1.6.0/TODO
.........  d /usr/share/doc/rdesktop-1.6.0/ipv6.txt
.........  d /usr/share/doc/rdesktop-1.6.0/keymap-names.txt
.........  d /usr/share/doc/rdesktop-1.6.0/keymapping.txt

verify openssh

% rpm -qVv openssh
.........    /etc/ssh
..?......  c /etc/ssh/moduli
.........    /usr/bin/ssh-keygen
.........    /usr/libexec/openssh
.........    /usr/libexec/openssh/ssh-keysign
.........    /usr/share/doc/openssh-5.5p1
.........  d /usr/share/doc/openssh-5.5p1/CREDITS
.........  d /usr/share/doc/openssh-5.5p1/ChangeLog
.........  d /usr/share/doc/openssh-5.5p1/INSTALL
.........  d /usr/share/doc/openssh-5.5p1/LICENCE
.........  d /usr/share/doc/openssh-5.5p1/OVERVIEW

fix permissions and ownership

% rpm --setperms {packagename}
% rpm --setugids {packagename}

NOTE: See man rpm for more details on -V|--verify output.

See this article for more details: http://www.cyberciti.biz/tips/reset-rhel-centos-fedora-package-file-permission.html.

share|improve this answer
Ok I tried to reinstall everything using apt-get, starting with Sudo - it complained about lots of files being incompatible, so I used dpkg -i --force-install to install that packaged. And that succeded,but again I had like a page of broken files that could not be modified. Sudo still would not work,complained about a missing sudoers file. Raspberry Pi forums suggested,that it might be a power issue,and it got the SD card corrupted. Seems likely,since it happened after a power cut. – gambiting Jan 20 '13 at 19:54
@gambiting : my Pi arrives tomorrow! Can you post a link to the forum thread? I'm hoping this is due to the surge which can sometimes accompany a grid failure -- was the device surge protected? – goldilocks Jan 20 '13 at 20:21
@goldilocks This is the thread I was talking about: raspberrypi.org/phpBB3/viewtopic.php?f=66&t=21266 And by the way - the card itself is not actually damaged. I decided to reinstall the entire system after all, and checked the card - it's clean. And yes, the device is surge protected, and powered from a genuine Apple iPad adapter(which gives more power than needed, 2.1A) – gambiting Jan 21 '13 at 1:59
Even though I gave you these options I would've re-installed too. It's generally easier! – slm Jan 21 '13 at 2:08
@gambiting, never use --force-install unless you are absolutely clear, in minute detail, of what you are doing, as that is guaranteed to leave the system in some inconsistent state. – vonbrand Jan 25 '13 at 12:41

In Fedora systems (I suspect this is really a yum thing) you can do yum reinstall <package> to reinstall a package (that should repair most damage). And rpm -Va gives a list of packages with some kind of problem (look at the manual for details of the output). For some unfathomable reason it usually reports differences even in freshly installed packages, but that hasn't bothered me enough to investigate further (yet). In any case, if the damage is too severe, rescue whatever can be salvaged and reinstall is still your best bet.

share|improve this answer

On Debian based distros, aptitude reinstall <corrupted-packages> may help you repair things.

If you know a specific file has been corrupted, you can get the corresponding package name with dpkg -S /my/corrupted/file.

You may want to try reinstalling only "base system" packages:

# aptitude reinstall "~prequired"
# aptitude reinstall "~pimportant"
# aptitude reinstall "~pstandard"

You may even try (be very careful though) reinstalling everything:

# aptitude reinstall "~i"

I never tested those "massive" reinstallations, so... no guarantee.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.