Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
50 lines (47 sloc) 1.82 KB
# -*- shell-script -*-
mountroot() {
if [ "$root" = "/dev/nbd0" ]; then
attach_nbd_device 0
if [ "$(get_any SKIP_OPTIONAL_NBD_DEVICES)" != "1" ]; then
attach_secondary_nbd_devices
fi
show_nbd_devices
fi
devinfo=$(partx -gro "SCHEME,NR,NAME,TYPE,UUID" $root 2>/dev/null)
if [ -n "$devinfo" ]; then
# disk has part table
einfo "Found partitions on $root"
# This is used (heuristically) to flag it as being "new"
is_new_type_image=0
# Decide which partition is root
partition_table_type=$(echo "$devinfo" | head -1 | cut -d' ' -f1)
partition_type=""
case $partition_table_type in
"gpt")
partition_type="0fc63daf-8483-4772-8e79-3d69d8477de4"
;;
"dos")
partition_type="0x83"
;;
*)
die "Unhandled partition table type $partition_table_type"
;;
esac
devinfo=$(echo "$devinfo" | cut -d' ' -f2- | sort)
# Try finding a partition named "root"
root_partition_uuid=$(echo "$devinfo" | cut -d' ' -f2- | grep -x "root .*" | head -1 | cut -d' ' -f3)
# If that doesn't work, use the first Linux filesystem partition
if [ -z "$root_partition_uuid" ]; then
root_partition_uuid=$(echo "$devinfo" | cut -d' ' -f3- | grep -x "$partition_type .*" | head -1 | cut -d' ' -f2)
fi
# If that didn't work either, give up
[ -z "$root_partition_uuid" ] && die "No root partition found"
bootdev=$(blkid -t PARTUUID="$root_partition_uuid" | cut -d':' -f1)
else
# disk has no part table
bootdev=$root
fi
log_begin_msg "Mounting ${bootdev} as root filesystem"
emount "${bootdev}" "${rootmnt}"
log_end_msg
}