Monday, October 11, 2021

Realtek USB Bluetooth Dongle with chip rtl8761b does not work on Linux

This post it to make Realtek Dongle with rtl8761b chipset working under any Linux districution

Symptom

Symptom-1: 

Syslog has below messages

Oct 11 11:54:37 nau20 kernel: [11338.462764] Bluetooth: hci1: RTL: loading rtl_bt/rtl8761b_fw.bin
Oct 11 11:54:37 nau20 kernel: [11338.463293] bluetooth hci1: Direct firmware load for rtl_bt/rtl8761b_fw.bin failed with error -2
Oct 11 11:54:37 nau20 kernel: [11338.463298] Bluetooth: hci1: RTL: firmware file rtl_bt/rtl8761b_fw.bin not found


Symptom-1: 

Blutooth adapter show DOWN

$ hciconfig -a
hci1: Type: Primary  Bus: USB
BD Address: 00:00:00:00:00:00  ACL MTU: 0:0  SCO MTU: 0:0
DOWN 
RX bytes:21 acl:0 sco:0 events:2 errors:0
TX bytes:6 acl:0 sco:0 commands:2 errors:0
Features: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Packet type: DM1 DH1 HV1 
Link policy: 
Link mode: SLAVE ACCEPT 


FIX

Your linux distribution does not have firmware for this chipset. Use below command to get Open Sourvce firmware and install it


    cd /tmp
    wget https://raw.githubusercontent.com/Realtek-OpenSource/android_hardware_realtek/rtk1395/bt/rtkbt/Firmware/BT/rtl8761b_config
    wget https://raw.githubusercontent.com/Realtek-OpenSource/android_hardware_realtek/rtk1395/bt/rtkbt/Firmware/BT/rtl8761b_fw
    sudo mv rtl8761b_config /lib/firmware/rtl_bt/rtl8761b_config.bin
    sudo mv rtl8761b_fw /lib/firmware/rtl_bt/rtl8761b_fw.bin
    sudo ls -l /lib/firmware/rtl_bt/rtl8761b_config.bin /lib/firmware/rtl_bt/rtl8761b_fw.bin
    sudo modprobe btusb
    sudo systemctl start bluetooth.service
    hciconfig -a # will show that Bluetooth is up now


Usb adapter should work now!

Reference: 

https://github.com/Realtek-OpenSource/android_hardware_realtek





Wednesday, July 29, 2020

Succeeding in CKA and CKAD

Last week in July 2020, I earned CKA (98%) and CKAD (81%). Sharing my learning journey here.


PREPARATION

When Mumshad Mannambeth and https://kodekloud.com/ claimed that their courses 'CKA with Practice Test' & 'CKAD with Test' ("KK" - also available on Udemy) along with official documentation are sufficient for Certification, my initial thought was - it is an exaggeration! There are so many blogs and posts saying CKA  & CKAD are hands on tests and one of the most difficult one.


I found the claim is - true. KK is the only platform that provides hands on labs, and grades your work immediately to provide feedback on your answers. I had explored courses on Linuxacademy, Pluralsight etc. too. Labs at KK are the most resembling real exams  in look and feel.


Here is preparation bullet points:


1- Start preparation with k8s cheat sheet documentation page. A single page has invaluable tips and at least a 10% mark is hidden in a single page!


2- During test, bash-completion package was already installed on jump host (node-1) from where you need to keep changing context to access different k8s clusters. If you are doing ssh to some other node, you need to come back to node-1. So you need to set your aliases, editor variables and auto completion only on jump host.


3- Do not create too many command alias (e.g. kg, kd, kk etc). First 4 lines in the cheat sheet along with a tab for autocomplete is sufficient.


4- If you do not want to miss even 2% marks (I got 98% in CKA), then read the complete question before starting to type a single character in the terminal!


5- Each question has context written at top.  A mouse click on it will copy it. Paste it in the terminal before starting each question.


6- Before writing even a single line in any yaml file, think- is there any imperative way to do this? Some resources (pv, pvc, csr etc.) do not have - but many have. Mastering imperative commands with "-o yaml --dry-run" is key to success.


7- First thing when you edit in any yaml is - namespace (if needed).  Be aware! Some imperative commands, even you mentioned namespace option, do not write namespace in created yaml file.


8- KK includes lessons on YAML and JSON/jsonptah. Understanding of both topics are essential.


