Giter VIP home page Giter VIP logo

bt-dualboot's Introduction

Sync Bluetooth for dualboot Linux and Windows

User-friendly tool making your bluetooth devices working both in Windows and Linux without re-pairing chore. more about dualboot Bluetooth issue

bt-dualboot

How to install

For developers: checkout the Developer insights for useful development and testings tips.

Usage: shortest way

Assuming you have paired devices in Windows already, boot to Linux and paired them too. Syncing would be simple as following 2 steps:

1. Mount Windows partition

Application will probe and use mounted Windows partition automatically. Otherwise use --win /mnt/win/path/. Partition should be mounted with write access.

2. Sync all devices available for sync

$ sudo bt-dualboot --sync-all

Syncing...
==========
 [C2:9E:1D:E2:3D:A5] Keyboard K380
...done

NOTES: (i) sudo tip: this tool needs read-only access to bluetooth devices configuration files which is inaccessible for regular user. (ii) --backup vs --no-backup: you will be asked about your Windows Registry backup strategy (iii) use --dry-run to preview any command effects

Usage: choose device manually

  1. List devices info
$ sudo bt-dualboot -l

Works both in Linux and Windows
===============================
 [A4:BF:C6:D0:E5:FF] WH-1000XM4

Needs sync
==========

Following devices available for sync with `--sync-all` or `--sync MAC` options.

 [C2:9E:1D:E2:3D:A5] Keyboard K380

Have to be paired in Windows
============================

Following devices unavailable for sync unless you boot Windows and pair them

 [E9:1D:FE:2A:C3:C8] JBL GO
  1. Sync devices using MAC
$ sudo bt-dualboot --sync C2:9E:1D:E2:3D:A5

Syncing...
==========
 [C2:9E:1D:E2:3D:A5] Keyboard K380
...done

See bt-dualboot -h and chapters below for details.

Prerequisites

  • Python 3.6+ installed.

  • chntpw package installed:

Ubuntu $ sudo apt install chntpw
...

see https://pogostick.net/~pnh/ntpasswd/

Install

$ sudo pip install bt-dualboot

NOTES: sudo - application requires read-only access to bluetooth devices configuration files which is inaccessible for regular user. Native OS packages will be added in next releases.

Supported OS

Tested with Linux Mint 19.3, 20.3 (Ubutntu 18.04 bionic, 20.04 focal), Windows 10

Supported:

  • Potentially any Linux-based systems keeping bluetooth configuration in similar format as Ubuntu
  • Windows 10+

With next releases more OSes will be tested, Mac OS support will be added. If you get success or fail results for any OS not listed as supported, please share your experience at #1.

Advanced usage

--backup vs --no-backup

Windows Registry update performed in the safe way using chntpw/reged without changing Hive-file's size (reged -N -E). Nevertheless chntpw is non-official tool hence backup is not bad idea. Application would perform it as you prefer.

You have to choose your backup strategy explicitly.

$ sudo bt-dualboot --sync-all 
usage: ....
bt-dualboot: error: Neither backup option given!

    Windows Registry Hive file will be updated!
    chntpw/reged tool is non-official and hackish Hive file editing tool.
    It is recommended to do backup prior writing into Hive file.

    Use:
      -b [path], --backup [path]    [default: /var/backup/bt-dualboot]
      -n, --no-backup               process without backup

    WARNING:
        Windows Registry Hive file may contain sensitive data. You shouldn't keep this file
        on a storage which may be accessed by others. Consider to remove backup files as soon
        as possible after ensure Windows boots and works correctly.

--win /mnt/win/path/

By default application will recognize and use mounted Windows partition. In case when it didn't found or more than single Windows partition exist you have to provide mount point with --win paramter.

Use --list-win-mounts to list recognized Windows partitions.

$ bt-dualboot --lsit-win-mounts

Windows locations:
==================
 /media/user/win_foo
 /media/user/win_bar
 
$ sudo bt-dualboot --win /media/user/win_foo -l

Troubleshooting: Windows partition write access

In case when Windows partition mounted in read-only mode, you have to remount it for read-write:

$ sudo mount -o remount,rw /mnt/win/path

Machine processing

--bot flag enables better parsable output for usage in scripts.

