(Even though this is a pretty old thread, I believe I still have something relevant to add to it, so here goes.)
TL;DR.
For those of you who aren’t interested in the detailed explanation below, I attached the bash script
‘disable-bluetooth’ that you can run under Slackware and that will:
- Deactivate Bluetooth on your running system;
- Blacklist the Bluetooth modules, to ensure that Bluetooth will remain deactivated whenever you reboot the system.
Just download the script, remove the
‘.txt’ extension, make it executable and run it as
‘root’ without any command-line parameters.
Introduction.
When you boot Slackware
(BTW, I’m running Slackware 14.2), a message such as the following will appear on the boot console:
Code:
Starting Bluetooth services: bluetoothd hciconfig sdptool hciattach
Furthermore, the kernel will spit out multiple messages relating to Bluetooth—e.g.:
Code:
# dmesg | grep --fixed-strings 'Bluetooth'
Bluetooth: Core ver 2.21
Bluetooth: HCI device and connection manager initialized
Bluetooth: HCI socket layer initialized
Bluetooth: L2CAP socket layer initialized
Bluetooth: SCO socket layer initialized
Bluetooth: hci0: read Intel version: 3707100180012d0d00
Bluetooth: hci0: Intel Bluetooth firmware file: intel/ibt-hw-37.7.10-fw-1.80.1.2d.d.bseq
Bluetooth: hci0: Intel Bluetooth firmware patch completed and activated
Bluetooth: BNEP (Ethernet Emulation) ver 1.3
Bluetooth: BNEP filters: protocol multicast
Bluetooth: BNEP socket layer initialized
Bluetooth: RFCOMM TTY layer initialized
Bluetooth: RFCOMM socket layer initialized
Bluetooth: RFCOMM ver 1.11
Given that Bluetooth support is set up, the corresponding system class will have been created as well:
Code:
# ls -ld /sys/class/bluetooth
drwxr-xr-x 2 root root 0 Dec 11 15:00 /sys/class/bluetooth/
Finally, the Bluetooth kernel module will have been loaded, together with the other modules that make up the Bluetooth stack. The precise list of supporting modules will depend on the hardware configuration of the computer, but on my laptop, it looks like the following:
Code:
# lsmod | grep '^bluetooth'
bluetooth 315713 39 bnep,btbcm,btrtl,btusb,rfcomm,btintel
Note that the third column of this output line—i.e., the number
“39”—represents the
‘use count’ of the Bluetooth module, and the fourth column lists the
‘referring modules’—i.e., the kernel modules that contribute (possibly multiple times) to the use count. It will not be possible to unload the Bluetooth module, since its use count is greater than zero:
Code:
# modprobe --remove bluetooth
modprobe: FATAL: Module bluetooth is in use.
All of the above—the boot console message, the kernel messages, the system class, and the loaded modules—will be gone once you completely disable Bluetooth.
1. Blacklisting the Bluetooth modules, to prevent them from loading at boot time.
If you want to prevent the Bluetooth modules from loading at boot time, then you will have to
‘blacklist’ them. Simply create a blacklist configuration file—e.g.,
‘/etc/modprobe.d/blacklist-bluetooth.conf’—that lists the affected modules. To determine the list of the modules that will have to be blacklisted, you will have to look at the output of the
‘lsmod’ command, shown above:
Code:
# lsmod | grep '^bluetooth'
bluetooth 315713 39 bnep,btbcm,btrtl,btusb,rfcomm,btintel
Given this output, the following command will create the appropriate blacklist configuration:
Code:
# cat <<'//*EOF' > /etc/modprobe.d/blacklist-bluetooth.conf
blacklist bluetooth
blacklist bnep
blacklist btbcm
blacklist btrtl
blacklist btusb
blacklist rfcomm
blacklist btintel
//*EOF
From this point on, Bluetooth will effectively be disabled whenever you boot the system. The boot console message, informing you that the Bluetooth services are getting started, will no longer appear, the kernel messages relating to Bluetooth will be missing, and the Bluetooth system class will not be set up:
Code:
# ls -ld /sys/class/bluetooth
/bin/ls: cannot access '/sys/class/bluetooth': No such file or directory
In addition, the Bluetooth module and its depencies will not get loaded:
Code:
# lsmod | grep '^bluetooth'
Note, however, that the Bluetooth modules
can still be loaded, and the Bluetooth service can subsequently be started, should you ever need it:
Code:
# modprobe bluetooth
# modprobe bnep
# modprobe btbcm
# modprobe btrtl
# modprobe btusb
# modprobe rfcomm
# modprobe btintel
# /etc/rc.d/rc.bluetooth start
Starting Bluetooth services: bluetoothd hciconfig sdptool hciattach
It should be noted that, even though the kernel will no longer automatically load the Bluetooth modules, it will still run the
‘/etc/rc.d/rc.bluetooth’ script to start the Bluetooth service. Under Slackware, however, this script will refuse to start the service if the Bluetooth system class,
‘/sys/class/bluetooth’ is missing. Since it is, then, rather pointless to run the script, you may want to make it non-executable:
Code:
# chmod -x /etc/rc.d/rc.bluetooth
Do keep in mind, though, that you will, then, no longer be able to run the script manually either. You will, consequently, be unable to start the Bluetooth services unless and until you make the script executable again.
If you want to make sure that the Bluetooth modules will not get loaded, ever, then, in addition to blacklisting them, you can
‘fake-install’ them—i.e., force execution of any arbitrary shell command whenever the kernel is instructed to load the modules. The
‘true’ command is an excellent choice here, since it will effectively perform no operation, and do so
successfully.
Thus, to
‘fake-install’ the Bluetooth modules using the
‘true’ command, you can simply add the appropriate lines to the blacklist configuration file:
Code:
# cat <<'//*EOF' >> /etc/modprobe.d/blacklist-bluetooth.conf
install bluetooth /usr/bin/true
install bnep /usr/bin/true
install btbcm /usr/bin/true
install btrtl /usr/bin/true
install btusb /usr/bin/true
install rfcomm /usr/bin/true
install btintel /usr/bin/true
//*EOF
2. Turning Bluetooth off without rebooting.
To dynamically turn Bluetooth off—i.e., without rebooting—you will have to:
- Stop the Bluetooth service;
- Unload the Bluetooth kernel modules.
1. Stopping the Bluetooth Service.
Stopping the Bluetooth service is as simple as running the following command:
Code:
# /etc/rc.d/rc.bluetooth stop
2. Unloading the Bluetooth Kernel Modules.
To unload the Bluetooth modules, you will first have to identify them, as follows:
Code:
# lsmod | grep '^bluetooth'
bluetooth 315713 39 bnep,btbcm,btrtl,btusb,rfcomm,btintel
Next, expand this output, to display the details of each of these modules on a separate line:
Code:
# lsmod | grep --extended-regexp '^(bluetooth|bnep|btbcm|btrtl|btusb|rfcomm|btintel)'
rfcomm 34772 0
bnep 11487 0
btusb 30305 0
btrtl 4402 1 btusb
btbcm 7234 1 btusb
btintel 8007 1 btusb
bluetooth 315713 9 bnep,btbcm,btrtl,btusb,rfcomm,btintel
You can now unload those modules that show a
use count of zero:
Code:
# modprobe --remove rfcomm bnep btusb
The
‘modprobe’ command will unload each of the listed modules in turn (provided that their
use count is 0, of course), and subsequently unload any further modules for which the
use count becomes 0. As a result, after you run the command, there should not be any remaining Bluetooth modules loaded:
Code:
# lsmod | grep --extended-regexp '^(bluetooth|bnep|btbcm|btrtl|btusb|rfcomm|btintel)'
Bluetooth will, at this point, effectively be turned off—which you can verify when you attempt to list the Bluetooth system class and find that it no longer exists:
Code:
# ls -ld /sys/class/bluetooth
/bin/ls: cannot access '/sys/class/bluetooth': No such file or directory
Unless you blacklist the Bluetooth kernel modules, however, Bluetooth will be reactivated when you reboot the system.