Ubuntu環境下,如何使用下指令的方式查詢「額外驅動程式」

測試環境

以下測試是在「Xubuntu 14.04 64位元」。

緣起

在「回答別人問題」的時候,在「這一頁
看到一個指令「ubuntu-drivers」,是屬於「ubuntu-drivers-common」這個套件。

用法

顯示說明

1
$ ubuntu-drivers -h

顯示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
usage: ubuntu-drivers [-h] [--package-list PATH] <command>

List/install driver packages for Ubuntu.

positional arguments:
<command> See below

optional arguments:
-h, --help show this help message and exit
--package-list PATH Create file with list of installed packages (in
autoinstall mode)

Available commands:
autoinstall: Install drivers that are appropriate for automatic installation.
debug: Print all available information and debug data about drivers.
list: Show all driver packages which apply to the current system.
devices: Show all devices which need drivers, and which packages apply to them.

以「裝在Virtualbox的系統」為例

執行

1
$ sudo ubuntu-drivers devices

會顯示

1
2
3
4
5
== /sys/devices/pci0000:00/0000:00:04.0 ==
modalias : pci:v000080EEd0000CAFEsv00000000sd00000000bc08sc80i00
vendor : InnoTek Systemberatung GmbH
model : VirtualBox Guest Service
driver : virtualbox-guest-dkms - distro non-free

執行

1
$ sudo ubuntu-drivers list

會顯示

1
virtualbox-guest-dkms

也就是說你可以執行下面的指令,來安裝套件「virtualbox-guest-dkms」。

1
$ sudo apt-get install virtualbox-guest-dkms

執行

1
$ sudo ubuntu-drivers debug

會顯示

1
2
3
4
5
6
7
8
9
10
=== log messages from detection ===

...略...

=== modaliases in the system ===

...略...

=== matching driver packages ===
virtualbox-guest-dkms: installed: 4.3.18-dfsg-1 available: 4.3.18-dfsg-1 (auto-install) [distro] non-free modalias: pci:v000080EEd0000CAFEsv00000000sd00000000bc08sc80i00 path: /sys/devices/pci0000:00/0000:00:04.0 vendor: InnoTek Systemberatung GmbH model: VirtualBox Guest Service

以「我的系統」為例

執行

1
$ sudo ubuntu-drivers devices

會顯示

1
2
3
4
5
6
7
8
9
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00000421sv00001458sd0000344Abc03sc00i00
vendor : NVIDIA Corporation
model : ...略...
driver : nvidia-331 - distro non-free recommended
driver : nvidia-304 - distro non-free
driver : xserver-xorg-video-nouveau - distro free builtin
driver : nvidia-331-updates - distro non-free
driver : nvidia-304-updates - distro non-free

執行

1
$ sudo ubuntu-drivers list

會顯示

1
2
3
4
nvidia-304-updates
nvidia-331
nvidia-331-updates
nvidia-304

也就是說你可以執行下面的指令,來安裝套件「nvidia-331-updates 」。

1
$ sudo apt-get install nvidia-331-updates

執行

1
$ sudo ubuntu-drivers debug

會顯示

1
2
3
4
5
6
7
8
9
10
=== log messages from detection ===

...略...

=== modaliases in the system ===

...略...

=== matching driver packages ===
...略...

探索套件

查詢「ubuntu-drivers」是屬於哪個套件

1
$ dpkg -S ubuntu-drivers

查詢

1
$ apt-cache show ubuntu-drivers-common

