Before build this driver make sure make
, gcc
, linux-header
/kernel-devel
, bc
and git
have been installed.
mkdir -p ~/build
cd ~/build
git clone https://github.com/brektrou/rtl8821CU.git
Check the interface name of your wifi adapter using ifconfig
. Usually, it will be wlan0 by default, but it may vary depends on the kernel and your device. On Ubuntu, for example, it may be named as wlx + MAC address. (https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/)
If this is the case, you can either disable the feature following the link above, or replace the name used in the driver by
grep -lr . | xargs sed -i '' -e '/ifcfg-wlan0/!s/wlan0/<name of the device>/g'
DKMS is a system which will automatically recompile and install a kernel module when a new kernel gets installed or updated. To make use of DKMS, install the dkms package.
sudo apt-get install dkms
sudo pacman -S dkms
To make use of the DKMS feature with this project, just run:
./dkms-install.sh
If you later on want to remove it, run:
./dkms-remove.sh
If wifi can be detected, congratulations. If not, maybe you need to switch your device usb mode by the following steps in terminal:
- find your usb-wifi-adapter device ID, like "0bda:1a2b", by type:
lsusb
- switch the mode by type: (the device ID must be yours.)
Need install usb_modeswitch
(Archlinux: sudo pacman -S usb_modeswitch
)
sudo usb_modeswitch -KW -v 0bda -p 1a2b
systemctl start bluetooth.service - starting Bluetooth service if it's in inactive state
It should work.
If steps above worked fine and in order to avoid periodically having to make usb_modeswitch
you can make it permanent (Working in Ubuntu 18.04 LTS):
-
Edit
usb_modeswitch
rules:sudo nano /lib/udev/rules.d/40-usb_modeswitch.rules
-
Append before the end line
LABEL="modeswitch_rules_end"
the following:# Realtek 8211CU Wifi AC USB ATTR{idVendor}=="0bda", ATTR{idProduct}=="1a2b", RUN+="/usr/sbin/usb_modeswitch -K -v 0bda -p 1a2b"
Use following commands:
cd ~/build/rtl8821CU
make
sudo make install
If you later on want to remove it, do the following:
cd ~/build/rtl8821CU
sudo make uninstall
If you successfully install the driver, the driver is installed on /lib/modules/<linux version>/kernel/drivers/net/wireless/realtek/rtl8821cu
. Check the driver with the ls
command:
ls /lib/modules/$(uname -r)/kernel/drivers/net/wireless/realtek/rtl8821cu
Make sure 8821cu.ko
file present on that directory
sudo dkms status
# For AArch32
sudo cp /lib/modules/$(uname -r)/build/arch/arm/Makefile /lib/modules/$(uname -r)/build/arch/arm/Makefile.$(date +%Y%m%d%H%M)
sudo sed -i 's/-msoft-float//' /lib/modules/$(uname -r)/build/arch/arm/Makefile
sudo ln -s /lib/modules/$(uname -r)/build/arch/arm /lib/modules/$(uname -r)/build/arch/armv7l
# For AArch64
sudo cp /lib/modules/$(uname -r)/build/arch/arm64/Makefile /lib/modules/$(uname -r)/build/arch/arm64/Makefile.$(date +%Y%m%d%H%M)
sudo sed -i 's/-mgeneral-regs-only//' /lib/modules/$(uname -r)/build/arch/arm64/Makefile
Use the tool 'iw', please don't use other tools like 'airmon-ng'
iw dev wlan0 set monitor none
To build this driver for Raspberry Pi 4, you need to follow the steps below.
#Follow the build step until just before ./dkms-install.sh
# Update and upgrade apt
sudo apt update -y
sudo apt upgrade -y
# Install bc
sudo apt-get install bc
# Reboot the system
sudo reboot
Next, edit the MakeFire to change these two lines
CONFIG_PLATFORM_I386_PC = y
CONFIG_PLATFORM_ARM_RPI = n
to
CONFIG_PLATFORM_I386_PC = n
CONFIG_PLATFORM_ARM_RPI = y
Then, run these lines to fix Make error on ARM processor
sudo cp /lib/modules/$(uname -r)/build/arch/arm/Makefile /lib/modules/$(uname -r)/build/arch/arm/Makefile.$(date +%Y%m%d%H%M)
sudo sed -i 's/-msoft-float//' /lib/modules/$(uname -r)/build/arch/arm/Makefile
sudo ln -s /lib/modules/$(uname -r)/build/arch/arm /lib/modules/$(uname -r)/build/arch/armv7l
Finally, continue the steps above to install via dkms
# Run dkms install with sudo
sudo ./dkms-install.sh
and you should see wlan1 pop up on your Pi 4.