MDEVCTL(8)
π MDEVCTL(8) β System Manager's Manual π
okay bestie, welcome to mdevctl, part of the System Manager's Manual family. grab a snack, this one's a whole vibe. π§
β¨ NAME β¨
mdevctl β Mediated device management utility π
πΈ SYNOPSIS πΈ
mdevctl {COMMAND} [OPTIONS...]
lsmdev [OPTIONS...]
π¦ DESCRIPTION π¦
so like, mdevctl is a utility for managing and persisting devices in the mediated device device framework of the Linux kernel. yes the name has "device device" in it, we don't talk about it. π
Mediated devices are sub-devices of a parent device (ex. a vGPU) which can be dynamically created and potentially used by drivers like vfio-mdev for assignment to virtual machines. it's giving "little baby device that belongs to a bigger device and gets handed to a VM". iconic honestly. π
lsmdev is an alias for mdevctl list. literally just that. same thing, cuter name. β¨
π OPTIONS π
The following options are understood:
--addattr=ATTRIBUTEβ Add an attribute ATTRIBUTE. Valid for themodifycommand. π-a|--autoβ Automatically start the device on parent availability. Valid fordefineandmodifycommands.-d|--definedβ List all defined devices, even if not active. Valid for thelistcommand. Also: modify the defined configuration of a device, even if the device is active. Valid for themodifycommand.--delattrβ Delete an attribute entry. Valid for themodifycommand.--dumpjsonβ Dump the configuration for a device in JSON format when filtered to as single device and used with thelistcommand. When used with thetypescommand, output machine readable type information. π€-i|--index=INDEXβ Act on the attribute INDEX. Valid for themodifycommand.--jsonfile=FILEβ Read the configuration for a device from a JSON file FILE. Valid for thedefineandstartcommands.-l|--liveβ Modify active device without modifying the defined configuration of the device. Valid for themodifycommand.-m|--manualβ Do not start a device automatically on parent availability. Valid for themodifycommand.-p|--parent=PARENTβ Specify or identify the device by its parent device. Note that the parent device is specified by its kernel sysfs name and is case-sensitive. lowercase girlies stay losing on this one, fr fr. π-t|--type=TYPEβ Specify or identify the device by its type.-u|--uuid=UUIDβ Specify or identify the device by its UUID.--value=VALUEβ Set an attribute to VALUE, in the format accepted by the attribute. Valid for themodifycommand.-v|--verboseβ Increase output verbosity, currently only adds attribute output to thelistcommand. it's not doing a lot but it's doing its best. π«Ά-V|--versionβ Printmdevctlversion.
π COMMANDS π
The following commands are understood:
define DEVICESPECβ Define a config for an mdev device, identified either by an UUID (if the device already exists), or by the parent device and either the type or a JSON configuration file, and, optionally, the UUID. If no UUID is specified, one is autogenerated and printed. If no file is used,-a|--automay be used to specify that the device should be started automatically. πlistβ List mdev devices. With no options, currently running devices are listed. With-d|--defined, previously defined devices are listed. Can be restricted to list only devices for a given parent or UUID. With--dumpjsonoutput is provided in machine readable JSON format. When a UUID is provided and the output results in a single device, the JSON output format is compatible with the configuration file format. β¨modify DEVICESPECβ Modify the configuration for an mdev device, identified via its UUID and optionally its parent. Type and startup mode (auto or manual) can be modified by this command. Attributes can be added or deleted. Attributes to be deleted must be specified by their index; if an attribute is specified without an index, it is appended at the end of the attribute list. Active devices are unaffected by this command; changes in the configuration are applied the next time the device is started. Depending on installed callout scripts active devices can be modified. With-l|--livemodifications can be applied to active devices if a callout scripts supports the eventlive. The option-d|--definedalso direct the modification to the started device configuration. πstart DEVICESPECβ Start a mediated device. This command can be used to start either a previously-defined device or a newly-created transient device.
If the UUID and optional parent argument matches an existing device definition, then the existing device will be started. It is an error to specify a device type that conflicts with the existing device definition. π¨
If the UUID argument is omitted or if the specified UUID and parent does not match an existing device definition, a new transient device will be started. If the UUID is omitted, a new UUID will be automatically generated. When starting a new transient device, the parent and device type must be specified. A --jsonfile may replace the --type specification and also include additional attributes in JSON format to be applied to the started device. π₯
stop DEVICESPECβ Stop an mdev device, specified via its UUID. πtypesβ List the mdev device types known to the system by parent device. Output may be limited to a single parent device with the-p|--parentoption. JSON output format is used with the--dumpjsonoption.undefine DEVICESPECβ Undefine, or remove the configuration for an mdev device, specified by its UUID and optionally its parent. If a UUID exists for multiple parents, all of them will be removed unless restricted to a single parent. Running devices are unaffected by this command. (they're fine, they're thriving, they don't even know.) π
π NOTE ON DEVICE SPECIFICATION π
For a given UUID, only one device with that UUID may be running at the same time. However, it is possible to define multiple devices with the same UUID under different parent devices. Therefore, it is sometimes necessary to specify the parent device alongside the UUID to uniquely identify a device. iykyk. π«Ά
β EXIT STATUS β
On success, 0 is returned, a non-zero failure code otherwise. classic. π
β¨ EXAMPLES β¨
Okay bestie, this is the part where it all clicks. Grab a snack π, because we're about to run through literally every vibe of mdevctl and it's so satisfying.
π The Basics
First up, peep which mdev devices are out here running:
# mdevctl list
85006552-1b4b-45ef-ad62-de05be9171df 0000:00:02.0 i915-GVTg_V4_4
83c32df7-d52e-4ec1-9668-1f3c7e4df107 0000:00:02.0 i915-GVTg_V4_8 (defined)
See that lil (defined) tag at the end? That's the device telling you it's both running and defined. Iconic double duty. π
Now let's see just the defined ones β the saved-for-later girlies:
# mdevctl list -d
83c32df7-d52e-4ec1-9668-1f3c7e4df107 0000:00:02.0 i915-GVTg_V4_8 auto
b0a3989f-8138-4d49-b63a-59db28ec8b48 0000:00:02.0 i915-GVTg_V4_8 auto
5cf14a12-a437-4c82-a13f-70e945782d7b 0000:00:02.0 i915-GVTg_V4_4 manual
Notice the last column: auto vs manual. That's the start-up energy, and we will be changing it, don't you worry. π
π¦ What types does the host even support?
Vibe check on the hardware, let's go:
# mdevctl types
0000:00:02.0
i915-GVTg_V4_2
Available instances: 1
Device API: vfio-pci
Description: low_gm_size: 256MB high_gm_size: 1024MB fence: 4 resolution: 1920x1200 weight: 8
i915-GVTg_V4_1
Available instances: 0
Device API: vfio-pci
Description: low_gm_size: 512MB high_gm_size: 2048MB fence: 4 resolution: 1920x1200 weight: 16
i915-GVTg_V4_8
Available instances: 4
Device API: vfio-pci
Description: low_gm_size: 64MB high_gm_size: 384MB fence: 4 resolution: 1024x768 weight: 2
i915-GVTg_V4_4
Available instances: 3
Device API: vfio-pci
Description: low_gm_size: 128MB high_gm_size: 512MB fence: 4 resolution: 1920x1200 weight: 4
Every type under its parent device, with how many instances are still up for grabs, the Device API, and a whole Description of the specs. π Lowkey the most useful thing you'll run all day, ngl.
πΈ Flip a device from auto to manual
Feeling bossy? Same. Let's change a defined device so it stops auto-starting:
# mdevctl modify --uuid 83c32df7-d52e-4ec1-9668-1f3c7e4df107 --manual
# mdevctl list -d
83c32df7-d52e-4ec1-9668-1f3c7e4df107 0000:00:02.0 i915-GVTg_V4_8 manual
b0a3989f-8138-4d49-b63a-59db28ec8b48 0000:00:02.0 i915-GVTg_V4_8 auto
5cf14a12-a437-4c82-a13f-70e945782d7b 0000:00:02.0 i915-GVTg_V4_4 manual
Look at her!! First line went from auto β‘οΈ manual and honestly, growth. π§
π₯ Stop a running mdev device
Sometimes you just gotta say bye:
# mdevctl stop -u 83c32df7-d52e-4ec1-9668-1f3c7e4df107
That's it. That's the whole thing. Clean, simple, no notes. π
β Start a device that isn't defined yet
New device, who dis? Make yourself a fresh UUID first:
# uuidgen
6eba5b41-176e-40db-b93e-7f18e04e0b93
# mdevctl start -u 6eba5b41-176e-40db-b93e-7f18e04e0b93 -p 0000:00:02.0 --type i915-GVTg_V4_1
# mdevctl list
85006552-1b4b-45ef-ad62-de05be9171df 0000:00:02.0 i915-GVTg_V4_4
6eba5b41-176e-40db-b93e-7f18e04e0b93 0000:00:02.0 i915-GVTg_V4_1
Boom. Brand new -u UUID, pointed at parent -p 0000:00:02.0, typed as i915-GVTg_V4_1, and she shows up in the running list. Main character debut fr fr. π
π Promote that new mdev to a defined device
Running is cute, but defined is forever:
# mdevctl define --uuid 6eba5b41-176e-40db-b93e-7f18e04e0b93
# mdevctl list -d
83c32df7-d52e-4ec1-9668-1f3c7e4df107 0000:00:02.0 i915-GVTg_V4_8 manual
6eba5b41-176e-40db-b93e-7f18e04e0b93 0000:00:02.0 i915-GVTg_V4_1 manual
b0a3989f-8138-4d49-b63a-59db28ec8b48 0000:00:02.0 i915-GVTg_V4_8 auto
5cf14a12-a437-4c82-a13f-70e945782d7b 0000:00:02.0 i915-GVTg_V4_4 manual
She's in the defined list now, baby!! Certified icon behavior. π
π ADVANCED EXAMPLES (ATTRIBUTES AND JSON) π
Okay this is the deep end, bestie. But you're built for this. π«Ά
Starting point β one defined device, vibing:
# mdevctl list -d
783e6dbb-ea0e-411f-94e2-717eaad438bf matrix vfio_ap-passthrough manual
π Add some attributes
Attributes go in one at a time, and they stack up in order like a little friendship bracelet. Watch the indices climb:
# mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --addattr=assign_adapter --value=5
# mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --addattr=assign_adapter --value=6
# mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --addattr=assign_domain --value=0xab
# mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --addattr=assign_control_domain --value=0xab
# mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --addattr=assign_domain --value=4
# mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --addattr=assign_control_domain --value=4
# mdevctl list -dv
783e6dbb-ea0e-411f-94e2-717eaad438bf matrix vfio_ap-passthrough manual
Attrs:
@{0}: {"assign_adapter":"5"}
@{1}: {"assign_adapter":"6"}
@{2}: {"assign_domain":"0xab"}
@{3}: {"assign_control_domain":"0xab"}
@{4}: {"assign_domain":"4"}
@{5}: {"assign_control_domain":"4"}
See how -dv gave us that whole Attrs: block with the @{0}, @{1}, @{2}β¦ indices? That's your receipt. Every --addattr just appends to the end. Obsessed. β¨
π Dump the JSON configuration
Want the raw truth? Ask for JSON:
# mdevctl list -d -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --dumpjson
{
"mdev_type": "vfio_ap-passthrough",
"start": "manual",
"attrs": [
{
"assign_adapter": "5"
},
{
"assign_adapter": "6"
},
{
"assign_domain": "0xab"
},
{
"assign_control_domain": "0xab"
},
{
"assign_domain": "4"
},
{
"assign_control_domain": "4"
}
]
}
Look at that. mdev_type, start, and attrs β the whole device laid bare. It's giving... structure. It's giving... clarity. π§
π Remove some attributes
Said too much? Take it back β by --index, from the top down:
# mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --delattr --index=5
# mdevctl modify -u 783e6dbb-ea0e-411f-94e2-717eaad438bf --delattr --index=4
# mdevctl list -dv
783e6dbb-ea0e-411f-94e2-717eaad438bf matrix vfio_ap-passthrough manual
Attrs:
@{0}: {"assign_adapter":"5"}
@{1}: {"assign_adapter":"6"}
@{2}: {"assign_domain":"0xab"}
@{3}: {"assign_control_domain":"0xab"}
Heads up bestie: indices shift when you delete! That's why we went--index=5first, then--index=4. Go from the back so your numbering doesn't get messy. π
π Define an mdev device from a file
You can also just hand it a JSON file and let it cook:
# cat vfio_ap_device.json
{
"mdev_type": "vfio_ap-passthrough",
"start": "manual",
"attrs": [
{
"assign_adapter": "5"
},
{
"assign_domain": "0x47"
},
{
"assign_domain": "0xff"
}
]
}
# mdevctl define -p matrix --jsonfile vfio_ap_device.json
e2e73122-cc39-40ee-89eb-b0a47d334cae
# mdevctl list -dv
783e6dbb-ea0e-411f-94e2-717eaad438bf matrix vfio_ap-passthrough manual
Attrs:
@{0}: {"assign_adapter":"5"}
@{1}: {"assign_adapter":"6"}
@{2}: {"assign_domain":"0xab"}
@{3}: {"assign_control_domain":"0xab"}
e2e73122-cc39-40ee-89eb-b0a47d334cae matrix vfio_ap-passthrough manual
Attrs:
@{0}: {"assign_adapter":"5"}
@{1}: {"assign_domain":"0x47"}
@{2}: {"assign_domain":"0xff"}
Two devices, two totally different Attrs: lists, living in harmony. And notice mdevctl define printed out the new UUID it made for you: e2e73122-cc39-40ee-89eb-b0a47d334cae. So thoughtful. π«Ά
πΈ CONFIGURATION FILE FORMAT πΈ
So those config files we keep feeding it? They're JSON. And here's the tea: the "attrs" field is optional β you can absolutely skip it, no cap.
{
"mdev_type": "TYPE",
"start": "auto|manual",
"attrs": [
{
"attribute0": "VALUE"
},
{
"attribute1": "VALUE"
}
]
}
Break it down:
"mdev_type"β the type of the mdev, written as"TYPE"."start"β either"auto"or"manual". Pick your girl."attrs"β optional, an array of objects. Each object holds one"attribute0"/"VALUE"pair, then"attribute1"/"VALUE", and so on down the list.
That's the whole format, bestie. Simple, readable, and it'll never text you back with drama. π
π INVOKING EXTERNAL SCRIPTS FOR DEVICE EVENTS π
okay so bestie, here's the tea: mdevctl is not a lone wolf. it supports calling out to external scripts to handle extra device-type-specific config stuff, and to broadcast notifications about changes or updates to a device. these scripts get invoked before, after, and/or during mdevctl's "primary command execution" β think writing the device configuration file for define, or activating a device for start. slay.
essentially, the procedure in mdevctl looks like this:
- command-line parsing & setup
- invoke live-command call-out [1]
- invoke pre-command call-out
- primary command execution [2]
- invoke post-command call-out [2]
- invoke notifier
[1] executed only if live update is requested.
[2] skipped if step invoke pre-command call-out fails.
π EVENT SCRIPTS π
a call-out or notification event invokes a script along with a set of parameters detailing the type of call-out, mdevctl's command execution progress, and the mediated device. the parameters are as follows:
<CONFIG> | SCRIPT <-t=type -e=event -a=action -s=state -u=UUID
-p=parent>
CONFIGβ the device's JSON configuration, provided via standard input.-t=typeβ the device type.-e=eventβ event type of call-out that is invoked. for call-out scripts, this may bepre,live,post, orget. for notification scripts, this will always benotify.-a=actionβ an action synonymous with an mdevctl command (e.g.define,start).-s=stateβ a trinary state of the mdevctl command execution. the possibilities arenoneif the mdevctl command has yet to execute,successif the mdevctl command completed successfully, orfailureif there was a problem executing the mdevctl command.-u=UUIDβ UUID of the mediated device.-p=parentβ parent of the mediated the device.
πΈ CALL-OUT EVENT SCRIPTS πΈ
a call-out event script is invoked during a live, pre, post or get event. mdevctl will attempt each script stored in the mdevctl callouts directory until either a script that satisfies the device type is found or all scripts have been attempted. a device script must check the "TYPE" parameter to make sure the specified device type is supported, otherwise error code 2 should be returned. if no script is found for the specified device type, then mdevctl will carry on as normal. no drama. π
these scripts are stored in /usr/lib/mdevctl/scripts.d/callouts. the same script is invoked for live, pre, post, and get call-out events for the device type.
β‘ Live-Command β‘
a live-command call-out event is invoked once before the pre-command call-out event execution. this only happens if the live option is specified on the modify command and the device modified is active. event type is live. state will always be none.
if the live command line option is specified, any non-zero return code results in a live modification failure β except for all call-outs returning with return code 2, which results in a live update not supported information. the return code is disruptive if also the option defined is provided and will prevent the update of the defined device configuration.
a notification event will follow if the live command line option is specified.
this event is only supported for the modify command.
π¦ Pre-Command π¦
a pre-command call-out event is invoked once prior to primary command execution. event type is pre. state will always be none.
any non-zero return code (exempting 2) will prevent mdevctl from performing the primary command execution and mdevctl will abort early. π¨
a notification event will follow only if an error code (exempting 2) is observed.
this event is not supported for thelist,types, orversioncommands.
β¨ Post-Command β¨
a post-command call-out event is invoked once after primary command execution. event type is post. state will be success if mdevctl was able to finish primary command execution successfully, or failure otherwise.
the same script used for the pre event is used for the post event.
any return code is non-disruptive. we love a chill queen.
a notification event will always follow a post-command call-out.
this event is not supported for thelist,types, orversioncommands.
π Get-attributes π
a get event is invoked during a define and list command to acquire device attributes from an active device. event type is get. action is attributes. state is none. note that, unlike other call-outs events, get-attributes does not expect a device config on stdin, and an array of JSON formatted device attributes is returned via stdout.
the same script used for the pre event is used for the get event. if the script is not designed to support a get event, then the return code is 0.
for define, a non-zero return code (exempting 2) will disrupt the define command entirely.
for list, any return code is non-disruptive.
a script must return a JSON formatted array of device attributes on standard output. example:
[
{
"attribute0": "VALUE"
},
{
"attribute1": "VALUE"
}
]
π Get-capabilities π
a get event is invoked on every new mdevctl execution to find a matching script supporting versioning for the device type. event type is get. action is capabilities. state is none. note that, unlike other call-outs events, get-capabilities provides a versioning JSON on stdin, and expects a versioning JSON is returned via stdout. the provided JSON on stdin explains in provides which actions and events mdevctl supports. the information is offered to the script to derive its supported actions and events from but it there is no obligation for scripts to follow this pattern. a valid versioning JSON response provides in supports the supported actions in actions and the supported events in events.
if a valid versioning JSON is returned on stdout by the script and the return code is NOT 2 the script is considered a positive match for the provided device type. a script providing versioning is the primary choice for a device type when mdevctl is executing callouts β or in other words, if a script which supports versioning is found the script is used for every event and action for the device type. should no versioning supporting script be found the none versioning search pattern is used.
a script is provided on standard in with a versioning JSON describing the mdevctl supported version, actions and events. example:
{
"provides": {
"version": 1,
"actions": [
"start",
"stop",
"define",
"undefine",
"modify",
"attributes",
"capabilities"
],
"events": [
"pre",
"post",
"notify",
"get"
]
}
}
a script that wants to support versioning must return a versioning JSON on standard output. the script should list all supported actions in the actions array and all supported events in the events array. it is possible to add additional actions or events in the array but if mdevctl did not have these in the arrays in provides they are ignored. example:
{
"supports": {
"version": 1,
"actions": [
"start",
"stop",
"define",
"undefine",
"modify",
"attributes",
"capabilities"
],
"events": [
"pre",
"post",
"notify",
"get"
]
}
}
π AUTO-START CALL-OUTS π
for each device set to start automatically during system boot, mdevctl will invoke the pre and post events. action is the string start.
return code and notification event behavior is the same as documented for the pre and post events. errors reported by a script will disrupt the auto-start for that particular device and the message will be reported to the system log before attempting to the next auto-start device.
heads up bestie π β note that if a notification script is used to convey information to another program or daemon during the auto-start procedure, it is not guaranteed that the program will already be active prior to mdevctl's invocation (e.g. the auto-start event may occur before the libvirt daemon is activated). so like, timing is not your friend here.
π NOTIFICATION EVENT SCRIPTS π
notification event scripts may be used to signal the state of the mediated device or the state of an mdevctl command to other programs or loggers. unlike call-out scripts, notifier scripts are device-type agnostic. periodt.
π Notify π
a notification event is invoked once either following a pre-command call-out failure or after a post-command call-out. event is notify. if following a pre event, then state will be none. if following a post event, then state will mirror the value passed to the post-command call-out.
these scripts are stored in /usr/lib/mdevctl/scripts.d/notifiers. all notification scripts will be invoked during a notification event.
a non-zero return code is ignored. we simply do not care.
this event is not supported for thelist,types, orversioncommands.
π SCRIPT RETURN VALUES π
a call-out script should return one of the following values:
0if OK,1if an error occurred,2if the script does not support the device type
π FILES π
/etc/mdevctl.d/*
configuration files are in one subdirectory per parent device and named by UUID.
/usr/lib/mdevctl/scripts.d/callouts/*
scripts for pre/post/get call-out events. NOTE: these scripts were previously located at /etc/mdevctl.d/scripts.d/callouts/*, but that location is now deprecated.
/usr/lib/mdevctl/scripts.d/notifiers/*
scripts for notification call-out events. NOTE: these scripts were previously located at /etc/mdevctl.d/scripts.d/notifiers/*, but that location is now deprecated.
π«Ά SEE ALSO π«Ά
udev(7), udevadm(8), driverctl(8)
and that's the whole page bestie, we ate and left absolutely no crumbs π
β¨ this was MDEVCTL(8) β go forth and mediate those devices, you iconic main character ππ¦π
π¦ where this page comes from
- debian trixie: mdevctl 1.4.0-2+b1 Β· LGPL-2.1-only
- fedora 43: mdevctl 1.4.0-2.fc43 Β· LGPL-2.1-only
- opensuse-leap 16.0: mdevctl 1.3.0-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: mdevctl 1.3.0-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: mdevctl 1.3.0-160000.2.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: mdevctl 1.3.0-160000.2.2 Β· LGPL-2.1-or-later
- ubuntu questing: mdevctl 1.4.0-1ubuntu2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms