Commit 5572e8a3 authored by Natanael Copa's avatar Natanael Copa

setup-disk: fix find_disks

The old way did not detect ida/c0d0. The new should detect it.
We also filter out md devices.
parent f1cce1c1
...@@ -146,25 +146,47 @@ find_swap_size() { ...@@ -146,25 +146,47 @@ find_swap_size() {
has_mounted_part() { has_mounted_part() {
local p local p
# parse /proc/mounts for moutned devices # parse /proc/mounts for mounted devices
for p in $(awk '$1 ~ /^\/dev\// {gsub("/dev/", "", $1); print $1}' \ for p in $(awk '$1 ~ /^\/dev\// {gsub("/dev/", "", $1); print $1}' \
/proc/mounts); do /proc/mounts); do
if [ -e /sys/block/$1/$p ]; then [ -e /sys/block/$1/$p ] && return 0
return 0
fi
done done
return 1 return 1
} }
has_holders() {
local i
# check if device is used by any md devices
for i in $1/holders/* $1/*/holders/*; do
[ -e "$i" ] && return 0
done
return 1
}
is_available_disk() {
local dev=$1
local b=$(echo $p | sed 's:/:!:g')
# check if its a "root" block device and not a partition
[ -e /sys/block/$b ] || return 1
# check so it does not have mounted partitions
has_mounted_part $dev && return 1
# check so its not part of an md setup
has_holders /sys/block/$b && return 1
# check so its not an md device
[ -e /sys/block/$b/md ] && return 1
return 0
}
find_disks() { find_disks() {
local p= disks= local p=
for p in $(awk '$1 ~ /[0-9]+/ {print $4}' /proc/partitions); do for p in $(awk '$1 ~ /[0-9]+/ {print $4}' /proc/partitions); do
b=$(echo $p | sed 's:/:!:g') is_available_disk $p && echo -n " $p"
if [ -e /sys/block/$b/device ] && ! has_mounted_part $p; then
disks="$disks $p"
fi
done done
echo $disks
} }
useall() { useall() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment