14

I try to repair an broken Ubunu 14.04 with chroot. What I did, is to boot Ubuntu from USB mounted the original system that has to be repaired and changed to this system with chroot:

sudo mount /dev/sdXY /mnt 
sudo mount -o bind /dev /mnt/dev 
sudo mount -o bind /sys /mnt/sys 
sudo mount -t proc /proc /mnt/proc 
sudo cp /proc/mounts /mnt/etc/mtab 
sudo chroot /mnt /bin/bash 

That worked fine, but in chroot environment I don't have access to the internet, so apt isn't able to resolve hostnames. What am I supposed to do?

ping www.askubuntu.com

does not work either.

  • I think my command should be for d in dev sys run proc; do sudo mount -o bind /$d /mnt/$d ; done – Avinash Raj May 19 '14 at 16:24
  • try and get back to me soon :-) – Avinash Raj May 19 '14 at 16:27
  • Seems to work, but I am not quite sure, because it my be an other reason making it work. Thank you anyway! – user5950 May 19 '14 at 16:54
19

On newer Ubuntu systems, name resolution is handled by the resolvconf service, and /etc/resolv.conf is a symbolic link to /run/resolvconf/resolv.conf. You can either add a bind mount to the /run filesystem along with your other bind mounts before executing the chroot command

sudo mount -o bind /run /mnt/run

so that the chroot system picks up the host system's DNS settings or, once you're in the chrooted system, temporarily create a static /etc/resolv.conf with nameserver(s) of your choice e.g.

echo 'nameserver 8.8.4.4' | sudo tee -a /etc/resolv.conf
  • What are "newer Ubuntu systems"; in other words since which version is name resolution handled by resolvconf? – Pro Backup Aug 11 '14 at 16:04
  • @ProBackup at least from 12.04 I think, although it may have been backported - see DNS in Ubuntu 12.04 – steeldriver Aug 11 '14 at 16:12
  • doing sudo mount --bind /run /mnt/run worked for me chrooting into a botched 17.10 upgrade. Thanks for the answer! – labyrinth Nov 17 '17 at 1:02
  • Is there a permanent solution? – gromit190 Aug 28 '18 at 15:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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