3

After an unclean shutdown, fsck reported corruption in several parts of the filesystem, apparently affecting installed packages (luckily no user data was affected).

Is there an easy way how I can reinstall these packages from scratch, e.g. tell apt or dpkg to install the same package again, without changing its flags (especially preserving the auto-installed flag)?

I have a list of the affected files and, with some effort, could figure out which packages I would need to reinstall. Alternative is to reinstall everything installed on the system.

  • 4
    apt-get --reinstall install packagename? – DopeGhoti Sep 1 '17 at 19:29
  • @DopeGhoti in theory yes, turns out it’s not quite as trivial as I thought to figure out the exact package for the files (for which I have the paths). Any ideas? – user149408 Sep 1 '17 at 19:43
  • 5
    @user149408 dpkg -S /full/path/of/the/corrupted/file will give you the packaged that installed the file. – xhienne Sep 1 '17 at 20:08
  • @xhienne thanks, that worked. Currently going through the list. – user149408 Sep 1 '17 at 20:27
  • This worked. Anyone of those commented care to make this an answer so I can accept it? – user149408 Sep 1 '17 at 20:40
8

For each of your corrupted file, the package that installed your file can be obtained with:

dpkg -S /full/path/of/the/corrupted/file

You can then reinstall it with the command:

apt-get --reinstall install package

If all your corrupted files are in a single file list.txt, then you can obtain all the associated packages with:

dpkg -S $(cat list.txt) | cut -d: -f1 | sort -u

And of course install all those packages with that single command:

apt-get --reinstall install $(dpkg -S $(cat list.txt) | cut -d: -f1 | sort -u)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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