6

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.

5
  • 4
    apt-get --reinstall install packagename?
    – DopeGhoti
    Commented Sep 1, 2017 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
    Commented Sep 1, 2017 at 19:43
  • 5
    @user149408 dpkg -S /full/path/of/the/corrupted/file will give you the packaged that installed the file.
    – xhienne
    Commented Sep 1, 2017 at 20:08
  • @xhienne thanks, that worked. Currently going through the list.
    – user149408
    Commented Sep 1, 2017 at 20:27
  • This worked. Anyone of those commented care to make this an answer so I can accept it?
    – user149408
    Commented Sep 1, 2017 at 20:40

1 Answer 1

12

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)
1
  • Using nowadays apt, the command is simply sudo apt reinstall <package>.
    – Olivier
    Commented May 25 at 21:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .