Skip to content

Commit

Permalink
Exclude loop devices from lsblk
Browse files Browse the repository at this point in the history
7 - is device major number for loop devices.

'-e 7' to 'lsblk' excludes all loop devices.
  • Loading branch information
SRIKKANTH authored and LiliDeng committed Dec 30, 2024
1 parent 519263b commit 5c24bb0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lisa/tools/lsblk.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,18 @@ def get_disks(self, force_run: bool = False) -> List[DiskInfo]:
# -b print SIZE in bytes rather than in human readable format
# -J output in JSON format
# -o list of columns to output
# -e exclude devices by major number, '-e 7' excludes loop devices
cmd_result = self.run(
"-b -J -o NAME,SIZE,TYPE,MOUNTPOINT,FSTYPE", sudo=True, force_run=force_run
"-e 7 -b -J -o NAME,SIZE,TYPE,MOUNTPOINT,FSTYPE",
sudo=True,
force_run=force_run,
)
output = cmd_result.stdout
if cmd_result.exit_code != 0 and re.match(
self._INVAILD_JSON_OPTION_PATTERN, output
):
output = self.run(
"-b -P -o NAME,SIZE,TYPE,MOUNTPOINT,FSTYPE",
"-e 7 -b -P -o NAME,SIZE,TYPE,MOUNTPOINT,FSTYPE",
sudo=True,
force_run=force_run,
).stdout
Expand Down

0 comments on commit 5c24bb0

Please sign in to comment.