Dualboot Bluetooth issue

Every time when a Bluetooth device paired in one dualboot OS it stop working in another one. It happens because both OS uses the same Bluetooth adapter with the same MAC. Each pairing process generates new pairing keys for adapter's MAC. This way previous pairing key which saved in another OS becomes obsolete.

The solution is to sync saved pairing keys for both OS. This answer describes ways to handle this manually: https://unix.stackexchange.com/a/255510/411221

This application implements the way suggested by the comment which copies pairng keys directly from Linux to Windows avoiding multiple reboots.

Advantages and alternatives

bt-dualboot:

  • doesn't require to reboot multiple times
  • simple install
  • provides single simple cli, doesn't require invoke additional scripts
  • discower mounted Windows partition automatically
  • safe update of Windows Registry without changing file size (rewrite only)
  • backup Windows Registry prior update
  • doesn't require import/export files, handle encoding issues
  • allows --dry-run prior actual changes

alternatives

checkout "bluetooth dualboot" on github

solved by invoke single tool under Linux: sync keys from Linux into Windows registry:

(similar approach to bt-dualboot)

solved by invoke multiple tools under Windows and Linux: sync keys from Windows registry into Linux configs:

(requires more steps and reboots, involves using windows tools, manage import/export files)

Most soulutions is kind of import tool of Windows *.reg file into Linux bluetooth configuration.

Mac OS:

Cli reference

$ bt-dualboot -h
usage: bt-dualboot [-h] [-l] [--list-win-mounts] [--bot] [--dry-run] [--win MOUNT] [--sync MAC [MAC ...]] [--sync-all] [-n] [-b [path]]

Sync bluetooth keys from Linux to Windows.

optional arguments:
  -h, --help            show this help message and exit

List resources:
  -l, --list            [root required] list bluetooth devices
  --list-win-mounts     list mounted Windows locations
  --bot                 parsable output for robots (supported: -l)

Sync keys:
  --dry-run             print actions to do without invocation
  --win MOUNT           Windows mount point (advanced usage)
  --sync MAC [MAC ...]  [root required] sync specified device
  --sync-all            [root required] sync all paired devices

Backup Windows Registry:
  -n, --no-backup       process without backup
  -b [path], --backup [path]
                        path to backup directory, default: /var/backup/bt-dualboot

Next releases

First priority is to extend list of tested and supported OS.

General roadmap assumes creating GUI and background service versions, adding sync Linux to Linux ability. It will be implemented on demand - give a voice at #2

bt-dualboot's People

Contributors

j3rn avatar x2es avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bt-dualboot's Issues

Doesn't work on Ubuntu 24.04

File "/usr/lib/python3.12/configparser.py", line 759, in get
d = self._unify_values(section, vars)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/configparser.py", line 1132, in _unify_values
raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'LinkKey'

Lowcase system file

In windows the file "system" was with lower case letters and because of that the program was not working, I renamed it and it worked

Multiple BT-adapter fstring broken

When a device is paired for multiple BT-adapters, the warning produced seems to have a broken fstring.

$ sudo bt-dualboot --sync-all -b ~/Dropbox/
> BACKUP /media/yee/<device MAC>/Windows/System32/config/SYSTEM to /home/yee/Dropbox/SYSTEM-2023-12-03--14-35-20
WARNING: Following devices paired on Linux for multiple BT-adapters: { .join(problem_devices_macs)}
WARNING: Following devices paired on Windows for multiple BT-adapters: { .join(problem_devices_macs)}
Nothing to sync

Version information:

$ sudo bt-dualboot --version
bt-dualboot 1.0.1
$ python --version
Python 3.10.12

Python issues (Pop 21.10)

Hello,

thanks for your hard work. This is the first attempt. Here's the output:

otheos@kepler:~$ sudo bt-dualboot --list-win-mounts

Windows locations:
==================
 /mnt

Then,

otheos@kepler:~$ sudo bt-dualboot --win /mnt -l
Traceback (most recent call last):
  File "/usr/lib/python3.9/configparser.py", line 789, in get
    value = d[option]
  File "/usr/lib/python3.9/collections/__init__.py", line 941, in __getitem__
    return self.__missing__(key)            # support subclasses that define __missing__
  File "/usr/lib/python3.9/collections/__init__.py", line 933, in __missing__
    raise KeyError(key)