顯示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Package: ubuntu-drivers-common
Priority: optional
Section: admin
Installed-Size: 279
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Version: 1:0.2.91.7
Replaces: jockey-common, jockey-gtk, jockey-kde, nvidia-common (<< 1:0.2.46)
Provides: jockey-common, jockey-gtk, jockey-kde, nvidia-common
Depends: python3:any (>= 3.3.2-2~), python3, debconf (>= 0.5.00) | debconf-2.0, libc6 (>= 2.4), libdrm2 (>= 2.4.3), libpciaccess0 (>= 0.10.7), pciutils, python3-apt, python3-xkit, udev (>= 204-0ubuntu4~), usbutils, alsa-utils, kmod | module-init-tools
Pre-Depends: dpkg (>= 1.15.7.2)
Suggests: python3-aptdaemon.pkcompat
Conflicts: jockey-common, jockey-gtk, jockey-kde, nvidia-common (<< 1:0.2.46)
Breaks: nvidia-prime (<< 0.6)
Filename: pool/main/u/ubuntu-drivers-common/ubuntu-drivers-common_0.2.91.7_amd64.deb
Size: 45418
MD5sum: 98a4b560f7fbcee58c57a23cbc649577
SHA1: 10bba00ac17bfe5b19450fe532ce982f7b703146
SHA256: f0f20ebfb6a25052cb7095ea478f8d73d1ea921038f95ec24673c2ba1d5c0d1a
Description-en: Detect and install additional Ubuntu driver packages
This package aggregates and abstracts Ubuntu specific logic and knowledge
about third-party driver packages. It provides:
.
- a Python API for detecting driver packages for a particular piece of
hardware or the whole system.
.
- an "ubuntu-drivers" command line tool to list or install driver packages
(mostly for integration in installers).
.
- a PackageKit plugin for WhatProvides() for types MODALIAS and
HARDWARE_DRIVER, to do the same queries as above through the PackageKit API
(for using in non-distro specific GUIs). This works with aptdaemon's
PackageKit compatibility layer (python3-aptdaemon.pkcompat) and with
PackageKit's apt backend, but _not_ with the PackageKit aptcc backend.
.
- some NVidia specific support code to find the most appropriate driver
version, as well as setting up the alternatives symlinks that the
proprietary NVidia and FGLRX packages use.
Description-md5: de3e80d0ec34be991721f7a39da892ac
Enhances: packagekit-system-interface
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 5y
Task: ubuntu-desktop, ubuntu-usb, kubuntu-desktop, kubuntu-active, kubuntu-active-desktop, kubuntu-active, edubuntu-desktop, edubuntu-usb, xubuntu-desktop, mythbuntu-frontend, mythbuntu-desktop, mythbuntu-backend-slave, mythbuntu-backend-master, mythbuntu-backend-master, lubuntu-core, ubuntustudio-desktop, ubuntu-gnome-desktop

建立工作環境

1
2
3
mkdir ~/Downloads/ubuntu-drivers-common
cd ~/Downloads/ubuntu-drivers-common
mkdir download source

探索「Source Package」-「ubuntu-drivers-common」

下載原始碼套件「ubuntu-drivers-common」,並解開

1
2
cd ~/Downloads/ubuntu-drivers-common/source
apt-get source ubuntu-drivers-common

觀看有哪些檔案

1
tree ubuntu-drivers-common-0.2.91.7

顯示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
ubuntu-drivers-common-0.2.91.7
├── Changes.txt
├── COPYING
├── debhelper
│   ├── dh_modaliases
│   ├── modaliases.pm
│   └── test_dh_modaliases
├── debian
│   ├── changelog
│   ├── compat
│   ├── control
│   ├── copyright
│   ├── dh-modaliases.install
│   ├── po
│   │   ├── POTFILES.in
│   │   └── templates.pot
│   ├── rules
│   ├── source
│   │   └── format
│   ├── tests
│   │   ├── control
│   │   └── system
│   ├── ubuntu-drivers-common.apport
│   ├── ubuntu-drivers-common.config
│   ├── ubuntu-drivers-common.install
│   └── ubuntu-drivers-common.templates
├── detect-plugins
│   ├── arm-gles.py
│   ├── open-vm-dkms.py
│   └── sl-modem.py
├── nvidia-common
├── nvidia-detector
├── NvidiaDetector
│   ├── alternatives.py
│   ├── __init__.py
│   └── nvidiadetector.py
├── nvidia-installer-hooks
│   └── pre-install
├── PKG-INFO
├── quirks
│   ├── dell_latitude
│   ├── lenovo_thinkpad
│   └── put_your_quirks_here
├── Quirks
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── quirkapplier.py
│   ├── quirkapplier.pyc
│   ├── quirkinfo.py
│   ├── quirkinfo.pyc
│   ├── quirkreader.py
│   └── quirkreader.pyc
├── quirks-handler
├── README
├── setup.py
├── share
│   ├── fake-devices-wrapper
│   ├── hybrid
│   │   ├── gpu-manager.c
│   │   ├── gpu-manager.conf
│   │   └── Makefile
│   └── obsolete
├── tests
│   ├── 0-test.py
│   ├── 0-test.pyc
│   ├── fakesysfs.pyc
│   ├── gpu-manager.py
│   ├── __init__.py
│   ├── quirkreader-test.py
│   ├── quirkreader-test.pyc
│   ├── run
│   ├── settings.py
│   ├── settings.pyc
│   ├── testarchive.py
│   ├── testarchive.pyc
│   ├── ubuntu_drivers.py
│   ├── ubuntu_drivers.pyc
│   └── xorg.conf
├── ubiquity
│   └── target-config
│   └── 31ubuntu_driver_packages
├── ubuntu-drivers
└── UbuntuDrivers
├── detect.py
├── __init__.py
├── kerneldetection.py
└── PackageKit.py

