I'm writing a custom automated install using AIF (Arch Installation Framework), and I need to find the filesystem on a partition given a partition.
So far I have this:
grok_partitions () {
local partitions=
for label in `ls /dev/disk/by-label | grep "Arch"`
do
if [ $label == "Arch" ]
then
mount_point="/"
else
IFS="-" read base mount <<< "${label}"
mount_point="/${mount}"
fi
local partition=$(readlink -f /dev/disk/by-label/${label})
local part_no=$(echo ${partition} | grep -Po '\d+')
local fs=$(parted -mls | grep "^${part_no}" | cut -d: -f5)
partitions+="${partition} raw ${label} ${fs};yes;${mount_point};target;no_opts;${label};no_params\n"
done
# do the swap
if [ -e /dev/disk/by-label/swap ]
then
local partition=$(readlink -f /dev/disk/by-label/swap)
partitions+="$partition raw swap swap;yes;no_mountpoint;target;no_opts;swap;no_params"
else
# if there's no labeled swap, use the first one we find
local partition=$(fdisk -l | grep -m1 swap | awk '{ print $1 }')
if [ ! -e $partition ]
then
echo "No swap detected. Giving up."
exit 1
fi
partitions+="$partition raw no_label swap;yes;no_mountpoint;target;no_opts;no_label;no_params"
fi
echo -n ${partitions}
}
This worked fine on my machine with only one hard drive, but it failed (obviously) when running in my VM running on a LiveCD (the LiveCD was being picked up as another drive, /dev/sr0).
I've thought of a couple of hacks I could try:
mount $partition; grep $partition /etc/mtab | awk ...
- use
parted -mls
, but pull out the partition I care about with clever scripting, then parse as I already do in the scriptt
Is there a better, simpler way of doing this? I already have the partitions I'm interested in, and I only need to find their filesystems (as well as find available swap).