Resize a devlink Device Resource Safely with devlink
You will inspect a devlink device, identify the exact resource path it exposes, save the current allocation, and resize that resource with devlink resource set. The examples use the command shipped by iproute2 6.1.0. Allow about 10 minutes, plus time to confirm that changing the device will not interrupt work using it.
The route
Jump straight to the step you need, or tick off Done means at the end.
Before you start
You need the devlink command and a device managed through devlink. The installed command reports its version like this:
devlink -V
On this machine the result is:
devlink utility, iproute2-6.1.0
You also need the device identifier in the form BUS_NAME/BUS_ADDRESS. For a PCI device, that commonly looks like pci/0000:01:00.0. Replace that example with the identifier for your own device. Reading resources is normally a non-mutating operation, but access to device information can still be restricted by system policy. Resizing requires elevated privileges.
1. Check that the resource commands are available
Start with the command's built-in help. This confirms the local syntax without touching a device:
devlink resource help
The relevant operations are show, which displays resources, and set, which changes one resource's size. The installed manpage does not define a universal resource list or a default device, so do not copy a resource path from an unrelated adapter.
2. Record the current resource tree
Set a shell variable to your actual device identifier, then show its resources:
DEV='pci/0000:01:00.0'
devlink resource show "$DEV"
Expected output is a device-specific resource listing. It should give you the resource names or paths and their current sizes. The exact output depends on the driver and hardware; an empty guess is not a safe basis for a change.
Save the output before continuing. A simple terminal capture is enough:
devlink resource show "$DEV" | tee devlink-resource-before.txt
Checkpoint: you should now have the exact device identifier, the exact resource path, and the old size written down. If the command reports that the device does not exist, stop and correct DEV. Do not try alternate paths at random.
3. Select one resource and its new size
The resource path is passed separately from the device. The manpage example uses /kvd/linear; that path is only an example, not a promise that your device provides it.
Choose a new size supported by the driver and hardware. Keep the old size from the captured listing so you can restore it if necessary. For example, if your listing shows the resource /kvd/linear and you have deliberately chosen 98304 as the new size:
RESOURCE_PATH='/kvd/linear'
NEW_SIZE='98304'
Do not treat the number as a universal unit conversion. The devlink interface accepts a resource size, while the device driver determines what values are valid and how the resource is represented.
4. Warn users and apply the change
Changing a device resource can affect the device's capacity and may be rejected or disruptive depending on the driver and what is using the device. Schedule the change appropriately, stop or drain dependent workloads when your device documentation requires it, and make sure you have console access for recovery.
Now run the mutating command with elevated privileges:
sudo devlink resource set "$DEV" path "$RESOURCE_PATH" size "$NEW_SIZE"
Success may produce no output. A diagnostic instead means the requested path, size, device state, or permissions were not accepted. Treat a successful return as acceptance by the command, not as proof that the intended allocation is present until you inspect it.
5. Verify the resulting allocation
Read the resource tree again and compare it with the saved output:
devlink resource show "$DEV" | tee devlink-resource-after.txt
Confirm that the intended path reports the requested size and that unrelated resources still have the values you expect. If the resource is missing, unchanged, or the command fails, keep the before and after captures for diagnosis and do not repeat the change with a different guessed path.
6. Restore the old size if you need to undo the change
The resource command has no separate undo operation. Restore the recorded old size by running the same command with that value:
OLD_SIZE='REPLACE_WITH_THE_RECORDED_OLD_SIZE'
sudo devlink resource set "$DEV" path "$RESOURCE_PATH" size "$OLD_SIZE"
devlink resource show "$DEV"
Replace the placeholder before pressing Enter. If the driver rejects the old value after other device changes, stop and follow the hardware or driver documentation rather than forcing more allocations. A reboot or device reset is not a generic recovery instruction and should only be used when the device documentation explicitly supports it.
Common traps
- Wrong device syntax:
DEVmust beBUS_NAME/BUS_ADDRESS, not a friendly interface name such aseth0. - Copied resource path: resource paths are device-specific. Get yours from
devlink resource show. - Missing privileges: use ordinary privileges for inspection where permitted, and
sudoforresource set. - Unrecorded old size: without the before capture, restoration becomes guesswork. Stop before changing anything if you have not saved it.
- Assuming silence means the desired state: rerun
resource showand compare the reported value.
Done means
- You identified the device as
BUS_NAME/BUS_ADDRESS. - You captured the original resource listing.
- You used a path and size shown or justified by the target device.
- You applied the change with the required privileges.
- A second
devlink resource showconfirmed the resulting size. - You retained the old size and know the command needed to restore it.