KeyError: 'class'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/bt-dualboot", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/dist-packages/bt_dualboot/cli/app.py", line 342, in main
    app.run()
  File "/usr/local/lib/python3.9/dist-packages/bt_dualboot/cli/app.py", line 252, in run
    self.list_devices()
  File "/usr/local/lib/python3.9/dist-packages/bt_dualboot/cli/app.py", line 173, in list_devices
    devices=sync_manager.devices_both_synced(),
  File "/usr/local/lib/python3.9/dist-packages/bt_dualboot/bt_sync_manager/bt_sync_manager.py", line 111, in devices_both_synced
    index = self._index_devices()
  File "/usr/local/lib/python3.9/dist-packages/bt_dualboot/bt_sync_manager/bt_sync_manager.py", line 61, in _index_devices
    linux_devices   = get_linux_devices()
  File "/usr/local/lib/python3.9/dist-packages/bt_dualboot/bt_linux/devices.py", line 40, in get_devices
    return [bluetooth_device_factory(device_path) for device_path in get_devices_paths()]
  File "/usr/local/lib/python3.9/dist-packages/bt_dualboot/bt_linux/devices.py", line 40, in <listcomp>
    return [bluetooth_device_factory(device_path) for device_path in get_devices_paths()]
  File "/usr/local/lib/python3.9/dist-packages/bt_dualboot/bt_linux/bluetooth_device_factory.py", line 55, in bluetooth_device_factory
    info = extract_info(device_info_path)
  File "/usr/local/lib/python3.9/dist-packages/bt_dualboot/bt_linux/bluetooth_device_factory.py", line 38, in extract_info
    "class":        config.get("General", "Class"),
  File "/usr/lib/python3.9/configparser.py", line 792, in get
    raise NoOptionError(option, section)
configparser.NoOptionError: No option 'class' in section: 'General'

Thanks.

Config parser error: no LinkKey section

Listing devices gives me the following error

Traceback (most recent call last):
  File "/usr/bin/bt-dualboot", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python3.10/site-packages/bt_dualboot/cli/app.py", line 342, in main
    app.run()
  File "/usr/lib/python3.10/site-packages/bt_dualboot/cli/app.py", line 252, in run
    self.list_devices()
  File "/usr/lib/python3.10/site-packages/bt_dualboot/cli/app.py", line 173, in list_devices
    devices=sync_manager.devices_both_synced(),
  File "/usr/lib/python3.10/site-packages/bt_dualboot/bt_sync_manager/bt_sync_manager.py", line 111, in devices_both_synced
    index = self._index_devices()
  File "/usr/lib/python3.10/site-packages/bt_dualboot/bt_sync_manager/bt_sync_manager.py", line 61, in _index_devices
    linux_devices   = get_linux_devices()
  File "/usr/lib/python3.10/site-packages/bt_dualboot/bt_linux/devices.py", line 40, in get_devices
    return [bluetooth_device_factory(device_path) for device_path in get_devices_paths()]
  File "/usr/lib/python3.10/site-packages/bt_dualboot/bt_linux/devices.py", line 40, in <listcomp>
    return [bluetooth_device_factory(device_path) for device_path in get_devices_paths()]
  File "/usr/lib/python3.10/site-packages/bt_dualboot/bt_linux/bluetooth_device_factory.py", line 55, in bluetooth_device_factory
    info = extract_info(device_info_path)
  File "/usr/lib/python3.10/site-packages/bt_dualboot/bt_linux/bluetooth_device_factory.py", line 39, in extract_info
    "pairing_key":  config.get("LinkKey", "Key"),
  File "/usr/lib/python3.10/configparser.py", line 782, in get
    d = self._unify_values(section, vars)
  File "/usr/lib/python3.10/configparser.py", line 1153, in _unify_values
    raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'LinkKey'

The command I used

sudo bt-dualboot -l

And reinstalling seems not working.

bt-dualboot: 1.0.1
Python: 3.10.7
OS: Arch Linux with kernel 5.19.11-arch1-1

Syncsing devices with same name

