Merge ~raharper/curtin:fix/partition-verify-flags-msdos-primary-types into curtin:master

Proposed by Ryan Harper
Status: Merged
Approved by: Ryan Harper
Approved revision: 669b5cf73d4cf15e1bccfb9913f15125fbb4b9c1
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~raharper/curtin:fix/partition-verify-flags-msdos-primary-types
Merge into: curtin:master
Diff against target: 771 lines (+699/-10)
5 files modified
curtin/commands/block_meta.py (+3/-1)
curtin/storage_config.py (+14/-9)
tests/data/probert_storage_msdos_mbr_extended_v2.json (+537/-0)
tests/unittests/test_commands_block_meta.py (+111/-0)
tests/unittests/test_storage_config.py (+34/-0)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Lucas Albuquerque Medeiros de Moura (community) Approve
Server Team CI bot continuous-integration Approve
Ryan Harper (community) Needs Fixing
Review via email: mp+384133@code.launchpad.net

Commit message

verify_ptable_flag: dos primary partitions use ptable_uuid map for flag

Curtin currently special-cases verifying MSDOS 'boot', 'extended'
and 'logical' flags. This ignored primary DOS partitions. When
verifying partition flags on a MSDOS primary partition use
ptable_uuid_to_flag_entry map as we do for GPT partitions.

LP: #1878890

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Lucas Albuquerque Medeiros de Moura (lamoura) wrote :

I don't know if this is a possible scenario, but is it possible to have a boot type partition that is not marked as bootable ?

For example, suppose we have this type of configuration:

sfdisk_info_dos = {
            "label": "dos",
            "id": "0xb0dbdde1",
            "device": "/dev/vdb",
            "unit": "sectors",
            "partitions": [
               {"node": "/dev/vdb1", "start": 2048, "size": 8388608,
                "type": "80"},
               {"node": "/dev/vdb2", "start": 8390656, "size": 8388608,
                "type": "83"}]
}

In that scenario the boot check would fail, because we will not have the bootable key, but the MBR_TYPE_TO_CURTIN_MAP would find the expected "boot" flag as we want.

But do we want to have a boot partition that is not marked as bootable ? I think this scenario can happen if we provide a custom sfdisk_info dict to the function, but I don't know if that can actually happen, or if it does, if it is a problem.

Revision history for this message
Ryan Harper (raharper) wrote :

Good catch, and actually I need to remove the 0x80 from the MBR table, as it's a flag, not a table type. I'll add a unittest covering this scenario.

Revision history for this message
Ryan Harper (raharper) wrote :

Marking Needs Fixing so we don't land until I fix.

review: Needs Fixing
6f37807... by Ryan Harper

Drop 0x80 boot flag from MBR_TYPE map, it's a PART_ENTRY_FLAGS value only.

3368f31... by Ryan Harper

Ensure boot flag is captured even on logical partitions

7e0fb61... by Ryan Harper

Add unittest for logical partition with boot flag

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
669b5cf... by Ryan Harper

Add unittest data file

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Lucas Albuquerque Medeiros de Moura (lamoura) wrote :

To the best of knowledge, I could not find any issue with the code

review: Approve
Revision history for this message
Chad Smith (chad.smith) wrote :

 Nice one Ryan, this looks good. one minor question/suggestion about whether we can always expect a 'type' key from block.get_partition_sfdisk_info and how we should handle it.
Otherwise +1

Revision history for this message
Chad Smith (chad.smith) :
review: Approve
Revision history for this message
Ryan Harper (raharper) wrote :

@Chad

Yes, each partition entry has a type.

Revision history for this message
Ryan Harper (raharper) :
Revision history for this message
Ryan Harper (raharper) wrote :

Kicking off a few vmtests

Revision history for this message
Ryan Harper (raharper) wrote :

