diff options
Diffstat (limited to '')
-rwxr-xr-x | tests/ts/fdisk/gpt | 96 | ||||
-rwxr-xr-x | tests/ts/fdisk/gpt-resize | 63 |
2 files changed, 159 insertions, 0 deletions
diff --git a/tests/ts/fdisk/gpt b/tests/ts/fdisk/gpt new file mode 100755 index 0000000..83fe342 --- /dev/null +++ b/tests/ts/fdisk/gpt @@ -0,0 +1,96 @@ +#!/bin/bash +# +# This file is part of util-linux. +# +# Copyright (C) 2013 Karel Zak <kzak@redhat.com> +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# + +TS_TOPDIR="${0%/*}/../.." +TS_DESC="GPT" + +. $TS_TOPDIR/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_FDISK" + +FDISK_CMD_CREATE_GPTLABEL="g\n" # create GPT label +FDISK_CMD_WRITE_CLOSE="w\nq\n" # write to image + +FDISK_CMD_CHANGE_TYPE_BY_NUM="t\n1\n1\n" # set 1st partition to EFI System + # set 5th partition to Linux swap +FDISK_CMD_CHANGE_TYPE_BY_UUID="t\n5\n0657FD6D-A4AB-43C4-84E5-0933C84B4F4F\n" + +FDISK_CMD_DELETE_PART="d\n2\n" # delete 2nd partition +FDISK_CMD_CREATE_PART="n\n2\n\n\n" # create 2nd partition + +function print_layout { + echo -ne "\n---layout----------\n" >> $TS_OUTPUT + $TS_CMD_FDISK -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>> $TS_ERRLOG + echo -ne "-------------------\n\n" >> $TS_OUTPUT +} + +ts_log "Initialize empty image" +TEST_IMAGE_NAME=$(ts_image_init 10) + +ts_log "Create new GPT partition table" +echo -e "${FDISK_CMD_CREATE_GPTLABEL}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK --noauto-pt ${TEST_IMAGE_NAME} &> /dev/null + +print_layout + +ts_log "Create partitions" +for i in {1..8}; do + echo -e "n\n${i}\n\n+1M\n${FDISK_CMD_WRITE_CLOSE}" | \ + $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null +done + +ts_log "Change partition type by number" +echo -e "${FDISK_CMD_CHANGE_TYPE_BY_NUM}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null + +print_layout + +ts_log "Change partition type by UUID" +echo -e "${FDISK_CMD_CHANGE_TYPE_BY_UUID}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null + +print_layout + +ts_log "Delete partition" +echo -e "${FDISK_CMD_DELETE_PART}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null + +print_layout + +ts_log "Create again partition" +echo -e "${FDISK_CMD_CREATE_PART}${FDISK_CMD_WRITE_CLOSE}" \ + | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null + +print_layout + +ts_log "Corrupt primary table" +dd if=/dev/zero of=${TEST_IMAGE_NAME} bs=512 count=1 seek=1 conv=notrunc &> /dev/null +echo -e "w\n" | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null + +print_layout + +ts_log "Corrupt backup table" +dd if=/dev/zero of=${TEST_IMAGE_NAME} bs=512 count=1 \ + seek=$(( 1024 * 1024 * 10 / 512 - 1)) conv=notrunc &> /dev/null +echo -e "w\n" | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null + +print_layout + +ts_fdisk_clean ${TEST_IMAGE_NAME} +ts_finalize diff --git a/tests/ts/fdisk/gpt-resize b/tests/ts/fdisk/gpt-resize new file mode 100755 index 0000000..a5d248a --- /dev/null +++ b/tests/ts/fdisk/gpt-resize @@ -0,0 +1,63 @@ +#!/bin/bash + +# +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +# +# Test GPT Alternative-LBA and backup header update after device resize. +# + +TS_TOPDIR="${0%/*}/../.." +TS_DESC="gpt-resize" + +. $TS_TOPDIR/functions.sh +ts_init "$*" + +ts_skip_nonroot + +ts_check_test_command "$TS_CMD_FDISK" +ts_check_test_command "$TS_CMD_SFDISK" +ts_check_prog "dd" + +ts_check_losetup + +ts_device_init 10 +DEVICE=$TS_LODEV + +# create GPT with one partition +echo ",," | $TS_CMD_SFDISK --no-reread --no-tell-kernel --label gpt $DEVICE >> $TS_OUTPUT 2>> $TS_ERRLOG +udevadm settle + +# enlarge the image +IMAGE=$($TS_CMD_LOSETUP --output BACK-FILE --noheadings $DEVICE) +dd if=/dev/zero of=${IMAGE} bs=1MiB count=10 conv=notrunc oflag=append &> /dev/null +udevadm settle + +# update device size +$TS_CMD_LOSETUP --set-capacity $DEVICE +udevadm settle + +ts_log_both "----- fixing after resize: -----" + +# create another GPT partition on new free space (all default) +echo -e 'n\n\n\n\nw\n' | $TS_CMD_FDISK $DEVICE >> $TS_OUTPUT 2>> $TS_ERRLOG +udevadm settle + + +ts_log "----- list result: -----" + +$TS_CMD_FDISK --list $DEVICE >> $TS_OUTPUT 2>> $TS_ERRLOG + +ts_fdisk_clean $DEVICE +ts_finalize |