2

I want to enable bluetooth device when system is up.

Which is the recommended way to do it?

The command is sudo hciconfig hci0 up.

Should I put it in /etc/rc.local? or should I use update-rc.d?

If there is no "proper" way to do it, I'll choose the way with /etc/rc.local.

Thanks.

Edit

Following @krt's answer I added @reboot cronjob, but hci0 are still down when rebooting. According to /var/log/syslog the job is running correctly.

1136 May 24 11:17:20 klein /usr/sbin/cron[2107]: (CRON) INFO (pidfile fd = 3)
1137 May 24 11:17:20 klein /usr/sbin/cron[2108]: (CRON) STARTUP (fork ok)
1138 May 24 11:17:20 klein /usr/sbin/cron[2108]: (CRON) INFO (Running @reboot jobs)
1
  • What (Linux?) distribution are you running? If it's Debian/Raspbian, what's the output of dpkg -S /sbin/init? Commented May 24, 2015 at 17:31

5 Answers 5

2

Is your system starting bluetoothd at boot? If yes, then you should check its configuration: it might be overriding the settings you make with hciconfig as it starts up.

For example, the [Policy] section of my /etc/bluetooth/main.conf has an AutoEnable setting, which defaults to false. If you set it to true, then all Bluetooth interfaces get activated automatically by bluetoothd.

If you want more fine-grained control than that, you may have to use bluetoothctl or some other command (depends on your BlueZ version).

1
  • That's it! Thanks!
    – k-war
    Commented Jul 24, 2023 at 17:16
0

with systemd unit, create for example /usr/lib/systemd/system/bluetooth-audio.service and add After=bluetooth.target, in order to make the unit start right after bluetooth.target had been reached and BindsTo=bluetooth.target to make it fail when bluetooth.target had failed:

#!/bin/sh
[Unit]
Description=Bluetooth Audio Connect
ConditionPathIsDirectory=/sys/class/bluetooth
After=bluetooth.target
BindsTo=bluetooth.target

[Service]
ExecStart=/home/scripts/bluetooth_connect.sh
Type=simple

systemctl daemon-reload and systemctl start bluetooth-audio.service bring the unit up. the problem is, that running scripts from udev is pretty useless, while there is no bluetooth yet. here are the corresponding (my) bluetooth_connect and bluetooth_disconnect shell scripts.

0

I am on Ubuntu 20.04 LTS and used systemd.service to load up my hciconfig script at startup.

  1. Save the script under /usr/bin/

     sudo cat /usr/bin/hciconfig_bt.sh
     #! /bin/bash
    
     # 'Interference between Headphones and Mouse' fix
    
     # from https://wiki.archlinux.org/index.php/Bluetooth#Interference_between_Headphones_and_Mouse
    
     hciconfig hci0 lm ACCEPT,MASTER
    
     hciconfig hci0 lp HOLD,SNIFF,PARK`
    
  2. Create systemd.service unit and moved it under /etc/systemd/system/

cat /etc/systemd/system/hciconfig_bt.service
[Unit]
Description=Bluetooth Mouse & Headphone Interference Fix systemd service.

[Service]
Type=forking
ExecStart=/bin/bash /usr/bin/hciconfig_bt.sh

[Install]
WantedBy=multi-user.target
  1. Make sure that you do chmod +x on your script and systemd.service unit.

  2. Run systemctl start 'your systemd.service unit' to make sure it runs successfully.

  3. Lastly, run systemctl enable 'your systemd.service unit' to have unit to be invoked at startup.

If you are not familiar with systemd.service, check below articles first.

https://www.linode.com/docs/quick-answers/linux/start-service-at-boot/ https://www.freedesktop.org/software/systemd/man/systemd.service.html

-1

Instead of using /etc/rc.local or update-rc-d you colud simply create a new @reboot cronjob. To do this, open up root's crontab with:

sudo crontab -u root -e

And add the following to it:

@reboot hciconfig hci0 up 

Crontabs @reboot runs the job once on each boot and reboot.

1
  • Thanks for your answer and sorry for late reply. I couldn't take time for raspberry pi. I did what you recommended but @reboot job didn't work.
    – ironsand
    Commented Jun 26, 2015 at 11:51
-1

Put the following in /etc/cron.d/<yourfilename>

#enable BT
@reboot root hciconfig hci0 up

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .