| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# This file is part of util-linux. |
| 4 |
# |
| 5 |
# Copyright (C) 2013 Karel Zak <[email protected]> |
| 6 |
# |
| 7 |
# This file is free software; you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 2 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# This file is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# |
| 18 |
|
| 19 |
TS_TOPDIR="${0%/*}/../.." |
| 20 |
TS_DESC="GPT" |
| 21 |
|
| 22 |
. "$TS_TOPDIR"/functions.sh |
| 23 |
ts_init "$*" |
| 24 |
|
| 25 |
ts_check_test_command "$TS_CMD_FDISK" |
| 26 |
|
| 27 |
FDISK_CMD_CREATE_GPTLABEL="g\n" # create GPT label |
| 28 |
FDISK_CMD_WRITE_CLOSE="w\nq\n" # write to image |
| 29 |
|
| 30 |
FDISK_CMD_CHANGE_TYPE_BY_NUM="t\n1\n1\n" # set 1st partition to EFI System |
| 31 |
# set 5th partition to Linux swap |
| 32 |
FDISK_CMD_CHANGE_TYPE_BY_UUID="t\n5\n0657FD6D-A4AB-43C4-84E5-0933C84B4F4F\n" |
| 33 |
|
| 34 |
FDISK_CMD_DELETE_PART="d\n2\n" # delete 2nd partition |
| 35 |
FDISK_CMD_CREATE_PART="n\n2\n\n\n" # create 2nd partition |
| 36 |
|
| 37 |
function print_layout { |
| 38 |
echo -ne "\n---layout----------\n" >> $TS_OUTPUT |
| 39 |
$TS_CMD_FDISK -l ${TEST_IMAGE_NAME} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 40 |
echo -ne "-------------------\n\n" >> $TS_OUTPUT |
| 41 |
|
| 42 |
ts_fdisk_clean ${TEST_IMAGE_NAME} |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
ts_init_subtest "empty-pt" |
| 47 |
ts_log "Initialize empty image" |
| 48 |
TEST_IMAGE_NAME=$(ts_image_init 10) |
| 49 |
|
| 50 |
ts_log "Create new GPT partition table" |
| 51 |
echo -e "${FDISK_CMD_CREATE_GPTLABEL}${FDISK_CMD_WRITE_CLOSE}" \ |
| 52 |
| $TS_CMD_FDISK --noauto-pt ${TEST_IMAGE_NAME} &> /dev/null |
| 53 |
|
| 54 |
print_layout |
| 55 |
ts_finalize_subtest |
| 56 |
|
| 57 |
ts_init_subtest "create-partitions" |
| 58 |
for i in {1..8}; do |
| 59 |
echo -e "n\n${i}\n\n+1M\n${FDISK_CMD_WRITE_CLOSE}" | \ |
| 60 |
$TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null |
| 61 |
done |
| 62 |
ts_finalize_subtest |
| 63 |
|
| 64 |
ts_init_subtest "change-type-by-number" |
| 65 |
echo -e "${FDISK_CMD_CHANGE_TYPE_BY_NUM}${FDISK_CMD_WRITE_CLOSE}" \ |
| 66 |
| $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null |
| 67 |
|
| 68 |
print_layout |
| 69 |
ts_finalize_subtest |
| 70 |
|
| 71 |
ts_init_subtest "change-type-by-uuid" |
| 72 |
echo -e "${FDISK_CMD_CHANGE_TYPE_BY_UUID}${FDISK_CMD_WRITE_CLOSE}" \ |
| 73 |
| $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null |
| 74 |
|
| 75 |
print_layout |
| 76 |
ts_finalize_subtest |
| 77 |
|
| 78 |
ts_init_subtest "delete-partition" |
| 79 |
echo -e "${FDISK_CMD_DELETE_PART}${FDISK_CMD_WRITE_CLOSE}" \ |
| 80 |
| $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null |
| 81 |
|
| 82 |
print_layout |
| 83 |
ts_finalize_subtest |
| 84 |
|
| 85 |
ts_init_subtest "create-again-partition" |
| 86 |
echo -e "${FDISK_CMD_CREATE_PART}${FDISK_CMD_WRITE_CLOSE}" \ |
| 87 |
| $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null |
| 88 |
|
| 89 |
print_layout |
| 90 |
ts_finalize_subtest |
| 91 |
|
| 92 |
ts_init_subtest "corrupt-primary-table" |
| 93 |
dd if=/dev/zero of=${TEST_IMAGE_NAME} bs=512 count=1 seek=1 conv=notrunc &> /dev/null |
| 94 |
echo -e "w\n" | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null |
| 95 |
|
| 96 |
print_layout |
| 97 |
ts_finalize_subtest |
| 98 |
|
| 99 |
ts_init_subtest "corrupt-backup-table" |
| 100 |
dd if=/dev/zero of=${TEST_IMAGE_NAME} bs=512 count=1 \ |
| 101 |
seek=$(( 1024 * 1024 * 10 / 512 - 1)) conv=notrunc &> /dev/null |
| 102 |
echo -e "w\n" | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null |
| 103 |
|
| 104 |
print_layout |
| 105 |
ts_finalize_subtest |
| 106 |
|
| 107 |
ts_finalize |