timebertt / pi-cloud-init

Minimal Raspberry Pi OS including cloud-init
Apache License 2.0
86 stars 11 forks source link

rfkill: cannot open /dev/rfkill #3

Closed geoff-coppertop closed 3 years ago

geoff-coppertop commented 3 years ago

Looks like permissions are not being set correctly for /dev/rfkill on boot. If I call rfkill as would done on boot, or during an ssh connect, as part of the /etc/profile.d/wifi-check.sh script I get the following errors,

rfkill: cannot open /dev/rfkill: Permission denied
rfkill: cannot read /dev/rfkill: Bad file descriptor

Looking at /dev/rfkill when this happens I see that only root has permissions and that it's accessible by the root group. In this circumstance the permission errors make sense since my user isn't root or in the root group.

thomasga@rpi-carbon-00:~ $ ls -lah /dev/rfkill
crw------- 1 root root 10, 242 May 11 04:21 /dev/rfkill

Experimentally I found that I can clear the error until the next reboot by calling sudo rfkill this causes the permissions on /dev/rfkill to change to root:netdev and my user is part of the netted group (shown below).

thomasga@rpi-carbon-00:~ $ sudo rfkill
thomasga@rpi-carbon-00:~ $ ls -lah /dev/rfkill
crw-rw-r-- 1 root netdev 10, 242 May 11 04:25 /dev/rfkill

I haven't gone back to a version of the software that had dhcpcd unmasked but I didn't see this error in that case so something in the boot sequence with dhcpcd active is more better...

timebertt commented 3 years ago

While I don't see blocking issues with rfkill as I don't use wifi, I however see this message on ssh login:

Wi-Fi is currently blocked by rfkill.
Use raspi-config to set the country before use.

rfkill list reveals the following:

tim@raspberry-0:~ $ rfkill list
0: phy0: Wireless LAN
    Soft blocked: yes
    Hard blocked: no
1: hci0: Bluetooth
    Soft blocked: no
    Hard blocked: no

I'm not an expert on these things, but it seems like one has to go through additional configuration steps for getting wifi to work out of the box. Can you try running raspi-config?

Maybe this helps as well: https://github.com/RPi-Distro/pi-gen/blob/66cd2d17a0d2d04985b83a2ba830915c9a7d81dc/export-noobs/00-release/files/release_notes.txt#L223-L229 I also saw one project setting up wifi via cloud-init (but on Ubuntu, not on RaspiOS), maybe this can help as well: https://gitlab.com/Bjorn_Samuelsson/raspberry-pi-cloud-init-wifi/-/blob/master/user-data-template#L65-70

geoff-coppertop commented 3 years ago

I should clarify that I'm running this on a compute module 3+ with 32GB eMMC memory, these modules don't have bluetooth or Wi-Fi. The behaviour I'm seeing isn't blocking, just the warning message as far as I'm able to tell, it just seems unfinished. I'll take a look at those links as soon as possible and also try running the example configs that you have in the repo, as there may be some configuration that is causing this.

My point of reference for these tests is that my configs seem to be ok when used with either Ubuntu Server 20.04 (runs out of memory during operation, but that's a separate problem) and HypriotOS (which is only 32bit).

kwitsch commented 3 years ago

I don't use wifi or bluetooth and got the rfkill message on ssh login. Is there a flaw in uninstalling rfkill which i didn't notice?

user-data:

runcmd:
  - echo -e "dtoverlay=disable-bt\ndtoverlay=disable-wifi" >> /boot/config.txt
  - apt-get purge --auto-remove -y rfkill
geoff-coppertop commented 3 years ago

I'm not sure, I've "fixed" it by adding,

bootcmd:
- rfkill

which has the effect of setting the permissions to

crw-rw-r-- 1 root netdev 10, 242 May 11 04:25 /dev/rfkill

which gets rid of the error message on ssh login.

timebertt commented 3 years ago

@geoff-coppertop @kwitsch So, I guess it's kind of clear now, what this error message is about and how to get rid of it. Do you think, it makes sense to do any of those steps "as a default" in the image, if it works for all users no matter if they want to use wifi or not?

kwitsch commented 3 years ago

In my opinion rfkill could be excluded from the image as default. If someone still has the need to soft block radio devices it could be simply included via user-data.

packages:
  - refkill

This would solve the problem for all who doesn't use radio devices and would reduce the number of unused services. For those using radio devices and depending on this service, only a small change in the user-data is neccesarry.

geoff-coppertop commented 3 years ago

I think both of the proposed work arounds show that there are methods to silence the error, I'm concerned that the error can be silenced seemingly without issue. I'd favour baking the solution I came to into the image build because it doesn't leave anything to the consumer to do, it just works. That being said I don't have a good method for getting there yet.

timebertt commented 3 years ago

I opened https://github.com/timebertt/pi-cloud-init/pull/6 to get rid of the warning message on startup, feel free to leave feedback there. I would like to keep the image as similar to stock raspiOS as possible, so I don't want to uninstall rfkill or similar. If you would want to get rid of all wifi/bt related packages, you would probably also remove a lot of other stuff (e.g. bluetoothd, iw, ...). Also, if someone does want to use wifi with this image, it's much easier and obvious to follow the steps that are also required to activate it on stock raspiOS, than having to install rfkill again. Unblocking (i.e. enabling) wifi by default is also strange, if you don't want to use it. So I just went with getting rid of the warning message instead of tampering with anything else.