If both device has the same name, but different MAC, tool able to detect and sync only one of them, even by supplying mac address of second device by:

sudo bt-dualboot --sync A0:AB:51:92:52:59 --backup
> BACKUP /run/media/calcifer/D49EB9E49EB9BF74/Windows/System32/config/SYSTEM to /var/backup/bt-dualboot/SYSTEM-2022-09-21--14-13-18
WARNING: Following devices paired on Linux for multiple BT-adapters: { .join(problem_devices_macs)}
WARNING: Following devices paired on Windows for multiple BT-adapters: { .join(problem_devices_macs)}
ERROR: Can't push A0:AB:51:92:52:59! Not found or already in sync!
Nothing changed.

Unfortunately name of devices is unchangeable (two DualSence controllers, if it matters).
Report from list option (missing second controller with MAC A0:AB:51:92:52:59):

sudo bt-dualboot -l
WARNING: Following devices paired on Linux for multiple BT-adapters: { .join(problem_devices_macs)}
WARNING: Following devices paired on Windows for multiple BT-adapters: { .join(problem_devices_macs)}

Works both in Linux and Windows
===============================
 [D8:37:3B:47:B2:29] JBL Flip 5
 [48:18:8D:55:25:1A] Wireless Controller

Needs sync
==========

Following devices available for sync with `--sync-all` or `--sync MAC` options.

 [DC:2C:26:DC:00:16] None

TypeError: 'NoneType' object is not subscriptable

This was the command (MOUNT is being replace with the actual path)

Python 3.12 PopOS 22.04 LTS

sudo bt-dualboot --win MOUNT --sync-all -n

Traceback (most recent call last):
File "/usr/local/bin/bt-dualboot", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.10/dist-packages/bt_dualboot/cli/app.py", line 342, in main
app.run()
File "/usr/local/lib/python3.10/dist-packages/bt_dualboot/cli/app.py", line 262, in run
self.sync_all()
File "/usr/local/lib/python3.10/dist-packages/bt_dualboot/cli/app.py", line 228, in sync_all
devices_for_push = sync_manager.devices_needs_sync()
File "/usr/local/lib/python3.10/dist-packages/bt_dualboot/bt_sync_manager/bt_sync_manager.py", line 129, in devices_needs_sync
index = self._index_devices()
File "/usr/local/lib/python3.10/dist-packages/bt_dualboot/bt_sync_manager/bt_sync_manager.py", line 61, in _index_devices
linux_devices = get_linux_devices()
File "/usr/local/lib/python3.10/dist-packages/bt_dualboot/bt_linux/devices.py", line 40, in get_devices
return [bluetooth_device_factory(device_path) for device_path in get_devices_paths()]
File "/usr/local/lib/python3.10/dist-packages/bt_dualboot/bt_linux/devices.py", line 40, in
return [bluetooth_device_factory(device_path) for device_path in get_devices_paths()]
File "/usr/local/lib/python3.10/dist-packages/bt_dualboot/bt_linux/bluetooth_device_factory.py", line 60, in bluetooth_device_factory
mac=macs["device_mac"],
TypeError: 'NoneType' object is not subscriptable

Restore the Windows registry backup?

Hi, sorry if this is a noob question, I'm not very familiar with Windows. I've got bt-dualboot ver 1.0.1 and I synced the keys from Linux to Windows partition with the backup option enabled. Now I'm pretty sure I needed to do it the other way around (keys from Win to Linux). How do I use the created Windows reg backup?

typo in readme

$ bt-dualboot --lsit-win-mounts

Windows locations:

/media/user/win_foo
/media/user/win_bar

lsit should be list

ERROR: None Windows locations found, use `--win MOUNT` to point actual Windows location

Installation step

Tool could not be installed from sudo pip install because of below error

Error message
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try 'pacman -S
    python-xyz', where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Arch-packaged Python package,
    create a virtual environment using 'python -m venv path/to/venv'.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip.
    
    If you wish to install a non-Arch packaged Python application,
    it may be easiest to use 'pipx install xyz', which will manage a
    virtual environment for you. Make sure you have python-pipx
    installed via pacman.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

So installed from AUR with
❯ yay -S bt-dualboot

Commands outputs

