# parted part 2 -- EDIT an existing table (flags, names, deletion, free-space # accounting), and prove a second on-disk format works through the same code. # See 97-parted.test for why this is split and why the fixtures are small. . "$BST_LIB" require parted parted/edit-present T=${TMPDIR:-/tmp}/bst-partede.$$ mkdir -p "$T" || exit 0 trap 'rm -rf "$T"' EXIT IMG=$T/disk.img IMG2=$T/msdos.img snap() { parted -m -s "$1" print 2>/dev/null | sed 's/;$//'; } disk() { printf '%s\n' "$1" | awk -F: 'NR==2{print $'"$2"'}'; } part() { printf '%s\n' "$1" | awk -F: '/^'"$2"':/{print $'"$3"'}'; } dd if=/dev/zero of="$IMG" bs=1M count=8 2>/dev/null parted -s "$IMG" mklabel gpt >/dev/null 2>&1 parted -s "$IMG" mkpart primary ext4 1MiB 3MiB >/dev/null 2>&1 parted -s "$IMG" mkpart data fat32 3MiB 5MiB >/dev/null 2>&1 check parted/set-boot parted -s "$IMG" set 1 boot on check parted/name-p1 parted -s "$IMG" name 1 BSTNAME check parted/rm-p2 parted -s "$IMG" rm 2 S=$(snap "$IMG") # on GPT `boot` is the ESP type GUID, so parted reports both names for it check_eq parted/p1-flags-rb "boot, esp" "$(part "$S" 1 7)" check_eq parted/p1-name-rb "BSTNAME" "$(part "$S" 1 6)" check_eq parted/rm-count-rb "1" "$(printf '%s\n' "$S" | grep -c '^[0-9]*:')" # free-space accounting is computed, not stored: with partition 2 removed the # tail of the disk must be reported free again. check_out parted/print-free "Free Space" parted -s "$IMG" print free rm -f "$IMG" # A second on-disk format through the same code path -- msdos, not GPT -- so a # pass above cannot have come from one hardcoded label parser. dd if=/dev/zero of="$IMG2" bs=1M count=4 2>/dev/null check parted/mklabel-msdos parted -s "$IMG2" mklabel msdos check parted/msdos-mkpart parted -s "$IMG2" mkpart primary 1MiB 3MiB S2=$(snap "$IMG2") check_eq parted/msdos-label "msdos" "$(disk "$S2" 6)" check_eq parted/msdos-p1-end "3146kB" "$(part "$S2" 1 3)" # partprobe ships from this same recipe (via update-alternatives, which is why # /usr/sbin/partprobe is a symlink to partprobe.parted). On a file it cannot ask # the kernel to reread anything, but -s still parses and summarises the table -- # which is the half that exercises libparted. if command -v partprobe >/dev/null 2>&1; then check_out parted/partprobe-summary "msdos partitions 1" partprobe -s "$IMG2" else bst_skip parted/partprobe-summary "partprobe not installed on this image" fi