16 directories, 70 files

觀看README

1
$ cat ubuntu-drivers-common-0.2.91.7/README

顯示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
ubuntu-drivers-common
=====================

This package aggregates and abstracts Ubuntu specific logic and knowledge
about third-party driver packages, and provides APIs for installers and driver
configuration GUIs. It also contains some NVidia specific support code to find
the most appropriate driver version (as we usually ship several), as well as
setting up the alternatives symlinks that the proprietary NVidia and FGLRX
packages use.

Command line interface
----------------------
The simplest frontend is the "ubuntu-drivers" command line tool. You can use
it to show the available driver packages which apply to the current system
(ubuntu-drivers list), or to install all drivers which are appropriate for
automatic installation (sudo ubuntu-drivers autoinstall), which is mostly
useful for integration into installers.

Please see "ubuntu-drivers --help" for details.


Python API
----------
The UbuntuDrivers.detect Python module provides some functions to detect the
system's hardware, matching driver packages, and packages which are eligible
for automatic installation.

The three main functions are:

"Which driver packages apply to this system?"

packages = UbuntuDrivers.detect.system_driver_packages()

"Which devices need drivers, and which packages do they need?"

driver_info = UbuntuDrivers.detect.system_device_drivers()

"Which driver package(s) applies to this piece of hardware?"

import apt
apt_cache = apt.Cache
apt_packages = UbuntuDrivers.detect.packages_for_modalias(apt_cache, modalias)

These functions only use python-apt. They do not need any other dependencies,
root privileges, D-BUS calls, etc.


PackageKit API
--------------
If you want to integrate driver lookups in software which should not be
distribution specific, or is not written in Python, you should use the
PackageKit API instead of the UbuntuDrivers.detect Python module. In
particular, ubuntu-drivers-common ships PackageKit plugins for the
"WhatProvides" PackageKit query for the types "MODALIAS" (corresponding to
UbuntuDrivers.detect.packages_for_modalias()), and "HARDWARE_DRIVER"
(corresponding to UbuntuDrivers.detect.system_driver_packages()).
This also works with aptdaemon's PackageKit compatibility layer
(python-aptdaemon.pkcompat), which is the preferred PackageKit API
implementation in Ubuntu.

Please see

https://www.packagekit.org/gtk-doc/PackageKit-pk-client-sync.html#pk-client-what-provides

about the WhatProvides() API, and

https://gitorious.org/packagekit/packagekit/blobs/master/docs/provides-component-naming.txt

for details about the various WhatProvides types.

Examples:

From Python:

>>> from gi.repository import PackageKitGlib
>>> pk = PackageKitGlib.Client()

>>> res = pk.what_provides(PackageKitGlib.FilterEnum.NONE, PackageKitGlib.ProvidesEnum.MODALIAS, ["pci:v000010DEd000007E3sv00sd00bc03sc00i00"], None, lambda p, t, d: True, None)
>>> res.get_exit_code()
<enum PK_EXIT_ENUM_SUCCESS of type PkExitEnum>
>>> for p in res.get_package_array(): print p.get_id()
nvidia-current;295.53-0ubuntu1;amd64;Ubuntu
nvidia-current-updates;295.53-0ubuntu1;amd64;Ubuntu

>>> res = pk.what_provides(PackageKitGlib.FilterEnum.NONE, PackageKitGlib.ProvidesEnum.HARDWARE_DRIVER, ["drivers_for_attached_hardware"], None, lambda p, t, d: True, None)
>>> res.get_exit_code()
<enum PK_EXIT_ENUM_SUCCESS of type PkExitEnum>
>>> for p in res.get_package_array(): print p.get_id()
open-vm-dkms;2011.12.20-562307-0ubuntu1;all;Ubuntu

Using the pkcon command line tool:

$ pkcon what-provides "pci:v000010DEd000007E3sv00sd00bc03sc00i00"
Available nvidia-current-295.49-0ubuntu1.amd64 NVIDIA binary Xorg driver, kernel module and VDPAU library
Available nvidia-current-updates-295.49-0ubuntu1.amd64 NVIDIA binary Xorg driver, kernel module and VDPAU library