❯ sudo bt-dualboot -l
ERROR: None Windows locations found, use `--win MOUNT` to point actual Windows location

❯ sudo bt-dualboot --list-win-mounts 
ERROR: None Windows locations found, use `--win MOUNT` to point actual Windows location

OS

Window 10 Home
EndeavourOS

How do I get the path to pass for --win parameter?

Support for multiboot Linux/Linux/Windows

Just read the README, it seems this is already planned but there is no issue for tracking it so here is one I guess.

readme.md

General roadmap assumes creating GUI and background service versions, adding sync Linux to Linux ability. It will be implemented on demand - give a voice at #2

Doesn't work when the same device connected to multiple bt-adapters.

          I'm using Fedora Silverblue 37 and Windows 10 (I'll update the version shortly).  I was ultimately unsuccessful with using the script.  First, the script crashed because evidently the `info` file for my Logitech MX Master 3S does not contain the `LinkKey` key.  Not sure what this means, but I removed it as a bluetooth device and was able to proceed.

The issue that ultimately prevented me from was this:

WARNING: Following devices paired on Windows for multiple BT-adapters: <headphone mac>

I do have two bluetooth adapters in my desktop; one is built-in to the motherboard and scarcely works, the other is an external one that I use. Indeed, my headphones have been, at different times, connected to each. I tried just about everything, but could not figure out how to get this error to go away. I wound up extracting the key by hand.

Originally posted by @J3RN in #1 (comment)

No LinkKey

$ sudo ./bt-dualboot --sync-all --no-backup --dry-run
Traceback (most recent call last):
  File "/home/shared/conda/bin/./bt-dualboot", line 8, in <module>
    sys.exit(main())
  File "/home/shared/conda/lib/python3.9/site-packages/bt_dualboot/cli/app.py", line 342, in main
    app.run()
  File "/home/shared/conda/lib/python3.9/site-packages/bt_dualboot/cli/app.py", line 262, in run
    self.sync_all()
  File "/home/shared/conda/lib/python3.9/site-packages/bt_dualboot/cli/app.py", line 228, in sync_all
    devices_for_push = sync_manager.devices_needs_sync()
  File "/home/shared/conda/lib/python3.9/site-packages/bt_dualboot/bt_sync_manager/bt_sync_manager.py", line 129, in devices_needs_sync
    index = self._index_devices()
  File "/home/shared/conda/lib/python3.9/site-packages/bt_dualboot/bt_sync_manager/bt_sync_manager.py", line 61, in _index_devices
    linux_devices   = get_linux_devices()
  File "/home/shared/conda/lib/python3.9/site-packages/bt_dualboot/bt_linux/devices.py", line 40, in get_devices
    return [bluetooth_device_factory(device_path) for device_path in get_devices_paths()]
  File "/home/shared/conda/lib/python3.9/site-packages/bt_dualboot/bt_linux/devices.py", line 40, in <listcomp>
    return [bluetooth_device_factory(device_path) for device_path in get_devices_paths()]
  File "/home/shared/conda/lib/python3.9/site-packages/bt_dualboot/bt_linux/bluetooth_device_factory.py", line 55, in bluetooth_device_factory
    info = extract_info(device_info_path)
  File "/home/shared/conda/lib/python3.9/site-packages/bt_dualboot/bt_linux/bluetooth_device_factory.py", line 39, in extract_info
    "pairing_key":  config.get("LinkKey", "Key"),
  File "/home/shared/conda/lib/python3.9/configparser.py", line 781, in get
    d = self._unify_values(section, vars)
  File "/home/shared/conda/lib/python3.9/configparser.py", line 1152, in _unify_values
    raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'LinkKey'

How did this happen?

Feature Requests

If you'd like to see new feature, here is best place to ask for it.

Revert registry changes

I've run the program to sync one device (with the backup flag enabled) between Fedora Linux and Windows 11, but now Bluetooth isn't working at all on my Windows installation. None of the Bluetooth devices I've tried to connect to have been able to connect.

I have since "forgotten" the device through Windows settings, removed it through bluetoothctl on Linux and factory reset the Bluetooth device itself, but still cannot connect to it nor any other Bluetooth device.

Is there some way I can restore my registry using the generated backup or revert the changes done?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.