3

Ubuntu 22.04.01 LTS Gnome

Changed python version which resulted in inability to access Terminal and a few other things.

Used a liveUSB and then selected to try ubuntu.

In that terminal entered:

sudo fdisk -l
sudo mount /dev/sda1 /mnt/
sudo mount --bind /proc/ /mnt/proc/
sudo mount --bind /sys/ /mnt/sys/
sudo mount --bind /dev/ /mnt/dev/
sudo cp /etc/resolv.conf /mnt/etc/resolv.conf
sudo chroot /mnt/

That code executed fine. I then wanted to change python3.11 to python 3.10 with

sudo update-alternatives  --set python /usr/bin/python3.6

However I get the error listed in the title. Other attemps with various code to change python also raise the same error. Can't find any similar questions on here.

Raffa
  • 32,237
  • 2
    You also need to mount /dev/pts. – muru Jan 12 '23 at 04:29
  • @muru Normally the devpts is already taken care of by the /dev bindmount; manual mounting of a devpts is only required when a devtmpfs is directly mounted into the chroot dev. – mcendu Feb 15 '24 at 07:59
  • @mcendu for that you need --rbind. A regular --bind mount like in the question wouldn't necessarily result in submounts being reflected. (/dev/pts is a mount of its own, of type devpts, devtmpfs has nothing to do with it.) – muru Feb 15 '24 at 08:08
  • 1
    @muru Ah yes, you are right. This sort of mistake is very easy to make when creating a chroot environment, and so people made arch-chroot to easily get over all the pitfalls. – mcendu Feb 15 '24 at 08:15

3 Answers3

3

PTY(AKA Pseudoterminal) is used for implementing terminal emulators such as xterm … It is involved in enabling the interpretation of passed data in the same way a real terminal would interpret the data … This becomes important when sending input to programs(such as su and sudo) that normally refuse to read input from pipes.

In Ubuntu(and many other Linux distributions), PTYs are pseudo-devices identified under /dev/pts and thus a simple mount —bind won’t make it available in the target mount-point but, a recursive mount —rbind will.

So you can solve this by either mount binding /dev/ recursively using the option —rbind like so:

sudo mount --rbind /dev/ /mnt/dev/

Or by additionally mount binding /dev/pts/ directly like so:

sudo mount --bind /dev/pts/ /mnt/dev/pts/

Or if you are not going to need such programs as su and sudo in the target chroot, then you can just become the user root before you run your commands like so:

sudo -i

Then you’ll be able to run your commands in the same shell with elevated permissions without the need to use sudo.

Raffa
  • 32,237
0

If this happens outside of a chroot, then /dev/pts may have been accidentally unmounted. Here is how to mount it:

mount none -t devpts /dev/pts
user1158559
  • 101
  • 1
-2

Remove sudo from the commands.

  • In your case running chroot with sudo in the first place i.e. sudo chroot /mnt/ will make you root in the new chroot environment … So, yes no need to use sudo there. – Raffa Sep 28 '23 at 18:34