$ pkcon what-provides "drivers_for_attached_hardware"
Available open-vm-dkms-2011.12.20-562307-0ubuntu1.all Source for VMware guest systems driver (DKMS)


Detection logic
---------------
The principal method of mapping hardware to driver packages is to use modalias
patterns. Hardware devices export a "modalias" sysfs attribute, for example

$ cat /sys/devices/pci0000:00/0000:00:1b.0/modalias
pci:v00008086d00003B56sv000017AAsd0000215Ebc04sc03i00

Kernel modules declare which hardware they can handle with modalias patterns
(globs), e. g.:

$ modinfo snd_hda_intel
[...]
alias: pci:v00008086d*sv*sd*bc04sc03i00*

Driver packages which are not installed by default (e. g. backports of drivers
from newer Linux packages, or the proprietary NVidia driver package
"nvidia-current") have a "Modaliases:" package header which includes all
modalias patterns from all kernel modules that they ship. It is recommended to
add these headers to the package with dh_modaliases(1).

ubuntu-drivers-common uses these package headers to map a particular piece of
hardware (identified by a modalias) to the driver packages which cover that
hardware.


Custom detection plugins
------------------------
For some kinds of drivers the modalias detection approach does not work. For
example, the "sl-modem-daemon" driver requires some checks in
/proc/asound/cards and "aplay -l" to decide whether or not it applies to the
system. These special cases can be put into a "detection plugin", by adding a
small piece of Python code to /usr/share/ubuntu-drivers-common/detect/NAME.py
(shipped in ./detect-plugins/ in the ubuntu-drivers-common source). They need
to export a method

def detect(apt_cache):
# do detection logic here
return ['driver_package', ...]

which can do any kind of detection and then return the resulting set of
packages that apply to the current system. Please note that this cannot rely on
having root privileges.

探索「Package」-「ubuntu-drivers-common」

下載套件「ubuntu-drivers-common」,並解開

1
2
3
4
cd ~/Downloads/ubuntu-drivers-common/download
apt-get download ubuntu-drivers-common
dpkg -x ubuntu-drivers-common_1%3a0.2.91.7_amd64.deb ubuntu-drivers-common
dpkg -e dpkg -e ubuntu-drivers-common_1%3a0.2.91.7_amd64.deb

觀看有哪些檔案

1
$ tree ubuntu-drivers-common

顯示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
ubuntu-drivers-common
├── etc
│   └── init
│   └── gpu-manager.conf
├── usr
│   ├── bin
│   │   ├── gpu-manager
│   │   ├── nvidia-detector
│   │   ├── quirks-handler
│   │   └── ubuntu-drivers
│   ├── lib
│   │   ├── nvidia
│   │   │   └── pre-install
│   │   ├── python3
│   │   │   └── dist-packages
│   │   │   ├── NvidiaDetector
│   │   │   │   ├── alternatives.py
│   │   │   │   ├── __init__.py
│   │   │   │   └── nvidiadetector.py
│   │   │   ├── Quirks
│   │   │   │   ├── __init__.py
│   │   │   │   ├── quirkapplier.py
│   │   │   │   ├── quirkinfo.py
│   │   │   │   └── quirkreader.py
│   │   │   ├── UbuntuDrivers
│   │   │   │   ├── detect.py
│   │   │   │   ├── __init__.py
│   │   │   │   ├── kerneldetection.py
│   │   │   │   └── PackageKit.py
│   │   │   └── ubuntu_drivers_common-0.0.0.egg-info
│   │   │   ├── dependency_links.txt
│   │   │   ├── entry_points.txt
│   │   │   ├── PKG-INFO
│   │   │   └── top_level.txt
│   │   └── ubiquity
│   │   └── target-config
│   │   └── 31ubuntu_driver_packages
│   └── share
│   ├── apport
│   │   └── package-hooks
│   │   └── ubuntu-drivers-common.py
│   ├── doc
│   │   └── ubuntu-drivers-common
│   │   ├── changelog.gz
│   │   ├── copyright
│   │   └── README.gz
│   ├── python3
│   │   └── runtime.d
│   │   └── ubuntu-drivers-common.rtupdate
│   └── ubuntu-drivers-common
│   ├── detect
│   │   ├── arm-gles.py
│   │   ├── open-vm-dkms.py
│   │   └── sl-modem.py
│   ├── fake-devices-wrapper
│   ├── obsolete
│   └── quirks
│   ├── dell_latitude
│   ├── lenovo_thinkpad
│   └── put_your_quirks_here
└── var
└── lib
└── ubuntu-drivers-common

27 directories, 35 files