Created
January 20, 2026 22:47
-
-
Save NQevxvEtg/04ddab25e0d9fea81b7b43f40faa9308 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 1. Create LVM Map (Major:Minor -> vgname/lvname) | |
| LVM_MAP=$(sudo lvs --noheadings -o lv_kernel_major,lv_kernel_minor,vg_name,lv_name --separator : | tr -d ' ') | |
| # 2. Iterate using -P (Pairs) to handle empty columns safely. | |
| lsblk -P -n -o NAME,TYPE,FSTYPE,MAJ:MIN,MOUNTPOINT | sed 's/MAJ:MIN/MAJMIN/g' | while read -r line; do | |
| # Load variables safely | |
| eval "$line" | |
| # EXCLUSION: Skip Boot partitions | |
| if [[ "$MOUNTPOINT" == "/boot"* ]]; then | |
| continue | |
| fi | |
| # LOGIC CHECK | |
| if [ "$TYPE" == "lvm" ]; then | |
| # CASE A: LVM Logical Volume | |
| MATCH=$(echo "$LVM_MAP" | grep "^$MAJMIN:") | |
| if [ -n "$MATCH" ]; then | |
| VG=$(echo "$MATCH" | cut -d: -f3) | |
| LV=$(echo "$MATCH" | cut -d: -f4) | |
| # Output format: '/dev/mapper/vg-lv' | |
| echo "'/dev/mapper/${VG}-${LV}'" | |
| fi | |
| elif [ "$TYPE" == "crypt" ]; then | |
| # CASE B: Encrypted Mapper (LUKS/dm-crypt) | |
| if [ -n "$MOUNTPOINT" ]; then | |
| echo "'/dev/mapper/${NAME}'" | |
| fi | |
| elif [ "$TYPE" == "part" ] || [ "$TYPE" == "disk" ]; then | |
| # CASE C: Standard Partition / Raw Disk | |
| # Output format: '/dev/sdb1' | |
| if [ -n "$MOUNTPOINT" ]; then | |
| echo "'/dev/${NAME}'" | |
| fi | |
| fi | |
| done | paste -sd "," - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment