1

I removed libc6 manually (i.e. by sudo apt remove libc6 command) on my Ubuntu 18.04 system and after reboot, there is just grub command prompt:

GNU GRUB   version 2.02

Minimal BASH_like line editing is supported. For the first word TAB lists possible command completions. Anywhere else TAB lists possible device or file completions.


grub>  _

Is there any way to reinstall libc6 and put my system working as before?

UPDATE1:

This is screenshot of my partition structure (as GParted shows): enter image description here

/dev/sda2 is the partition that is encrypted and contains /etc/, /root/, /lib/, /run/ and other Linux OS default folders and was mounted (at my previous working Lubuntu) as / i.e. system root.

/dev/sda5 is the partition that is not encrypted and was mounted (at my previous working Lubuntu) as /home/ folder.

UPDATE2:

Although /dev/sda5/ is not an encrypted partition, but my /home/myusername/ folder is encrypted as follows and I do not remember how I did this encryption during OS installation and do not know how to recover my data in my /home/myusername/ folder:

lubuntu@lubuntu:~$ sudo ls /media/lubuntu/UUID/myusername/ -la
total 12
dr-x------ 3 1000 1000 4096 Aug  1  2013 .
drwxr-xr-x 7 root root 4096 Aug 25  2014 ..
lrwxrwxrwx 1 1000 1000   27 Aug  1  2013 .Private -> /home/.ecryptfs/myusername/.Private
drwx------ 3 1000 1000 4096 Aug  2  2013 .cache
lrwxrwxrwx 1 1000 1000   28 Aug  1  2013 .ecryptfs -> /home/.ecryptfs/myusername/.ecryptfs
lrwxrwxrwx 1 1000 1000   56 Aug  1  2013 Access-Your-Private-Data.desktop -> /usr/share/ecryptfs-utils/ecryptfs-mount-private.desktop
lrwxrwxrwx 1 1000 1000   52 Aug  1  2013 README.txt -> /usr/share/ecryptfs-utils/ecryptfs-mount-private.txt
PHP Learner
  • 2,788
  • 10
  • 30
  • 48

3 Answers3

2

I think this will work.

Download the .iso of your operating system and make a bootable USB using something like rufus. Boot from USB and when the GRUB menu appears select Try Ubuntu without installing.

After it boots up, the LiveUSB environment open a terminal. If you enabled LUKS in your hard drive, open the file manager enter the password. Now in the terminal run :

sudo pvscan    
sudo lvscan    
sudo vgchange -a y

This will activate the LUKS volume for mounting. Read the volume name from the output.

sudo mount /dev/sdaX/root  /mnt

where sdaX is the volume name.

If you have a separate /boot drive: go to the /mnt of LiveUSB where the filesystem is mounted. Open /etc/fstab and check for a /boot [UUID] entry and remember the drive name. Do :

sudo mount /dev/sdaX /mnt/boot    
sudo mount --bind /sys /mnt/sys    
sudo mount --bind /dev /mnt/dev    
sudo mount --bind /proc /mnt/proc

where sdaX is the above drive name.

Now sudo nano /etc/hosts. You should have two or more entries like :

127.0.0 localhost    
127.0.0 username

Copy the host address to the next line and add the host name the one you find in your terminal prompt. Should be something like ubuntu. Save and exit. Now :

sudo chroot /mnt

Reinstall libc6 using apt-get.

sudo apt-autoremove
sudo apt-get update && sudo apt-get upgrade    
sudo apt install -f    
sudo update-grub    
exit

Unmount everything using sudo umount /mnt/... and reboot from OS.