9- you can bookmark official documentation pages in Chrome browser bookmarks, but do not bookmark more than a few as official documentation search is pretty good. For example, if you search netpol or pv, the first search result is Persistent Volume and Network Policies document page respectively.


10- CKA (3 hours test) has a timer bar at the top left corner that turns Red when 1 hour is left. CKAD does not have. Proctor was proactively informing remaining time every 30 minutes.


11- I was able to complete CKA alomost 1h earlier and CKAD ….. I could not do last 2 question! why? With my CKA experience, I derived that there is enough time for me - hence I spend too much time in post verification of each question. Key is - chase your last question. You do not know if upcoming questions are comparatively easy or hard. Once you are done with all questions, spend remaining time to verify and re-chek tricky questions. I did not listen to the advice of many bloggers… and paid the price!


12- Each question has percentage weight. Cosider 4% as 4 marks. How much time you need to spend on this ( CKA : 3h x 60 minutes * .04 ~= 7.2 minutes). So if you cannot complete it in  this time, flag it for later attempt and move on.


13- If you are using vim editor, your friend is : echo 'set nu list sw=2 ts=2 expandtab' >> ~/.vimrc


14- Learn how to use explain to see all possible attributes of a k8s resource. In certain cases, it will eliminate the need to search documentation.

   kubectl explain pods --recursive | sed 's/ <.*/:/g' > pe.txt (after first /, press ctrl+v then Tab and then literal <.*/)


15- To create 3 nodes VM clusters locally, do not waste time on researching here and there. Bring it up in 15 minutes with Vagrant https://github.com/nansari/vagrant. If you are taking a KK course, just follow it. It has a full module on creating k8s HA clusters by hard way.


16- Do all Lightning Labs + Mock Labs + Labs on DaemonSet, multi-container, Ingress, NetPol exercises until you get 90% right within given time


17- Read about all kubeadm init option even you have not used it and think that you are not going to use it. 


18- In the last one week test your learning by solving free 'Games of Pods'. It will teach you a few more things, test your knowledge and shake your beliefs too!


19- Occasionally, there will be a discount offer 15-30% by Linux Foundation, or even more during Black Friday. Continue your preparation and purchase exam at a later date.


20- Finally, are these tests hard as many posts and blogs claim? Depends - how did you prepare? Get yourself ~3-4 months. If planning to take CKAD and CKA both, attempt CKAD first.



PRE-EXAM

1- Schedule your exam 10-15 days earlier to get a favorable time slot, especially for CKA. I could not find APAC favorable time and finished the exam at 2 AM!


2- If possible, avoid taking tests in late evening. You may not be able to sleep whole night with anxiety.


3- Portal will be open for login 15 minutes earlier.

- Disable ctrl+w to eliminate closing of tab accidently! On my Ubuntu, I have key mapped it to ‘nope’ a few days earlier than the test.


4- Mute mike, you do not need headphones too. All is done over chat.


5- Use two screen setups to take exams - one for the test terminal and another to browse k8s documentation.


6- Do not keep anything on your desk. Only Keep your ID proof and a bottle of water. Remove all other things beforehand as anyway proctor will ask you to remove all other items.


7- You need to move the webcam around your room to show all 4 walls, 4 corners of table and under table space.



DURING-EXAM

1- You can request a break during the exam though the timer will not stop.


2- Notepad editor located at the top right corner of the test portal is not very efficient. Whatever you write there will remain there even if you close and reopen it.

- Ctrl+C and Ctrl+v do not work for copy and paste . User Control+Insert to copy and Shift+Insert to Paste


3- if you are creating a k8s object from yaml, spend a moment to re-check yaml (especially pv, pvc and pod)  before doing apply/create on it. Once an object is created, deleting may take a couple of minutes - time is a precious resource!


POST-EXAM

1- Remember, you have a second free attempt, so switch off all your k8s related thoughts for a day until the result is delivered to your email inbox.


2- Do not expect results too early - wait for 36 hours, especially if you are in a certain time zone.


3- Celebrate your success and share your experience.



ADDITIONAL RESOURCES

Free courses

  https://www.udacity.com/course/scalable-microservices-with-kubernetes--ud615 

  https://www.edx.org/course/introduction-to-kubernetes

Book

Kubernetes: Up and Running


Do comment if you find this post valuable. Feel free to share; no creaditt required.


I'm reachable @nasim_ansari


