新闻详情

新闻详情

首页 / 资讯中心 / 详情

lsblk Command in Linux: Syntax, Options Practical Examples (Block Devices)

发布时间:2026/9/20 11:51:14来源:尧图网络
lsblk Command in Linux: Syntax, Options  Practical Examples (Block Devices)
lsblk — quick referenceDefault listingShow the block-device tree with name, size, type, and mount points — no root required.When to useCommandDefault tree of all block deviceslsblkLimit output to one disk and its childrenlsblk /dev/sdaList format (one line per device, no tree branches)lsblk -lShow disks only — skip partition childrenlsblk -dHide empty devices with no holderslsblk -AFilesystems and identifiersSee filesystem type, UUID, and usage alongside block layout.When to useCommandAdd filesystem type, label, UUID, and use% columnslsblk -fPrint full/dev/...paths in the NAME columnlsblk -pPrint sizes in bytes instead of human unitslsblk -b /dev/sdaShow owner, group, and device node permissionslsblk -m /dev/sdaColumns, filters, and layoutPick columns, sort, and hide device classes you do not care about.When to useCommandChoose explicit columnslsblk -o NAME,SIZE,TYPE,MOUNTPOINTSExclude devices by major number (hide loop devices: major 7)lsblk -e7ASCII tree characters only (safe for logs)lsblk -iTree layout with the-Tformatterlsblk -TSort by a column (for example size)lsblk -x SIZESkip the header rowlsblk -nDependencies, topology, and scriptingTrace holders, inspect queue settings, or emit JSON for scripts.When to useCommandShow inverse dependencies (which disk holds this partition)lsblk -s /dev/sda1Print topology columns (alignment, scheduler, rotational)lsblk -tJSON output for parserslsblk -JList available output column nameslsblk --list-columnsHelp and versionWhen to useCommandShow brief usagelsblk --helpShow util-linux versionlsblk --versionlsblk — command syntaxSynopsis fromlsblk --helpon Ubuntu 25.04 (util-linux 2.40.2):textCopylsblk [options] [device ...]lsblkreads the kernel block layer and udev; it does not change partitions or filesystems. Pair it with parted orfdiskwhen you need to create or resize partitions.lsblk — command examplesExpand or collapse all examples below to scan titles quickly or open every step at once.Expand allCollapse allRunlsblkwith no arguments when you want a quick map of disks, partitions, LVM volumes, and loop devices on the host.Run the command:bashCopylsblkSample output:outputNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 4K 1 loop /snap/bare/5 sda 8:0 0 25G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 2G 0 part /boot └─sda3 8:3 0 23G 0 part └─ubuntu--vg-ubuntu--lv 252:0 0 58.4G 0 lvm / sdb 8:16 0 35.4G 0 disk └─ubuntu--vg-ubuntu--lv 252:0 0 58.4G 0 lvm /Tree branches show parent/child relationships:sda3is a partition; the LVM logical volume underneath is where/is mounted.TYPEtells you disk, part, lvm, or loop.Before mounting or editing/etc/fstab,-fadds filesystem columns so you can match UUIDs without a separateblkidcall.Run the command:bashCopylsblk -f /dev/sdaSample output:outputNAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS sda ├─sda1 ├─sda2 ext4 1.0 c254a326-948a-4ae2-993b-1659f4ddcf03 1.5G 17% /boot └─sda3 LVM2_member LVM2 001 xLar7A-0CSb-mAmp-Y2sy-s6KG-FtEP-kIBAUL └─ubuntu--vg-ubuntu--lv ext4 1.0 72457fae-1731-4c94-b5c1-ac4564f4311c 35.5G 34% /FSTYPEon the partition showsLVM2_memberwhen that partition is a physical volume; the filesystem type appears on the logical volume row.Pass a device path to limit the tree to that disk — handy on servers with many SAN LUNs.Run the command:bashCopylsblk /dev/sdaSample output:outputNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 25G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 2G 0 part /boot └─sda3 8:3 0 23G 0 part └─ubuntu--vg-ubuntu--lv 252:0 0 58.4G 0 lvm /MAJ:MINis the kernel major:minor number.ROset to1means the device is read-only (common for squashfs loops).Desktop Ubuntu hosts often have dozens of snap loop devices. Major number7is the loop driver — exclude it to see only real disks.Run the command:bashCopylsblk -e7Sample output:outputNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 25G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 2G 0 part /boot └─sda3 8:3 0 23G 0 part └─ubuntu--vg-ubuntu--lv 252:0 0 58.4G 0 lvm / sdb 8:16 0 35.4G 0 disk └─ubuntu--vg-ubuntu--lv 252:0 0 58.4G 0 lvm / sr0 11:0 1 50.7M 0 rom /media/golinuxcloud/VBox_GAs_7.2.0Add more major numbers to the exclude list separated by commas if needed (-e7,11also hides the CD-ROM).-opicks exactly the fields you want.MOUNTPOINTSsupports multiple mount points per device on newer util-linux.Run the command:bashCopylsblk -o NAME,SIZE,TYPE,MOUNTPOINTSSample output:outputNAME SIZE TYPE MOUNTPOINTS loop0 4K loop /snap/bare/5 sda 25G disk ├─sda1 1M part ├─sda2 2G part /boot └─sda3 23G part └─ubuntu--vg-ubuntu--lv 58.4G lvm /Runlsblk --list-columnsto see every available column name on your build.When you are about to runmount,fsck, ordd,-pprints complete/dev/...paths so you do not guess the node name.Run the command:bashCopylsblk -p /dev/sdaSample output:outputNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS /dev/sda 8:0 0 25G 0 disk ├─/dev/sda1 8:1 0 1M 0 part ├─/dev/sda2 8:2 0 2G 0 part /boot └─/dev/sda3 8:3 0 23G 0 part └─/dev/mapper/ubuntu--vg-ubuntu--lv 252:0 0 58.4G 0 lvm /Copy paths directly into commands — still double-check before destructive operations.Scripts and configuration management tools often parse JSON more reliably than ASCII trees.Run the command:bashCopylsblk -J /dev/sdaSample output:output{ blockdevices: [ { name: sda, maj:min: 8:0, rm: false, size: 25G, ro: false, type: disk, mountpoints: [ null ], children: [ { name: sda1, maj:min: 8:1, rm: false, size: 1M, ro: false, type: part, mountpoints: [ null ] },{Pipe throughjqfor field extraction, for examplelsblk -J | jq .blockdevices[].name.If you have a partition device and need the parent disk (for example beforeddor cloning),-swalks upward.Run the command:bashCopylsblk -s /dev/sda1Sample output:outputNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda1 8:1 0 1M 0 part └─sda 8:0 0 25G 0 diskThe child appears first; parents stack below with tree markers.lsblk — when to use / when notUse lsblk whenUse something else whenYou want a readable tree of disks, partitions, LVM volumes, and mount pointsYou need filesystem type, UUID, or usage% next to device names (-f)You are scripting with JSON (-J) or custom columns (-o)You must confirm which disk holds a partition before resize or wipe (-s)You are troubleshooting missing mounts or unexpected loop devicesYou need to create or resize partitions → parted orfdiskYou need inode-level detail or bad blocks → filesystem tools (dumpe2fs,xfs_info)You are creating LVM physical volumes → pvcreate andvgdisplayYou only need UUID for fstab and already know the device →blkidYou want to mount a filesystem → mountlsblk vs fdisk / blkidlsblkfdisk -l / blkidLayoutIndented tree with holdersFlat list or one line per FSMount pointsBuilt inNot infdisk; partial inblkidLVM mappingShows LV under PV/partitionNeeds extra toolsChanges disksRead-onlyfdiskis for editing tablesUselsblkfirst for orientation; switch topartedorfdiskwhen you are ready to change partition tables.lsblk — interview cornerlsblklistsblock devices— kernel-level disk nodes under/dev— in a hierarchy. Disks sit at the top; partitions, LVM logical volumes, and device-mapper nodes appear as children. Columns usually include size, read-only flag, device type, and where the filesystem is mounted.It is read-only and fast. Admins run it beforefdisk,resize2fs, or LVM extend work to confirm they are targeting the correct device.A strong answer is:lsblk prints a tree of block devices — disks, partitions, LVM volumes, loops — with sizes and mount points. I use it as a read-only map before any disk-changing command.fdisk -lreads partition tables and prints geometry and partition types — it is the tool you use beforewritinga new table.lsblkshows how therunning systemsees devices, including LVM and mount points, in a tree. It does not display every partition-table fieldfdiskshows.Use both:lsblkfor layout and mounts;fdisk -lor parted when you need sector-level partition detail or plan changes.A strong answer is:lsblk is a live tree with mounts and LVM; fdisk -l is partition-table detail for editing. I start with lsblk for orientation, fdisk or parted when Im changing partitions.Snap and container tooling creates manyloopdevices (major number 7). Exclude them:bashCopylsblk -e7You can pass multiple majors:lsblk -e7,11drops loops and CD-ROM (sr0, major 11). On busy desktops this keeps the tree focused on real disks.A strong answer is:Loop devices are major 7 — I run lsblk -e7 to hide them when snap loops clutter the output.-faddsfilesystemcolumns:FSTYPE,UUID,LABEL, and usage percentages where available. That is exactly what you need when:Writing or checking/etc/fstabby UUIDConfirming which partition is ext4 versus LVM2_memberSeeing if/bootstill has free spaceIt replaces a separateblkidcall for a quick overview.A strong answer is:lsblk -f shows filesystem type, UUID, label, and use% beside the device tree — I use it before fstab edits or when tracing which partition holds which FS.Pass-Jfor JSON or-owith a fixed column list for grep-friendly lines. Add-nto drop headers in pipelines.bashCopylsblk -J -o NAME,SIZE,TYPE,MOUNTPOINTSParse withjqin shell or feed into Ansible facts. JSON includes nestedchildrenarrays that mirror the tree.A strong answer is:For scripts I use lsblk -J or lsblk -n -o with explicit columns, then parse with jq — it is more stable than scraping the ASCII tree.TroubleshootingSymptomLikely causeFixExpected disk missingDriver not loaded or multipath aliasdmesg, check/dev/disk/by-id/; install HBA driverPartition not listedTable not written or whole-disk FSsudo parted /dev/sdX print;fdisk -lMOUNTPOINTSempty but disk in useUnmounted or LVM not activatedmount;sudo vgchange -ayHuge loop device listSnap / flatpak loopslsblk -e7Wrong size shownRecent resize, kernel cachesudo partprobe; re-runlsblklsblk: command not foundutil-linux not installedsudo apt install util-linux
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

CANN Runtime 模型任务回退实战:基于 Model RI 的 Task 级参数切换与禁用 2026/9/20 11:49:12

CANN Runtime 模型任务回退实战:基于 Model RI 的 Task 级参数切换与禁用

CANNAscend人工智能任务调度 【免费下载链接】runtime 本项目提供CANN运行时组件和维测功能组件。 项目地址: https://gitcode.com/cann/runtime 点击查看 免费下载 本技术指南围绕开源仓库 cann/runtime 中的示例 example/6_scenarios/fault_tolerant_exec/0_mode…

阅读更多 →
清理 package.json:5 个可安全删除的 npm 依赖及迁移指南 2026/9/20 11:49:12

清理 package.json:5 个可安全删除的 npm 依赖及迁移指南

1. 为什么现在可以动手清理 package.json 了如果你维护过超过两年的前端项目,打开package.json的那一刻大概率会有一种翻旧仓库的感觉:有些依赖你根本想不起来当初为什么装,有些依赖的 GitHub 仓库已经两年没提交,还有些依赖你每次…

阅读更多 →
chezmoi ejson 模板函数详解:`ejsonDecrypt` 与 `ejsonDecryptWithKey` 在 dotfiles 中的安全密钥解密实践 2026/9/20 11:49:12

chezmoi ejson 模板函数详解:`ejsonDecrypt` 与 `ejsonDecryptWithKey` 在 dotfiles 中的安全密钥解密实践

chezmoi ejson 模板函数详解:ejsonDecrypt 与 ejsonDecryptWithKey 在 dotfiles 中的安全密钥解密实践 【免费下载链接】chezmoi Manage your dotfiles across multiple diverse machines, securely. 项目地址: https://gitcode.com/gh_mirrors/ch/chezmoi 本…

阅读更多 →
RocketMQ 客户端负载均衡机制深度解析:Producer 发送与 Consumer 订阅的全链路原理 2026/9/20 11:49:12

RocketMQ 客户端负载均衡机制深度解析:Producer 发送与 Consumer 订阅的全链路原理

RocketMQ 客户端负载均衡机制深度解析:Producer 发送与 Consumer 订阅的全链路原理 【免费下载链接】rocketmq Apache RocketMQ is a cloud native messaging and streaming platform, making it simple to build event-driven applications. 项目地址: https://g…

阅读更多 →
Pipenv 贡献开发指南:环境搭建、Owned vs Vendored 代码治理与测试体系全解析 2026/9/20 11:49:12

Pipenv 贡献开发指南:环境搭建、Owned vs Vendored 代码治理与测试体系全解析

Pipenv 贡献开发指南:环境搭建、Owned vs Vendored 代码治理与测试体系全解析 【免费下载链接】pipenv Python Development Workflow for Humans. 项目地址: https://gitcode.com/gh_mirrors/pi/pipenv Pipenv 是"为人类设计的 Python 开发工作流"…

阅读更多 →
urfave/cli v2 旗标(Flag)实战指南:定义、取值源、优先级与校验的完整解析 2026/9/20 11:46:12

urfave/cli v2 旗标(Flag)实战指南:定义、取值源、优先级与校验的完整解析

CLI开发工具 【免费下载链接】cli A declarative, simple, fast, and fun package for building command line tools in Go 项目地址: https://gitcode.com/gh_mirrors/cli1/cli 点击查看 免费下载 导读 旗标(Flag,即命令行选项&#xff09…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