Fixing '/dev/null: Permission denied' repeatedly in chroot

5

I've chrooted into an external disk with sudo chroot /mnt/disk, but almost everything I do (logging in, tab-completion, lessing a file, ...) results in an error mentioning /dev/null: Permission denied, even if the command seems to work.

/dev/null has the correct permissions (666), and file says it's a character device, so it's not like anything has overwritten it with a regular file or changed the permissions.

What can I do to fix this?

Here's what tab-completion (of ls /u) results in:

$ ls /ubash: /dev/null: Permission denied
bash: _upvars: `-a2': invalid number specifier
bash: /dev/null: Permission denied
bash: _upvars: `-a0': invalid number specifier

Ash

Posted 2018-04-04T15:19:04.547

Reputation: 192

Answers

3

The disk might be mounted with the nodev option, which mount interprets thusly:

Do not interpret character or block special devices on the file system.

You can verify this by checking the output of mount outside the chroot:

$ mount
...
/dev/sda1 on /mnt/disk type ext4 (rw,nosuid,nodev,relatime,data=ordered,uhelper=udisks2)

(This is a particularly tricky problem to spot, as configuration outside of the chroot is affecting the behaviour of programs inside it!)

Fixing it is as easy as remounting without the nodev option. The following command will accomplish this (even while the chrooted process is running!), although there's probably a way that removes just the nodev option without removing all the other options too:

sudo mount -o remount /dev/sda1 /mnt/disk

Ash

Posted 2018-04-04T15:19:04.547

Reputation: 192