Short url of this document : https://bit.ly/ckackad


Thursday, January 30, 2020

git - revert a file to older version away by few commits

Lets's say there is config.cfg on which 6 commits have been done. We need to revert the file to version as it was on 2nd commit.


Latest git repository looks like this after committing 6 changes:

 $ cd myapp                         
$ git init                             
Initialized empty Git repository in myapp/.git/

$ for i in 1 2 3 4 5 6               
do                                 
  echo $i >>config.cfg                 
  echo $i >>static.cfg               
  git add config.cfg static.cfg
  git commit -m "Commiting version $i"
done

[master (root-commit) 9b0d011] Commiting version 1
2 files changed, 2 insertions(+)
create mode 100644 config.cfg
create mode 100644 static.cfg
[master 68387a7] Commiting version 2
2 files changed, 2 insertions(+)
[master c16b5bb] Commiting version 3
2 files changed, 2 insertions(+)
[master 405f4c4] Commiting version 4
2 files changed, 2 insertions(+)
[master 768bb51] Commiting version 5
2 files changed, 2 insertions(+)
[master 45a8393] Commiting version 6
2 files changed, 2 insertions(+)

Version 6 of config.cfg file looks like this:

$ cat config.cfg 
1
2
3
4
5
6
$ cat static.cfg
1
2
3
4
5
6

git repository commit log look like this at this stage

$ git log --oneline 
45a8393 (HEAD -> master) Committing version 6     
768bb51 Commiting version 5                                   405f4c4 Commiting version 4                                 
c16b5bb Commiting version 3                                 
68387a7 Commiting version 2                                 
9b0d011 Commiting version 1                                                                                                          

Attempt to revert to version 2 commit fails as there are few more commit on config.cfg between version 2 and version 6.

$ git revert 68387a7   
error: could not revert 68387a7... Commiting version 2  
hint: after resolving the conflicts, mark the corrected paths 
hint: with 'git add ' or 'git rm '  
hint: and commit the result with 'git commit'                                                                                         
$ git status       
On branch master   
You are currently reverting commit 68387a7.                 
  (fix conflicts and run "git revert --continue")           
  (use "git revert --abort" to cancel the revert operation)    Changes to be committed:                                        (use "git reset HEAD ..." to unstage)                  (use "git add ..." to mark resolution)
both modified:   static.cfg

The correct way to revert to version 2 of config file is:
  1- checkout config.cfg file from version 2 commit 
  2- Check status and verify that checked out file in staging area is modified and it looks same as version 2 file
  3- commit this file on top of HEAD commit 45a8393

$ git status
On branch master
nothing to commit, working tree clean
$ git checkout 68387a7 config.cfg
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD ..." to unstage)
modified:   config.cfg

$ cat config.cfg 
1
2
$ git commit -m'Commit config file as version 2'
[master f30f027] Commit config file as version 2
1 file changed, 4 deletions(-)

        $ git log --oneline
f30f027 (HEAD -> master) Commit config file as version 2
45a8393 Commiting version 6
768bb51 Commiting version 5
405f4c4 Commiting version 4
c16b5bb Commiting version 3
68387a7 Commiting version 2
9b0d011 Commiting version 1

$ git status
On branch master
nothing to commit, working tree clean

Verify that config.cfg has been reverted back to same as version 2 and there is no change in any other file

$ cat config.cfg 
1
2
$ cat static.cfg 
1
2
3
4
5
6


Share if you know a better way!










Saturday, January 13, 2018

Puppet: concatenate existing variable to make new variable

Oftenly, we have to need to create a new variable by concatenating two existing variable. Below is some of way we can do.

CODE:

  1 $first = 'jelly'
  2 $last = 'fish'
  3 $full = "$first$last"
  4 notice("I am $full")


OUTPUT

Notice: Scope(Class[main]): I am jellyfish


Modify code in a different way to see how it change output.    

CODE:

$full = "${first}$last"

OUTPUT:  
Notice: Scope(Class[main]): I am jellyfish


CODE:

$full = "${first}${last}"

OUTPUT: 

Notice: Scope(Class[main]): I am jellyfish


CODE:
   
$full = "${first}_${last}"

OUTPUT: 

Notice: Scope(Class[main]): I am jelly_fish


CODE:

  1 $first = ['jelly', 'start']  # Now, it is list
  2 $last = 'fish'