PS. If apt does not work,maybe it depends on libc6, I would recommend making a backup of important files once the partition is mounted or do a reinstall without removing or repair the os.

  • I tried your solution. My /home/ folder is encrypted and is a separated partition. When I click that partition in Live OS file manager, It asks me for password and after entering password, it gives following error message: Error unlocking /dev/sda2: The function 'bd_crypto_luks_open_blob' called, but not implemented! – PHP Learner Nov 28 '19 at 13:44
  • Also, these three commands does not show any result: sudo pvscan sudo lvscan sudo vgchange -a y – PHP Learner Nov 28 '19 at 13:54
  • Run this in the live environment before trying to give the password,skip no step: sudo apt-get install libblockdev-crypto2 and systemctl restart udisks2.service.You may need to restart other services,post any error messages after this.After entering the password and opening the volume run the commands sudo pvscan etc. – kortewegdevries Nov 29 '19 at 03:31
  • Thank you very much, I did exactly what you told in your comment, the partition was opened after 2 mins waiting and its files are readable. But sudo pvscan returns: No matching physical volumes found and sudo lvscan and sudo vgchange -a y return nothing! Any solution? – PHP Learner Nov 30 '19 at 16:11
  • After opening my encrypted partition (/dev/sda2/) by Live OS file manager, I found my /root/ folder in it and tried to mount whole partition on /mnt folder by sudo mount /dev/sda2 /mnt command, but it returns: mount: /mnt: unknown filesystem type 'crypto_LUKS'. and If I try to mount /root folder by sudo mount /media/lubuntu/UUID/root /mnt it returns: mount: /mnt: /media/lubuntu/UUID/root is not a block device (UUID is uu-id of my encrypted partition (/dev/sda2 and /media/lubuntu/UUID/ is the location it is mounted by Live OS file manager). – PHP Learner Nov 30 '19 at 16:39
  • Maybey you don't have the package lvm2,install it with apt.pvscan,lvscan,vgchange -ay should return a drive name like ubuntu-vg. You should mount it like sudo mount /dev/ubuntu-vg/root/ /mnt since it is a LUKS volume. And before running lvscan check in the file manger if the partition is decrypted, they return blank responses if the drive is not activated with the passphrase. – kortewegdevries Dec 01 '19 at 06:09
  • Here is a screenshot of the process https://ibb.co/NjZ98Fm and I ran a simulation of apt remove to check if libc6 can be reinstalled: https://pastebin.com/hFaazHi2 I don't think it can. You can try but if it fails you need to reinstall the os. – kortewegdevries Dec 01 '19 at 06:39
  • Thank you very much, I will try. But it fails, how I can reinstall the OS and keep my encrypted volumes as before! I am afraid of loosing data if I reinstall the OS! – PHP Learner Dec 01 '19 at 12:45
  • I tried to install lvm2 but it says that lvm2 is already the newest version. /dev/mapper/ contains luks-UUID block after decrypting the partition by file manager, but there is no /dev/lubuntu-vg/xxx and pvscan, lvscan, vgchange -ay return as before!!! – PHP Learner Dec 01 '19 at 12:55
  • Can you please post your partition structure? Did you use LMV+LUKS while installing Ubuntu or did you encrypt only the /home folder and not the entire disk ?Where was your filesystem root? About reinstalling backup your entire /home and if you modified system files back them up.Follow this https://askubuntu.com/questions/841308/installing-ubuntu-16-04-without-losing-data/841310 and/or this https://help.ubuntu.com/community/UbuntuReinstallation Yo'll likely loose any packages installed, so you'll need to reinstall them. – kortewegdevries Dec 01 '19 at 13:19
  • Is there any one that could help me to solve the problem? – PHP Learner Dec 11 '19 at 06:35
  • In order to succeed I beiieve you need to run "cryptsetup open /dev/sdXn sdXn_crypt and provide your LUKS password. – storestyggeulv Dec 14 '19 at 15:53
  • the cryptsetup command need to be run before pvscan, lvscan and vgchange. – storestyggeulv Dec 14 '19 at 16:00
0

From Issues you faced, it looks like more packages are missing than libc6 and they were removed accidentally. I would suggest to mount / partition and go through apt and dpkg logs to check removed packages.

cat /var/log/dpkg.log | grep remove
cat /var/log/apt/history.log | grep remove

Get list of packages those were removed and try to re-install them.

KK Patel
  • 19,083
  • May be you are right, but for installing any packages if I use "-o RootDir=/mnt" option it returns E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem. error and i do not know how to run sudo dpkg --configure -a on /mnt as root! – PHP Learner Jan 17 '20 at 13:40
  • i solved chroot problem by runing sudo cp -a /bin/bash /mnt/bin ; sudo chmod +x /mnt/bin/bash ; sudo cp -an /usr /mnt ; sudo cp -an /lib /mnt ; sudo cp -an /lib64 /mnt ; and after above commands, sudo chroot /mnt worked! – PHP Learner Jan 17 '20 at 16:38
0

For mounting your encrypted partition it looks like you need mount /media/lubuntu/UUID /mnt. If running apt/apt-get inside the chroot doesn't work run it in the live CD terminal without chroot but with the added option -o RootDir=/mnt. That will put everything on the encrypted partition properly.

  • After running following commands: udisksctl unlock -b /dev/sda2 ; sudo mount /dev/dm-0 /mnt ; sudo mount /dev/sda1 /mnt/boot/ ; sudo mount --bind /sys /mnt/sys/ ; sudo mount --bind /dev /mnt/dev/ ; sudo mount --bind /proc /mnt/proc/ ; I did following command as you sugested: sudo apt autoremove -o RootDir=/mnt ; but it returns: E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem. and running sudo dpkg --configure -a does not returns anythings and does not solve above error message, any suggestion? – PHP Learner Jan 17 '20 at 13:25
  • It seems that I have to run sudo dpkg --configure -a on my /mnt as root directory, but dkpg command does not accept -o RootDir=/mnt option. Is there any suggestion for how to run sudo dpkg --configure -a on /mnt as root? – PHP Learner Jan 17 '20 at 13:42
  • i solved chroot problem by runing sudo cp -a /bin/bash /mnt/bin ; sudo chmod +x /mnt/bin/bash ; sudo cp -an /usr /mnt ; sudo cp -an /lib /mnt ; sudo cp -an /lib64 /mnt ; and after above commands, sudo chroot /mnt worked! – PHP Learner Jan 17 '20 at 16:38