Install package to Ubuntu 16.04 installation while booted into live cd

I have installed Ubuntu 16.04 onto my hard disk.

After tingling with the nvidia drivers and installing xserver-xorg-core or something (I was trying to get bumblebee and optirun to work), I found a post saying xserver-xorg-input-all was not installed - which left me with a system that I can boot into, but not interact with.

I tried recovery mode, but my laptop only has wifi (or LAN via USB-Stick, which I think would probably be as complicated to get to work) and I cannot manage to get network up and working in recovery mode.

So I started a live cd / live-USB-Stick with Ubuntu 16.04 (that I used to install Ubuntu) and it mounted my hard drive with Ubuntu on it as well.

Is there a way to somehow install that package into the installation of Ubuntu on my hard drive while running live Ubuntu?


Solution 1:

It's difficult to speak to the exact situation with xserver-xorg-input-all, however, I can show how to install packages on an installation booted from a live image.

I tested this with a Xubuntu 17.04 VM.

Summary of steps

  • Boot from a compatible live image, preferably the one you installed from.
  • Mount the root volume of the installation.
  • Bind mount /dev, /proc, and /sys inside the root volume mount.
  • Bind mount /run if /etc/resolv.conf is a symlink to /run/resolvconf/resolv.conf. This is required on Ubuntu 17.04, but I'm not sure if it is on 16.04. This is required for DNS name resolution.
  • chroot into the mounted file system.
  • Install, uninstall, or configure as needed.
  • Reboot into installation.

Actual commands

The device you're mounting in the first command will need to be adjusted to match your installation's root volume.

mount /dev/xubuntu-vg/root /mnt
mount --bind /dev /mnt/dev
mount --bind /sys /mnt/sys
mount --bind /proc /mnt/proc
mount --bind /run /mnt/run # if needed, as noted above
chroot /mnt
apt install gnucash # or whatever you need

Wrap up

I was able to install gnucash, an application I did not previously have installed and which has many dependencies. After a reboot, GnuCash was installed and functional.

Note that I did not update the cache with apt-get update before installing, this was intentional because I knew my cache on the installation was up-to date enough. Depending on your situation, updating the cache may be necessary.