OUTPUT: ( Possibly, this is not what you want to use)
Notice: Scope(Class[main]): I am [jelly, start]_fish


CODE: Looping using each does not work on Puppet 3

$first = ['jelly', 'star']
$last = 'fish'
$first.each | $name | {
  $full = "${name}_${last}"
  notice("I am $full")
}

OUTPUT:

Notice: Scope(Class[main]): I am jelly_fish
Notice: Scope(Class[main]): I am star_fish







Saturday, November 4, 2017

Making vagrant and virtualbox on Ubuntu 16.04

MY ENVIRONMENT

$ grep RELEASE /etc/lsb-release
DISTRIB_RELEASE=16.04
$
$ vagrant --version
Vagrant 2.0.1
$
$ VBoxManage -v
5.0.40_Ubuntur115130
$ vagrant plugin list
vagrant-hostmanager (1.8.7)
vagrant-share (1.1.9, system)
vagrant-vbguest (0.15.0)

$ vagrant plugin list
vagrant-hostmanager (1.8.7)
vagrant-share (1.1.9, system)
vagrant-vbguest (0.15.0)


STEPS TO INSTALL VITUALBOX AND VAGRANT ON UBUNTU 16.04



VIRTUALBOX

sudo apt-get install virutalbox virtualbox-dkms linux-headers-generic virtualbox-guest-x11
VBoxManage --version # if this complains about device /dev/vboxdrv, do following
sudo dpkg-reconfigure virtualbox-dkms
sudo dpkg-reconfigure virtualbox
sudo modprobe vboxdrv
sudo modprobe vboxnetctl
VBoxManage --version
sudo modprobe vboxnetadp # sudo modprobe vboxnetadp
sudo modprobe vboxnetadp #  sudo modprobe vboxnetadp


VAGRANT

sudo apt-get install vagrant
vagrant plugin install vagrant-vbguest
vagrant plugin install vagrant-hostmanager
sudo apt-get -y install dkms build-essential \
  linux-headers-$(uname -r) virtualbox-guest-additions-iso
apt-get install linux-headers-virtual


ADD A BOX IN VAGRANT
Add a box and start it as mention here 

vagrant status
vagrant ssh


SAMPLE CONFIG FILE TO START 2 VAGRANT BOXES

#Sample Vagrantfile file to start 2 ubuntu boxes
https://www.vagrantup.com/docs/multi-machine/  multi machine configuration reference
# only first machin in below config has been set to start by default

Vagrant.configure("2") do |config|

    config.vm.provider "virtualbox"
    config.vm.network "public_network", bridge: "wlp6s0"

    config.vm.provision 'shell', path: 'install_docker.sh', run: 'always'

   config.vm.define "vm1", primary: true, autostart: true do | vm1 |
      vm1.vm.box = "minimal/xenial64"
      vm1.vm.hostname = 'vm1'

      vm1.vm.provider :virtualbox do |v|
        v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
        v.customize ["modifyvm", :id, "--memory", 1024]
        v.customize ["modifyvm", :id, "--name", "vm1"]
      end
   end

   config.vm.define "vm2", autostart: false do | vm2 |
      vm2.vm.box = "minimal/xenial64"
      vm2.vm.hostname = 'vm2'

      vm2.vm.provider :virtualbox do |v|
        v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
        v.customize ["modifyvm", :id, "--memory", 1024]
        v.customize ["modifyvm", :id, "--name", "vm2"]
      end
    end
end



References:
https://gist.github.com/larsar/1687725
https://github.com/rekibnikufesin

Sunday, April 16, 2017

How to fix youtube plugin error "quota limit exceeded" on Kodi ( example illustrating OSMC)

Problem: Recently, you might have started getting an error "quota limit exceeded" when you are trying to use youtube plugin on Kodi.

Cause: Reason is - youtube plugin uses google API to get information. Non-paid version has certain Quota limit per day per API Key.

Fix: You can generate and add your own API Key and Secret.

How to Fix it?

I use OSMC on Raspberry Pi. It runs Kodi 16 and youtube plugin. I am listing file path below from my system. It may vary depending on which platform you are using youtube plugin of Kodi.

- Go to https://console.cloud.google.com
- Click on top down-drop error and click 'Create project'. Name it something like - kodi_youtube
- Go to 'API Manager' -> Credentials
- Click Credentials Tab and click 'Create Credential'
- Create API Key and OAuthr 2.0 Client ID as per below document
  https://support.google.com/cloud/answer/6158857?hl=en
