Debian Codegraph @

tests/ts/fdisk/gpt-resize

raw
1 #!/bin/bash
2
3 #
4 # This file is part of util-linux.
5 #
6 # This file is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This file is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16
17 #
18 # Test GPT Alternative-LBA and backup header update after device resize.
19 #
20
21 TS_TOPDIR="${0%/*}/../.."
22 TS_DESC="gpt-resize"
23
24 . "$TS_TOPDIR"/functions.sh
25 ts_init "$*"
26
27 ts_skip_nonroot
28
29 ts_check_test_command "$TS_CMD_FDISK"
30 ts_check_test_command "$TS_CMD_SFDISK"
31 ts_check_prog "dd"
32
33 ts_check_losetup
34
35 ts_device_init 10
36 DEVICE=$TS_LODEV
37
38 # create GPT with one partition
39 echo ",," | $TS_CMD_SFDISK --no-reread --no-tell-kernel --label gpt $DEVICE >> $TS_OUTPUT 2>> $TS_ERRLOG
40 udevadm settle
41
42 # enlarge the image
43 IMAGE=$($TS_CMD_LOSETUP --output BACK-FILE --noheadings $DEVICE)
44 dd if=/dev/zero of=${IMAGE} bs=1MiB count=10 conv=notrunc oflag=append &> /dev/null
45 udevadm settle
46
47 # update device size
48 $TS_CMD_LOSETUP --set-capacity $DEVICE
49 udevadm settle
50
51 ts_log_both "----- fixing after resize: -----"
52
53 # create another GPT partition on new free space (all default)
54 echo -e 'n\n\n\n\nw\n' | $TS_CMD_FDISK $DEVICE >> $TS_OUTPUT 2>> $TS_ERRLOG
55 udevadm settle
56
57
58 ts_log "----- list result: -----"
59
60 $TS_CMD_FDISK --list $DEVICE >> $TS_OUTPUT 2>> $TS_ERRLOG
61
62 ts_fdisk_clean $DEVICE
63 ts_finalize