]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/partition/test-repart.sh
test-repart: also print json output
[thirdparty/systemd.git] / src / partition / test-repart.sh
1 #!/usr/bin/env bash
2 set -ex
3
4 repart=$1
5 test -x $repart
6
7 D=$(mktemp --directory)
8 trap "rm -rf '$D'" EXIT INT QUIT PIPE
9 mkdir -p $D/definitions
10
11 SEED=e2a40bf9-73f1-4278-9160-49c031e7aef8
12
13 echo "### Testing systemd-repart --empty=create ###"
14
15 $repart $D/zzz --empty=create --size=1G --seed=$SEED
16
17 sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/empty
18
19 cmp $D/empty - <<EOF
20 label: gpt
21 label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
22 device: $D/zzz
23 unit: sectors
24 first-lba: 2048
25 last-lba: 2097118
26 EOF
27
28 echo "### Testing with root, root2, home, & swap ###"
29
30 cat >$D/definitions/root.conf <<EOF
31 [Partition]
32 Type=root-x86-64
33 EOF
34
35 ln -s root.conf $D/definitions/root2.conf
36
37 cat >$D/definitions/home.conf <<EOF
38 [Partition]
39 Type=home
40 Label=home-first
41 Label=home-always-too-long-xxxxxxxxxxxxxx-%v
42 EOF
43
44 cat >$D/definitions/swap.conf <<EOF
45 [Partition]
46 Type=swap
47 SizeMaxBytes=64M
48 PaddingMinBytes=92M
49 EOF
50
51 $repart $D/zzz --dry-run=no --seed=$SEED --definitions=$D/definitions
52
53 sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated
54
55 cmp $D/populated - <<EOF
56 label: gpt
57 label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
58 device: $D/zzz
59 unit: sectors
60 first-lba: 2048
61 last-lba: 2097118
62 $D/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=A6005774-F558-4330-A8E5-D6D2C01C01D6, name="home-first"
63 $D/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64"
64 $D/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2"
65 $D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap"
66 EOF
67
68 echo "### Testing with root, root2, home, swap, & another partition ###"
69
70 cat >$D/definitions/swap.conf <<EOF
71 [Partition]
72 Type=swap
73 SizeMaxBytes=64M
74 EOF
75
76 cat >$D/definitions/extra.conf <<EOF
77 [Partition]
78 Type=linux-generic
79 Label=custom_label
80 UUID=a0a1a2a3a4a5a6a7a8a9aaabacadaeaf
81 EOF
82
83 echo "Label=ignored_label" >>$D/definitions/home.conf
84 echo "UUID=b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" >>$D/definitions/home.conf
85
86 $repart $D/zzz --dry-run=no --seed=$SEED --definitions=$D/definitions
87
88 sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated2
89
90 cmp $D/populated2 - <<EOF
91 label: gpt
92 label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
93 device: $D/zzz
94 unit: sectors
95 first-lba: 2048
96 last-lba: 2097118
97 $D/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=A6005774-F558-4330-A8E5-D6D2C01C01D6, name="home-first"
98 $D/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64"
99 $D/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2"
100 $D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap"
101 $D/zzz5 : start= 1908696, size= 188416, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name="custom_label"
102 EOF
103
104 echo "### Resizing to 2G ###"
105
106 $repart $D/zzz --size=2G --dry-run=no --seed=$SEED --definitions=$D/definitions
107
108 sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated3
109
110 cmp $D/populated3 - <<EOF
111 label: gpt
112 label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
113 device: $D/zzz
114 unit: sectors
115 first-lba: 2048
116 last-lba: 4194270
117 $D/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=A6005774-F558-4330-A8E5-D6D2C01C01D6, name="home-first"
118 $D/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64"
119 $D/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2"
120 $D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap"
121 $D/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name="custom_label"
122 EOF
123
124 dd if=/dev/urandom of=$D/block-copy bs=4096 count=10240
125
126 echo "### Testing with root, root2, home, swap, another partition, & partition copy ###"
127
128 cat >$D/definitions/extra2.conf <<EOF
129 [Partition]
130 Type=linux-generic
131 Label=block-copy
132 UUID=2a1d97e1d0a346cca26eadc643926617
133 CopyBlocks=$D/block-copy
134 EOF
135
136 $repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions
137
138 sfdisk -d $D/zzz | grep -v -e 'sector-size' -e '^$' >$D/populated4
139
140 cmp $D/populated4 - <<EOF
141 label: gpt
142 label-id: EF7F7EE2-47B3-4251-B1A1-09EA8BF12D5D
143 device: $D/zzz
144 unit: sectors
145 first-lba: 2048
146 last-lba: 6291422
147 $D/zzz1 : start= 2048, size= 591856, type=933AC7E1-2EB4-4F13-B844-0E14E2AEF915, uuid=A6005774-F558-4330-A8E5-D6D2C01C01D6, name="home-first"
148 $D/zzz2 : start= 593904, size= 591856, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=CE9C76EB-A8F1-40FF-813C-11DCA6C0A55B, name="root-x86-64"
149 $D/zzz3 : start= 1185760, size= 591864, type=4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709, uuid=AC60A837-550C-43BD-B5C4-9CB73B884E79, name="root-x86-64-2"
150 $D/zzz4 : start= 1777624, size= 131072, type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F, uuid=2AA78CDB-59C7-4173-AF11-C7453737A5D1, name="swap"
151 $D/zzz5 : start= 1908696, size= 2285568, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A0A1A2A3-A4A5-A6A7-A8A9-AAABACADAEAF, name="custom_label"
152 $D/zzz6 : start= 4194264, size= 2097152, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=2A1D97E1-D0A3-46CC-A26E-ADC643926617, name="block-copy"
153 EOF
154
155 cmp --bytes=41943040 --ignore-initial=0:$((512*4194264)) $D/block-copy $D/zzz
156
157 echo "### Testing json output ###"
158 $repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions --json=help
159 $repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions --json=pretty
160 $repart $D/zzz --size=3G --dry-run=no --seed=$SEED --definitions=$D/definitions --json=short