- Now you have three strings (1) Client ID (2) API Key (3) Client Secret
- ssh to you kodi installation.
- Add or update (if already existing) below lines in settings.xml (my osmc absolute path is be)
>>>File Name: /home/osmc/.kodi/userdata/addon_data/plugin.video.youtube/settings.xml
>>>You need to add following lines

   
   
   



And you are done! Did this step help you?


Also refer this article.



Friday, September 23, 2016

Manually installing UEFI and grub2 on USB already have Ubuntu

You might have installed Ubuntu on USB drive ( using steps similar to my other blog)  but UEFI and grub is not installed on USB drive hence you can not use same USB drive to boot Ubuntu on other system.

A Little Theory


1-UEFI industry standard boot procedure for personal computers from 2006. Firmware of your computer hardware knows that it need to look far 'Unifed Extensible Firmware Interface' install on available storage.

2-System native firmware scans all storage devices for ESP ( EFI System Partition - a variant of vfat32 partition with boot flag enabled). gparted shows boot and esp flags for this partition. Each storage device must have only on ESP.

3-Firmware mounts this (a variant of vfat32) partition to /boot/efi and locates /boot/efi/EFI/

/*..efi file and execute it. ( remember - filename on vfat32 partition is case insensitive).  It triggers grub. This file has location of grub. See this for more detail. 

4-UEFI does not rely on boot sector. Instead it invoke boot manager like - grub. In turn, grub menu will appear. Grub configuration have /boot partition information from where  kernel and initrd will be  loaded, uncopressed and executed. they will mount root flesystem and trigger user space process init ( pid=1 ).


Installing UEFI and grub2 on a same USB from which Ubuntu is booted


You are able to boot Ubuntu installed on an USB via a chainloder boot loader and want to install EFI and grub2 on this. Follow below seps to install EFI and grub.

1-Ensure you have an ESP partition of USB Flash drive - sdX and it is mount on /boot/efi. Use gparted to check flag of this partition - boot, esp
     df -PhalT /boot/efi Filesystem Type Size Used Avail Use% Mounted on /dev/sdb2 vfat 286M 132K 286M 1% /boot/efi


2-Move old stuff somewhere and install EFI and grub

mkdir /var/tmp/boot_efi_backup
mv /boot/efi/* /var/tmp/boot_efi_backup
apt-get install --reinstall grub-efi-amd64
grub-install --removable  --boot-directory=/boot --efi-directory=/boot/efi /dev/sdX
( above command use whole disk as last argument - do not partition /dev/sdX1 )
find /boot/efi/ /boot/efi/ /boot/efi/EFI /boot/efi/EFI/BOOT /boot/efi/EFI/BOOT/BOOTX64.EFI

3-Look for some interesting thing it has.

strings /boot/efi/EFI/BOOT/BOOTX64.EFI |grep -Ei "grub|hd|setuuid|root|boot|set"|less 
 ghex /boot/efi/EFI/BOOT/BOOTX64.EFI

4-Reboot with UEFI ready USB
 


Installing EFI and grub2 on a USB having Ubuntu while booted from other Ubuntu


If you want to install EFI and grub2 on a USB having an Ubuntu by mounting it on another instance of Ubuntu, Installer Media OS, Rescue CD, Live DVD etc., follow below steps. Creates ESp partition on USB if it dows not have. If you can not create it, you can not install UEFI !

1-Mount root, boot and EFI partition
   mount /dev/sdYn  /mnt
   mount /dev/sdYn  /mnt/boot
   mount /dev/sdYp  /mnt/boot/efi

2-Take backup, chroot, install EFI and grub2

  mkdir /mnt/boot_efi_backup
  mv /mnt/boot/efi/* /mnt/boot_efi_backup/
  chroot /mnt
apt-get install --reinstall grub-efi-amd64
grub-install --removable  --target=x86_64-efi --boot-directory=/mnt/boot --efi-directory=/mnt/boot/efi /dev/sdY

4-Reboot with UEFI ready USB

Installing grub2 in BIOS mode.

If your system do not support UEFI mode, you need to install grub2 in legacy BIOS mode. It will install grub on MBR of disk sdX

apt-get install grub-pc-bin grub-install --removable --target=i386-pc --debug --boot-directory=/boot /dev/sdX