]> git.ipfire.org Git - thirdparty/util-linux.git/blob - tests/ts/fdisk/gpt
62dce6d6fb1c4dbf080708c7b32c8bba6819ffcf
[thirdparty/util-linux.git] / tests / ts / fdisk / gpt
1 #!/bin/bash
2 #
3 # This file is part of util-linux.
4 #
5 # Copyright (C) 2013 Karel Zak <kzak@redhat.com>
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>&1
40 echo -ne "-------------------\n\n" >> $TS_OUTPUT
41 }
42
43 ts_log "Initialize empty image"
44 TEST_IMAGE_NAME=$(ts_image_init 10)
45
46 ts_log "Create new GPT partition table"
47 echo -e "${FDISK_CMD_CREATE_GPTLABEL}${FDISK_CMD_WRITE_CLOSE}" \
48 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
49
50 print_layout
51
52 ts_log "Create partitions"
53 for i in {1..8}; do
54 echo -e "n\n${i}\n\n+1M\n${FDISK_CMD_WRITE_CLOSE}" | \
55 $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
56 done
57
58 ts_log "Change partition type by number"
59 echo -e "${FDISK_CMD_CHANGE_TYPE_BY_NUM}${FDISK_CMD_WRITE_CLOSE}" \
60 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
61
62 print_layout
63
64 ts_log "Change partition type by UUID"
65 echo -e "${FDISK_CMD_CHANGE_TYPE_BY_UUID}${FDISK_CMD_WRITE_CLOSE}" \
66 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
67
68 print_layout
69
70 ts_log "Delete partition"
71 echo -e "${FDISK_CMD_DELETE_PART}${FDISK_CMD_WRITE_CLOSE}" \
72 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
73
74 print_layout
75
76 ts_log "Create again partition"
77 echo -e "${FDISK_CMD_CREATE_PART}${FDISK_CMD_WRITE_CLOSE}" \
78 | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
79
80 print_layout
81
82 ts_log "Corrupt primary table"
83 dd if=/dev/zero of=${TEST_IMAGE_NAME} bs=512 count=1 seek=1 conv=notrunc &> /dev/null
84 echo -e "w\n" | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
85
86 print_layout
87
88 ts_log "Corrupt backup table"
89 dd if=/dev/zero of=${TEST_IMAGE_NAME} bs=512 count=1 \
90 seek=$(( 1024 * 1024 * 10 / 512 - 1)) conv=notrunc &> /dev/null
91 echo -e "w\n" | $TS_CMD_FDISK ${TEST_IMAGE_NAME} &> /dev/null
92
93 print_layout
94
95 ts_fdisk_clean ${TEST_IMAGE_NAME}
96 ts_finalize