Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This script is just meant to clean up the mountpoints of the Btrfs
- # (pseudo-RAID / JBOD) partition (data: single, metadata: raid1) on my
- # SD cards. For some reason it gets automatically remounted sometimes,
- # appending higher and higher numbers to the name of the mountpoint. So
- # this script will unmount all the ones except the first one.
- regex="^\/run\/media\/${USER}\/SD_BTRFS([0-9]+)$"
- mapfile -t lines < <(mount -t btrfs)
- for (( i = 0; i < ${#lines[@]}; i++ )); do
- line="${lines[${i}]}"
- mapfile -d' ' -t line_parts <<<"$line"
- line_parts[-1]="${line_parts[-1]%$'\n'}"
- dev="${line_parts[0]}"
- mnt_pt="${line_parts[2]}"
- if [[ ! -b $dev ]]; then
- continue
- fi
- if [[ $mnt_pt =~ $regex ]]; then
- printf '\n%s\n' "${mnt_pt}: unmounting..."
- sudo umount "$mnt_pt"
- fi
- done
- printf '\n'
Advertisement
Add Comment
Please, Sign In to add comment