Accidentally deleted /bin on Ubuntu 16.04 [closed]
I deleted /bin
folder on Ubuntu 16.04 by mistake. There was a folder named bin
in home folder and I deleted /bin
folder instead ~/bin
folder in home folder. Unfortunately, when I restarted my PC, it didn't boot.
I have important files in home folder and the home folder it is not in separate partition from OS. Is upgrading the system to a newer version via bootable USB flash useful to solve this problem?
Solution 1:
On Ubuntu Desktop releases (inc. flavors), you can Upgrade via re-install.
Boot the live system
Start the ubiquity
installer for Ubuntu Desktop and using Something else (Manual Partitioning with calamares
)
- Select your existing partition(s)
- ensure you don't have FORMAT tagged
It will cause the following to occur
- your installed packages are noted
- your system directories are erased (desktop apps don't store data in system directories; some server apps do though)
- new system is installed
- any additional packages you had installed (noted earlier) get re-installed IF available in your new release from Ubuntu repositories
- no user file is touched (unless you selected format)
- you are asked to reboot
It's far faster than a release-upgrade, and my usual fall back for an install that went wrong (and I'm too lazy to fix it), or I don't have time to release-upgrade.
Complications can occur if you have an encrypted system, as Ubuntu 17.10 & earlier used different encryption to 18.04 & later, so the package some encrypted installs need is no longer included by default; but that can be worked around via a manual install during the live session prior to starting the installed (ubiquity
).
Of course, and as always you should always have backups as things can happen (power goes out etc) so backup your data first using the live session prior to install.
Solution 2:
I see the following way to recover your current Ubuntu 16.04 LTS version without reinstall:
-
You boot the original installation Ubuntu 16.04 LTS LiveCD/LiveUSD in Try Ubuntu mode, then mount your current operating system partition and copy
/bin
folder from LiveCD/LiveUSB to the OS partition by using command likesudo cp -ar /bin /media/ubuntu/OS/
or with GUI, then reboot; -
After first successful login to your OS, you can reinstall the packages which have files in
/bin
by using command below:sudo apt-get update sudo apt-get install --reinstall $(dpkg -S /bin | sed "s/,//g" | sed "s|: /bin||")
-
To keep system consistent locate extra executable files which were copied from LiveCD/LiveUSB, but should not exist in your OS, and remove them manually by using command below
find /bin -type f -exec dpkg -S {} \; 2> ~/not-from-apt.out
then carefully inspect the contents of
~/not-from-apt.out
and remove binary files which are listed here. Or use one-liner below if you are sure:sudo rm -v -i $(cat ~/not-from-apt.out | awk '{print $7}')
-
Then upgrade this system to newer 18.04 LTS release by
sudo do-release-upgrade
or by usingupdate-manager -c
.