vmtest says yes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/curtin/commands/block_meta.py b/curtin/commands/block_meta.py
2index f2bb8da..ff0f2e9 100644
3--- a/curtin/commands/block_meta.py
4+++ b/curtin/commands/block_meta.py
5@@ -760,7 +760,9 @@ def verify_ptable_flag(devpath, expected_flag, sfdisk_info=None):
6 elif expected_flag == 'logical':
7 (_parent, partnumber) = block.get_blockdev_for_partition(devpath)
8 found_flag = 'logical' if int(partnumber) > 4 else None
9- else:
10+
11+ # gpt and msdos primary partitions look up flag by entry['type']
12+ if found_flag is None:
13 (found_flag, _code) = ptable_uuid_to_flag_entry(entry['type'])
14 msg = (
15 'Verifying %s partition flag, expecting %s, found %s' % (
16diff --git a/curtin/storage_config.py b/curtin/storage_config.py
17index e285f98..494b142 100644
18--- a/curtin/storage_config.py
19+++ b/curtin/storage_config.py
20@@ -34,12 +34,13 @@ GPT_GUID_TO_CURTIN_MAP = {
21 MBR_TYPE_TO_CURTIN_MAP = {
22 '0XF': ('extended', 'f'),
23 '0X5': ('extended', 'f'),
24- '0X80': ('boot', '80'),
25 '0X83': ('linux', '83'),
26 '0X85': ('extended', 'f'),
27 '0XC5': ('extended', 'f'),
28 }
29
30+MBR_BOOT_FLAG = '0x80'
31+
32 PTABLE_TYPE_MAP = dict(GPT_GUID_TO_CURTIN_MAP, **MBR_TYPE_TO_CURTIN_MAP)
33
34 StorageConfig = namedtuple('StorageConfig', ('type', 'schema'))
35@@ -820,16 +821,20 @@ class BlockdevParser(ProbertParser):
36 entry['size'] *= 512
37
38 ptype = blockdev_data.get('ID_PART_ENTRY_TYPE')
39- # use PART_ENTRY_FLAGS if set, msdos
40- ptype_flag = blockdev_data.get('ID_PART_ENTRY_FLAGS')
41- if ptype_flag:
42- ptype = ptype_flag
43 flag_name, _flag_code = ptable_uuid_to_flag_entry(ptype)
44
45- # logical partitions are not tagged in data, however
46- # the partition number > 4 (ie, not primary nor extended)
47- if ptable and ptable.get('label') == 'dos' and entry['number'] > 4:
48- flag_name = 'logical'
49+ if ptable and ptable.get('label') == 'dos':
50+ # if the boot flag is set, use this as the flag, logical
51+ # flag is not required as we can determine logical via
52+ # partition number
53+ ptype_flag = blockdev_data.get('ID_PART_ENTRY_FLAGS')
54+ if ptype_flag in [MBR_BOOT_FLAG]:
55+ flag_name = 'boot'
56+ else:
57+ # logical partitions are not tagged in data, however
58+ # the partition number > 4 (ie, not primary nor extended)
59+ if entry['number'] > 4:
60+ flag_name = 'logical'
61
62 if flag_name:
63 entry['flag'] = flag_name
64diff --git a/tests/data/probert_storage_msdos_mbr_extended_v2.json b/tests/data/probert_storage_msdos_mbr_extended_v2.json
65new file mode 100644
66index 0000000..4719f44
67--- /dev/null
68+++ b/tests/data/probert_storage_msdos_mbr_extended_v2.json
69@@ -0,0 +1,537 @@
70+{
71+ "dasd": {},
72+ "raid": {},
73+ "zfs": {
74+ "zpools": {}
75+ },
76+ "bcache": {
77+ "backing": {},
78+ "caching": {}
79+ },
80+ "filesystem": {
81+ "/dev/vdb1": {
82+ "TYPE": "vfat",
83+ "USAGE": "filesystem",
84+ "UUID": "5EB4-6065",
85+ "UUID_ENC": "5EB4-6065",
86+ "VERSION": "FAT32"
87+ },
88+ "/dev/vdb5": {
89+ "TYPE": "ext4",
90+ "USAGE": "filesystem",
91+ "UUID": "a55d4dc5-dacb-48af-b589-828ee55f5208",
92+ "UUID_ENC": "a55d4dc5-dacb-48af-b589-828ee55f5208",
93+ "VERSION": "1.0"
94+ }
95+ },
96+ "dmcrypt": {},
97+ "multipath": {},
98+ "blockdev": {
99+ "/dev/vda": {
100+ "DEVLINKS": "/dev/disk/by-path/virtio-pci-0000:00:08.0 /dev/disk/by-path/pci-0000:00:08.0",
101+ "DEVNAME": "/dev/vda",
102+ "DEVPATH": "/devices/pci0000:00/0000:00:08.0/virtio2/block/vda",
103+ "DEVTYPE": "disk",
104+ "ID_PATH": "pci-0000:00:08.0",
105+ "ID_PATH_TAG": "pci-0000_00_08_0",
106+ "MAJOR": "252",
107+ "MINOR": "0",
108+ "SUBSYSTEM": "block",
109+ "TAGS": ":systemd:",
110+ "USEC_INITIALIZED": "1159634",
111+ "attrs": {
112+ "alignment_offset": "0",
113+ "bdi": null,
114+ "cache_type": "write back",
115+ "capability": "50",
116+ "dev": "252:0",
117+ "device": null,
118+ "discard_alignment": "0",
119+ "events": "",
120+ "events_async": "",
121+ "events_poll_msecs": "-1",
122+ "ext_range": "256",
123+ "hidden": "0",
124+ "inflight": " 0 0",
125+ "range": "16",
126+ "removable": "0",
127+ "ro": "0",
128+ "serial": "",
129+ "size": "21474836480",
130+ "stat": " 490 0 22696 179 0 0 0 0 0 176 64 0 0 0 0",
131+ "subsystem": "block",
132+ "uevent": "MAJOR=252\nMINOR=0\nDEVNAME=vda\nDEVTYPE=disk"
133+ }
134+ },
135+ "/dev/vdb": {
136+ "DEVLINKS": "/dev/disk/by-path/pci-0000:00:09.0 /dev/disk/by-path/virtio-pci-0000:00:09.0",
137+ "DEVNAME": "/dev/vdb",
138+ "DEVPATH": "/devices/pci0000:00/0000:00:09.0/virtio3/block/vdb",
139+ "DEVTYPE": "disk",
140+ "ID_PART_TABLE_TYPE": "dos",
141+ "ID_PART_TABLE_UUID": "c72f0a19",
142+ "ID_PATH": "pci-0000:00:09.0",
143+ "ID_PATH_TAG": "pci-0000_00_09_0",
144+ "MAJOR": "252",
145+ "MINOR": "16",
146+ "SUBSYSTEM": "block",
147+ "TAGS": ":systemd:",
148+ "USEC_INITIALIZED": "1133535",
149+ "attrs": {
150+ "alignment_offset": "0",
151+ "bdi": null,
152+ "cache_type": "write back",
153+ "capability": "50",
154+ "dev": "252:16",
155+ "device": null,
156+ "discard_alignment": "0",
157+ "events": "",
158+ "events_async": "",
159+ "events_poll_msecs": "-1",
160+ "ext_range": "256",
161+ "hidden": "0",
162+ "inflight": " 0 0",
163+ "range": "16",
164+ "removable": "0",
165+ "ro": "0",
166+ "serial": "",
167+ "size": "10737418240",
168+ "stat": " 609 0 39218 164 0 0 0 0 0 212 68 0 0 0 0",
169+ "subsystem": "block",
170+ "uevent": "MAJOR=252\nMINOR=16\nDEVNAME=vdb\nDEVTYPE=disk"
171+ },
172+ "partitiontable": {
173+ "label": "dos",
174+ "id": "0xc72f0a19",
175+ "device": "/dev/vdb",
176+ "unit": "sectors",
177+ "partitions": [
178+ {
179+ "node": "/dev/vdb1",
180+ "start": 2048,
181+ "size": 1048576,
182+ "type": "b",
183+ "bootable": true
184+ },
185+ {
186+ "node": "/dev/vdb2",
187+ "start": 1052670,
188+ "size": 19916802,
189+ "type": "5"
190+ },
191+ {
192+ "node": "/dev/vdb5",
193+ "start": 1052672,
194+ "size": 19916800,
195+ "type": "83"
196+ }
197+ ]
198+ }
199+ },
200+ "/dev/vdb1": {
201+ "DEVLINKS": "/dev/disk/by-partuuid/c72f0a19-01 /dev/disk/by-uuid/5EB4-6065 /dev/disk/by-path/virtio-pci-0000:00:09.0-part1 /dev/disk/by-path/pci-0000:00:09.0-part1",
202+ "DEVNAME": "/dev/vdb1",
203+ "DEVPATH": "/devices/pci0000:00/0000:00:09.0/virtio3/block/vdb/vdb1",
204+ "DEVTYPE": "partition",
205+ "ID_FS_TYPE": "vfat",
206+ "ID_FS_USAGE": "filesystem",
207+ "ID_FS_UUID": "5EB4-6065",
208+ "ID_FS_UUID_ENC": "5EB4-6065",
209+ "ID_FS_VERSION": "FAT32",
210+ "ID_PART_ENTRY_DISK": "252:16",
211+ "ID_PART_ENTRY_FLAGS": "0x80",
212+ "ID_PART_ENTRY_NUMBER": "1",
213+ "ID_PART_ENTRY_OFFSET": "2048",
214+ "ID_PART_ENTRY_SCHEME": "dos",
215+ "ID_PART_ENTRY_SIZE": "1048576",
216+ "ID_PART_ENTRY_TYPE": "0xb",
217+ "ID_PART_ENTRY_UUID": "c72f0a19-01",
218+ "ID_PART_TABLE_TYPE": "dos",
219+ "ID_PART_TABLE_UUID": "c72f0a19",
220+ "ID_PATH": "pci-0000:00:09.0",
221+ "ID_PATH_TAG": "pci-0000_00_09_0",
222+ "ID_SCSI": "1",
223+ "MAJOR": "252",
224+ "MINOR": "17",
225+ "PARTN": "1",
226+ "SUBSYSTEM": "block",
227+ "TAGS": ":systemd:",
228+ "USEC_INITIALIZED": "1161634",
229+ "attrs": {
230+ "alignment_offset": "0",
231+ "dev": "252:17",
232+ "discard_alignment": "0",
233+ "inflight": " 0 0",
234+ "partition": "1",
235+ "ro": "0",
236+ "size": "536870912",
237+ "start": "2048",
238+ "stat": " 200 0 14424 72 0 0 0 0 0 104 44 0 0 0 0",
239+ "subsystem": "block",
240+ "uevent": "MAJOR=252\nMINOR=17\nDEVNAME=vdb1\nDEVTYPE=partition\nPARTN=1"
241+ },
242+ "partitiontable": {
243+ "label": "dos",
244+ "id": "0x00000000",
245+ "device": "/dev/vdb1",
246+ "unit": "sectors",
247+ "partitions": []
248+ }
249+ },
250+ "/dev/vdb2": {
251+ "DEVLINKS": "/dev/disk/by-path/pci-0000:00:09.0-part2 /dev/disk/by-path/virtio-pci-0000:00:09.0-part2 /dev/disk/by-partuuid/c72f0a19-02",
252+ "DEVNAME": "/dev/vdb2",
253+ "DEVPATH": "/devices/pci0000:00/0000:00:09.0/virtio3/block/vdb/vdb2",
254+ "DEVTYPE": "partition",
255+ "ID_PART_ENTRY_DISK": "252:16",
256+ "ID_PART_ENTRY_NUMBER": "2",
257+ "ID_PART_ENTRY_OFFSET": "1052670",
258+ "ID_PART_ENTRY_SCHEME": "dos",
259+ "ID_PART_ENTRY_SIZE": "19916802",
260+ "ID_PART_ENTRY_TYPE": "0x5",
261+ "ID_PART_ENTRY_UUID": "c72f0a19-02",
262+ "ID_PART_TABLE_TYPE": "dos",
263+ "ID_PART_TABLE_UUID": "e7ad4c09",
264+ "ID_PATH": "pci-0000:00:09.0",
265+ "ID_PATH_TAG": "pci-0000_00_09_0",
266+ "ID_SCSI": "1",
267+ "MAJOR": "252",
268+ "MINOR": "18",
269+ "PARTN": "2",
270+ "SUBSYSTEM": "block",
271+ "TAGS": ":systemd:",
272+ "USEC_INITIALIZED": "1149403",
273+ "attrs": {
274+ "alignment_offset": "0",
275+ "dev": "252:18",
276+ "discard_alignment": "0",
277+ "inflight": " 0 0",
278+ "partition": "2",
279+ "ro": "0",
280+ "size": "1024",
281+ "start": "1052670",
282+ "stat": " 9 0 18 10 0 0 0 0 0 44 8 0 0 0 0",
283+ "subsystem": "block",
284+ "uevent": "MAJOR=252\nMINOR=18\nDEVNAME=vdb2\nDEVTYPE=partition\nPARTN=2"
285+ },
286+ "partitiontable": {
287+ "label": "dos",
288+ "id": "0xe7ad4c09",
289+ "device": "/dev/vdb2",
290+ "unit": "sectors",
291+ "grain": "512",
292+ "partitions": [
293+ {
294+ "node": "/dev/vdb2p1",
295+ "start": 2,
296+ "size": 19916800,
297+ "type": "83"
298+ }
299+ ]
300+ }
301+ },
302+ "/dev/vdb5": {
303+ "DEVLINKS": "/dev/disk/by-uuid/a55d4dc5-dacb-48af-b589-828ee55f5208 /dev/disk/by-path/pci-0000:00:09.0-part5 /dev/disk/by-partuuid/c72f0a19-05 /dev/disk/by-path/virtio-pci-0000:00:09.0-part5",
304+ "DEVNAME": "/dev/vdb5",
305+ "DEVPATH": "/devices/pci0000:00/0000:00:09.0/virtio3/block/vdb/vdb5",
306+ "DEVTYPE": "partition",
307+ "ID_FS_TYPE": "ext4",
308+ "ID_FS_USAGE": "filesystem",
309+ "ID_FS_UUID": "a55d4dc5-dacb-48af-b589-828ee55f5208",
310+ "ID_FS_UUID_ENC": "a55d4dc5-dacb-48af-b589-828ee55f5208",
311+ "ID_FS_VERSION": "1.0",
312+ "ID_PART_ENTRY_DISK": "252:16",
313+ "ID_PART_ENTRY_NUMBER": "5",
314+ "ID_PART_ENTRY_OFFSET": "1052672",
315+ "ID_PART_ENTRY_SCHEME": "dos",
316+ "ID_PART_ENTRY_SIZE": "19916800",
317+ "ID_PART_ENTRY_TYPE": "0x83",
318+ "ID_PART_ENTRY_UUID": "c72f0a19-05",
319+ "ID_PART_TABLE_TYPE": "dos",
320+ "ID_PART_TABLE_UUID": "c72f0a19",
321+ "ID_PATH": "pci-0000:00:09.0",
322+ "ID_PATH_TAG": "pci-0000_00_09_0",
323+ "ID_SCSI": "1",
324+ "MAJOR": "252",
325+ "MINOR": "21",
326+ "PARTN": "5",
327+ "SUBSYSTEM": "block",
328+ "TAGS": ":systemd:",
329+ "USEC_INITIALIZED": "1155916",
330+ "attrs": {
331+ "alignment_offset": "0",
332+ "dev": "252:21",
333+ "discard_alignment": "0",
334+ "inflight": " 0 0",
335+ "partition": "5",
336+ "ro": "0",
337+ "size": "10197401600",
338+ "start": "1052672",
339+ "stat": " 202 0 14888 36 0 0 0 0 0 108 8 0 0 0 0",
340+ "subsystem": "block",
341+ "uevent": "MAJOR=252\nMINOR=21\nDEVNAME=vdb5\nDEVTYPE=partition\nPARTN=5"
342+ }
343+ }
344+ },
345+ "lvm": {},
346+ "mount": [
347+ {
348+ "target": "/",
349+ "source": "/cow",
350+ "fstype": "overlay",
351+ "options": "rw,relatime,lowerdir=/installer.squashfs:/filesystem.squashfs,upperdir=/cow/upper,workdir=/cow/work",
352+ "children": [
353+ {
354+ "target": "/sys",
355+ "source": "sysfs",
356+ "fstype": "sysfs",
357+ "options": "rw,nosuid,nodev,noexec,relatime",
358+ "children": [
359+ {
360+ "target": "/sys/kernel/security",
361+ "source": "securityfs",
362+ "fstype": "securityfs",
363+ "options": "rw,nosuid,nodev,noexec,relatime"
364+ },
365+ {
366+ "target": "/sys/fs/cgroup",
367+ "source": "tmpfs",
368+ "fstype": "tmpfs",
369+ "options": "ro,nosuid,nodev,noexec,mode=755",
370+ "children": [
371+ {
372+ "target": "/sys/fs/cgroup/unified",
373+ "source": "cgroup2",
374+ "fstype": "cgroup2",
375+ "options": "rw,nosuid,nodev,noexec,relatime,nsdelegate"
376+ },
377+ {
378+ "target": "/sys/fs/cgroup/systemd",
379+ "source": "cgroup",
380+ "fstype": "cgroup",
381+ "options": "rw,nosuid,nodev,noexec,relatime,xattr,name=systemd"
382+ },
383+ {
384+ "target": "/sys/fs/cgroup/rdma",
385+ "source": "cgroup",
386+ "fstype": "cgroup",
387+ "options": "rw,nosuid,nodev,noexec,relatime,rdma"
388+ },
389+ {
390+ "target": "/sys/fs/cgroup/cpu,cpuacct",
391+ "source": "cgroup",
392+ "fstype": "cgroup",
393+ "options": "rw,nosuid,nodev,noexec,relatime,cpu,cpuacct"
394+ },
395+ {
396+ "target": "/sys/fs/cgroup/net_cls,net_prio",
397+ "source": "cgroup",
398+ "fstype": "cgroup",
399+ "options": "rw,nosuid,nodev,noexec,relatime,net_cls,net_prio"
400+ },
401+ {
402+ "target": "/sys/fs/cgroup/hugetlb",
403+ "source": "cgroup",
404+ "fstype": "cgroup",
405+ "options": "rw,nosuid,nodev,noexec,relatime,hugetlb"
406+ },
407+ {
408+ "target": "/sys/fs/cgroup/pids",
409+ "source": "cgroup",
410+ "fstype": "cgroup",
411+ "options": "rw,nosuid,nodev,noexec,relatime,pids"
412+ },
413+ {
414+ "target": "/sys/fs/cgroup/blkio",
415+ "source": "cgroup",
416+ "fstype": "cgroup",
417+ "options": "rw,nosuid,nodev,noexec,relatime,blkio"
418+ },
419+ {
420+ "target": "/sys/fs/cgroup/memory",
421+ "source": "cgroup",
422+ "fstype": "cgroup",
423+ "options": "rw,nosuid,nodev,noexec,relatime,memory"
424+ },
425+ {
426+ "target": "/sys/fs/cgroup/cpuset",
427+ "source": "cgroup",
428+ "fstype": "cgroup",
429+ "options": "rw,nosuid,nodev,noexec,relatime,cpuset"
430+ },
431+ {
432+ "target": "/sys/fs/cgroup/freezer",
433+ "source": "cgroup",
434+ "fstype": "cgroup",
435+ "options": "rw,nosuid,nodev,noexec,relatime,freezer"
436+ },
437+ {
438+ "target": "/sys/fs/cgroup/devices",
439+ "source": "cgroup",
440+ "fstype": "cgroup",
441+ "options": "rw,nosuid,nodev,noexec,relatime,devices"
442+ },
443+ {
444+ "target": "/sys/fs/cgroup/perf_event",
445+ "source": "cgroup",
446+ "fstype": "cgroup",
447+ "options": "rw,nosuid,nodev,noexec,relatime,perf_event"
448+ }
449+ ]
450+ },
451+ {
452+ "target": "/sys/fs/pstore",
453+ "source": "pstore",
454+ "fstype": "pstore",
455+ "options": "rw,nosuid,nodev,noexec,relatime"
456+ },
457+ {
458+ "target": "/sys/firmware/efi/efivars",
459+ "source": "efivarfs",
460+ "fstype": "efivarfs",
461+ "options": "rw,nosuid,nodev,noexec,relatime"
462+ },
463+ {
464+ "target": "/sys/fs/bpf",
465+ "source": "none",
466+ "fstype": "bpf",
467+ "options": "rw,nosuid,nodev,noexec,relatime,mode=700"
468+ },
469+ {
470+ "target": "/sys/kernel/debug",
471+ "source": "debugfs",
472+ "fstype": "debugfs",
473+ "options": "rw,nosuid,nodev,noexec,relatime"
474+ },
475+ {
476+ "target": "/sys/kernel/tracing",
477+ "source": "tracefs",
478+ "fstype": "tracefs",
479+ "options": "rw,nosuid,nodev,noexec,relatime"
480+ },
481+ {
482+ "target": "/sys/fs/fuse/connections",
483+ "source": "fusectl",
484+ "fstype": "fusectl",
485+ "options": "rw,nosuid,nodev,noexec,relatime"
486+ },
487+ {
488+ "target": "/sys/kernel/config",
489+ "source": "configfs",
490+ "fstype": "configfs",
491+ "options": "rw,nosuid,nodev,noexec,relatime"
492+ }
493+ ]
494+ },
495+ {
496+ "target": "/proc",
497+ "source": "proc",
498+ "fstype": "proc",
499+ "options": "rw,nosuid,nodev,noexec,relatime",
500+ "children": [
501+ {
502+ "target": "/proc/sys/fs/binfmt_misc",
503+ "source": "systemd-1",
504+ "fstype": "autofs",
505+ "options": "rw,relatime,fd=28,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=18206"
506+ }
507+ ]
508+ },
509+ {
510+ "target": "/dev",
511+ "source": "udev",
512+ "fstype": "devtmpfs",
513+ "options": "rw,nosuid,noexec,relatime,size=1969872k,nr_inodes=492468,mode=755",
514+ "children": [
515+ {
516+ "target": "/dev/pts",
517+ "source": "devpts",
518+ "fstype": "devpts",
519+ "options": "rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000"
520+ },
521+ {
522+ "target": "/dev/shm",
523+ "source": "tmpfs",
524+ "fstype": "tmpfs",
525+ "options": "rw,nosuid,nodev"
526+ },
527+ {
528+ "target": "/dev/mqueue",
529+ "source": "mqueue",
530+ "fstype": "mqueue",
531+ "options": "rw,nosuid,nodev,noexec,relatime"
532+ },
533+ {
534+ "target": "/dev/hugepages",
535+ "source": "hugetlbfs",
536+ "fstype": "hugetlbfs",
537+ "options": "rw,relatime,pagesize=2M"
538+ }
539+ ]
540+ },
541+ {
542+ "target": "/run",
543+ "source": "tmpfs",
544+ "fstype": "tmpfs",
545+ "options": "rw,nosuid,nodev,noexec,relatime,size=402820k,mode=755",
546+ "children": [
547+ {
548+ "target": "/run/lock",
549+ "source": "tmpfs",
550+ "fstype": "tmpfs",
551+ "options": "rw,nosuid,nodev,noexec,relatime,size=5120k"
552+ }
553+ ]
554+ },
555+ {
556+ "target": "/cdrom",
557+ "source": "/dev/loop0",
558+ "fstype": "iso9660",
559+ "options": "ro,relatime,nojoliet,check=s,map=n,blocksize=2048"
560+ },
561+ {
562+ "target": "/rofs",
563+ "source": "/dev/loop1",
564+ "fstype": "squashfs",
565+ "options": "ro,noatime"
566+ },
567+ {
568+ "target": "/usr/lib/modules",
569+ "source": "/dev/loop3",
570+ "fstype": "squashfs",
571+ "options": "ro,relatime"
572+ },
573+ {
574+ "target": "/media/filesystem",
575+ "source": "/dev/loop1",
576+ "fstype": "squashfs",
577+ "options": "ro,relatime"
578+ },
579+ {
580+ "target": "/tmp",
581+ "source": "tmpfs",
582+ "fstype": "tmpfs",
583+ "options": "rw,nosuid,nodev,relatime"
584+ },
585+ {
586+ "target": "/snap/core/8935",
587+ "source": "/dev/loop4",
588+ "fstype": "squashfs",
589+ "options": "ro,nodev,relatime"
590+ },
591+ {
592+ "target": "/snap/subiquity/1626",
593+ "source": "/dev/loop5",
594+ "fstype": "squashfs",
595+ "options": "ro,nodev,relatime"
596+ },
597+ {
598+ "target": "/snap/subiquity/1632",
599+ "source": "/dev/loop6",
600+ "fstype": "squashfs",
601+ "options": "ro,nodev,relatime"
602+ }
603+ ]
604+ }
605+ ]
606+}
607diff --git a/tests/unittests/test_commands_block_meta.py b/tests/unittests/test_commands_block_meta.py
608index 4cc9299..b768cdc 100644
609--- a/tests/unittests/test_commands_block_meta.py
610+++ b/tests/unittests/test_commands_block_meta.py
611@@ -2446,4 +2446,115 @@ class TestVerifySize(CiTestCase):
612 self.devpath = self.random_string()
613
614
615+class TestVerifyPtableFlag(CiTestCase):
616+
617+ def setUp(self):
618+ super(TestVerifyPtableFlag, self).setUp()
619+ base = 'curtin.commands.block_meta.'
620+ self.add_patch(base + 'block.sfdisk_info', 'm_block_sfdisk_info')
621+ self.add_patch(base + 'block.get_blockdev_for_partition',
622+ 'm_block_get_blockdev_for_partition')
623+ self.sfdisk_info_dos = {
624+ "label": "dos",
625+ "id": "0xb0dbdde1",
626+ "device": "/dev/vdb",
627+ "unit": "sectors",
628+ "partitions": [
629+ {"node": "/dev/vdb1", "start": 2048, "size": 8388608,
630+ "type": "83", "bootable": True},
631+ {"node": "/dev/vdb2", "start": 8390656, "size": 8388608,
632+ "type": "83"},
633+ {"node": "/dev/vdb3", "start": 16779264, "size": 62914560,
634+ "type": "85"},
635+ {"node": "/dev/vdb5", "start": 16781312, "size": 31457280,
636+ "type": "83"},
637+ {"node": "/dev/vdb6", "start": 48240640, "size": 10485760,
638+ "type": "83"},
639+ {"node": "/dev/vdb7", "start": 58728448, "size": 20965376,
640+ "type": "83"}]}
641+ self.sfdisk_info_gpt = {
642+ "label": "gpt",
643+ "id": "AEA37E20-8E52-4B37-BDFD-9946A352A37B",
644+ "device": "/dev/vda",
645+ "unit": "sectors",
646+ "firstlba": 34,
647+ "lastlba": 41943006,
648+ "partitions": [
649+ {"node": "/dev/vda1", "start": 227328, "size": 41715679,
650+ "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
651+ "uuid": "42C72DE9-FF5E-4CD6-A4C8-283685DEB1D5"},
652+ {"node": "/dev/vda14", "start": 2048, "size": 8192,
653+ "type": "21686148-6449-6E6F-744E-656564454649",
654+ "uuid": "762F070A-122A-4EB8-90BF-2CA6E9171B01"},
655+ {"node": "/dev/vda15", "start": 10240, "size": 217088,
656+ "type": "C12A7328-F81F-11D2-BA4B-00A0C93EC93B",
657+ "uuid": "789133C6-8579-4792-9D61-FC9A7BEC2A15"}]}
658+
659+ def test_verify_ptable_flag_finds_boot_on_gpt(self):
660+ devpath = '/dev/vda15'
661+ expected_flag = 'boot'
662+ block_meta.verify_ptable_flag(devpath, expected_flag,
663+ sfdisk_info=self.sfdisk_info_gpt)
664+
665+ def test_verify_ptable_flag_raises_exception_missing_flag(self):
666+ devpath = '/dev/vda1'
667+ expected_flag = 'boot'
668+ with self.assertRaises(RuntimeError):
669+ block_meta.verify_ptable_flag(devpath, expected_flag,
670+ sfdisk_info=self.sfdisk_info_gpt)
671+
672+ def test_verify_ptable_flag_raises_exception_invalid_flag(self):
673+ devpath = '/dev/vda1'
674+ expected_flag = self.random_string()
675+ self.assertNotIn(expected_flag, block_meta.SGDISK_FLAGS.keys())
676+ self.assertNotIn(expected_flag, block_meta.MSDOS_FLAGS.keys())
677+ with self.assertRaises(RuntimeError):
678+ block_meta.verify_ptable_flag(devpath, expected_flag,
679+ sfdisk_info=self.sfdisk_info_gpt)
680+
681+ def test_verify_ptable_flag_checks_bootable_not_table_type(self):
682+ devpath = '/dev/vdb1'
683+ expected_flag = 'boot'
684+ del self.sfdisk_info_dos['partitions'][0]['bootable']
685+ self.sfdisk_info_dos['partitions'][0]['type'] = '0x80'
686+ with self.assertRaises(RuntimeError):
687+ block_meta.verify_ptable_flag(devpath, expected_flag,
688+ sfdisk_info=self.sfdisk_info_dos)
689+
690+ def test_verify_ptable_flag_calls_block_sfdisk_if_info_none(self):
691+ devpath = '/dev/vda15'
692+ expected_flag = 'boot'
693+ self.m_block_sfdisk_info.return_value = self.sfdisk_info_gpt
694+ block_meta.verify_ptable_flag(devpath, expected_flag, sfdisk_info=None)
695+ self.assertEqual(
696+ [call(devpath)],
697+ self.m_block_sfdisk_info.call_args_list)
698+
699+ def test_verify_ptable_flag_finds_boot_on_msdos(self):
700+ devpath = '/dev/vdb1'
701+ expected_flag = 'boot'
702+ block_meta.verify_ptable_flag(devpath, expected_flag,
703+ sfdisk_info=self.sfdisk_info_dos)
704+
705+ def test_verify_ptable_flag_finds_linux_on_dos_primary_partition(self):
706+ devpath = '/dev/vdb2'
707+ expected_flag = 'linux'
708+ block_meta.verify_ptable_flag(devpath, expected_flag,
709+ sfdisk_info=self.sfdisk_info_dos)
710+
711+ def test_verify_ptable_flag_finds_dos_extended_partition(self):
712+ devpath = '/dev/vdb3'
713+ expected_flag = 'extended'
714+ block_meta.verify_ptable_flag(devpath, expected_flag,
715+ sfdisk_info=self.sfdisk_info_dos)
716+
717+ def test_verify_ptable_flag_finds_dos_logical_partition(self):
718+ devpath = '/dev/vdb5'
719+ expected_flag = 'logical'
720+ self.m_block_get_blockdev_for_partition.return_value = (
721+ ('/dev/vdb', '5'))
722+ block_meta.verify_ptable_flag(devpath, expected_flag,
723+ sfdisk_info=self.sfdisk_info_dos)
724+
725+
726 # vi: ts=4 expandtab syntax=python
727diff --git a/tests/unittests/test_storage_config.py b/tests/unittests/test_storage_config.py
728index ecdc565..a38f9cd 100644
729--- a/tests/unittests/test_storage_config.py
730+++ b/tests/unittests/test_storage_config.py
731@@ -405,6 +405,40 @@ class TestBlockdevParser(CiTestCase):
732 self.assertDictEqual(expected_dict,
733 self.bdevp.asdict(blockdev))
734
735+ def test_blockdev_detects_dos_bootable_flag(self):
736+ self.probe_data = _get_data(
737+ 'probert_storage_msdos_mbr_extended_v2.json')
738+ self.bdevp = BlockdevParser(self.probe_data)
739+ blockdev = self.bdevp.blockdev_data['/dev/vdb1']
740+ expected_dict = {
741+ 'id': 'partition-vdb1',
742+ 'type': 'partition',
743+ 'device': 'disk-vdb',
744+ 'number': 1,
745+ 'offset': 1048576,
746+ 'size': 536870912,
747+ 'flag': 'boot',
748+ }
749+ self.assertDictEqual(expected_dict,
750+ self.bdevp.asdict(blockdev))
751+
752+ def test_blockdev_detects_dos_bootable_flag_on_logical_partitions(self):
753+ self.probe_data = _get_data('probert_storage_lvm.json')
754+ self.bdevp = BlockdevParser(self.probe_data)
755+ blockdev = self.bdevp.blockdev_data['/dev/vda5']
756+ blockdev['ID_PART_ENTRY_FLAGS'] = '0x80'
757+ expected_dict = {
758+ 'id': 'partition-vda5',
759+ 'type': 'partition',
760+ 'device': 'disk-vda',
761+ 'number': 5,
762+ 'offset': 3223322624,
763+ 'size': 2147483648,
764+ 'flag': 'boot',
765+ }
766+ self.assertDictEqual(expected_dict,
767+ self.bdevp.asdict(blockdev))
768+
769 def test_blockdev_asdict_disk_omits_ptable_if_none_present(self):
770 blockdev = self.bdevp.blockdev_data['/dev/sda']
771 del blockdev['ID_PART_TABLE_TYPE']

Subscribers

People subscribed via source and target branches