對於第一個,你可以找出什麼是裝在一個給定的掛載點與此(至少在Arch Linux的這個作品,我不知道如何安裝的輸出可能是在不同的系統不同) :
awk '$2 == "/" && $1 != "rootfs" { print($1); exit; }' /proc/mounts
將打印出裝在根上的任何設備文件。另外,您可以使用「=〜」(matches)運算符來針對正則表達式測試該字符串。因此,你可以做類似
# Save the device file's name into ROOTMOUNT env variable.
ROOTMOUNT="$(awk '$2 == "/" && $1 != "rootfs" { print($1); exit; }' /proc/mounts)"
# Check to see if it is a sd device or an hd device.
if [[ "$ROOTMOUNT" =~ "/dev/sd[a-z][0-9]" ]]; then
echo "It's a SD!";
elif [[ "$ROOTMOUNT" =~ "/dev/hd[a-z][0-9]" ]]; then
echo "It's an HD!";
else
echo "I don't think it's either, but on the other hand,"
echo "this script was just slapped together so it probably needs work."
fi
而你必須做一些擺弄它。
對於第二個,你應該使用UUID來掛載你的設備而不是設備文件名。執行以下步驟以瞭解更多內容
man fstab
man mount
那些應該有一些很好的信息來啓動你。
更好地使用'/ proc/mounts'來代替'mount'的輸出。然後你會得到這樣的「root」分區:'awk'$ 2 ==「/」&& $ 1!=「rootfs」{print($ 1);出口; }'/ proc/mounts' –
謝謝!我不記得存儲在哪裏。我會編輯我的答案。 –