]>
git.proxmox.com Git - pve-edk2-firmware.git/blob - debian/python/UEFI/Filesystems.py
2 # Copyright 2019-2022 Canonical Ltd.
4 # - dann frazier <dann.frazier@canonical.com>
6 # This program is free software: you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License version 3, as published
8 # by the Free Software Foundation.
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
12 # SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License along with
16 # this program. If not, see <http://www.gnu.org/licenses/>.
26 def __init__(self
, size_in_mb
):
27 with tempfile
.NamedTemporaryFile(delete
=False) as f
:
30 subprocess
.check_call(
32 'dd', 'if=/dev/zero', 'of=%s' % (self
.path
),
33 'count=0', 'bs=1M', 'seek=%d' % (size_in_mb
), 'status=none'
36 new_env
= os
.environ
.copy()
37 new_env
['PATH'] = f
"{os.environ['PATH']}:/sbin"
38 subprocess
.check_call(['mkdosfs', '-F', '32', self
.path
], env
=new_env
)
44 subprocess
.run(['mmd', '-i', self
.path
, dir])
46 def makedirs(self
, dir):
47 dirs
= dir.split(os
.path
.sep
)
48 for dir_idx
in range(1, len(dirs
)+1):
49 next_dir
= os
.path
.sep
.join(dirs
[:dir_idx
])
52 def insert_file(self
, src
, dest
):
53 subprocess
.check_call(
55 'mcopy', '-i', self
.path
, src
, '::%s' % (dest
)
60 class EfiBootableIsoImage
:
61 def __init__(self
, eltorito_img
):
62 with tempfile
.TemporaryDirectory() as iso_root
:
63 eltorito_iso_root
= 'boot'
64 eltorito_iso_path
= os
.path
.join(eltorito_iso_root
, 'efi.img')
65 eltorito_local_root
= os
.path
.join(iso_root
, eltorito_iso_root
)
66 eltorito_local_path
= os
.path
.join(iso_root
, eltorito_iso_path
)
68 os
.makedirs(eltorito_local_root
)
69 shutil
.copyfile(eltorito_img
.path
, eltorito_local_path
)
71 with tempfile
.NamedTemporaryFile(delete
=False) as f
:
74 subprocess
.check_call(
76 'xorriso', '-as', 'mkisofs', '-J', '-l',
77 '-c', 'boot/boot.cat',
78 '-partition_offset', '16', '-append_partition', '2',
79 '0xef', eltorito_local_path
,
80 '-e', '--interval:appended_partition_2:all::',
81 '-no-emul-boot', '-o', self
.path
, iso_root
89 class GrubShellBootableIsoImage(EfiBootableIsoImage
):
90 def __init__(self
, efi_arch
, shim_path
, grub_path
):
91 efi_img
= FatFsImage(64)
92 efi_img
.makedirs(os
.path
.join('EFI', 'BOOT'))
93 removable_media_path
= os
.path
.join(
94 'EFI', 'BOOT', 'BOOT%s.EFI' % (efi_arch
.upper())
96 grub_dest
= os
.path
.join(
97 'EFI', 'BOOT', 'GRUB%s.EFI' % (efi_arch
.upper())
99 efi_img
.insert_file(shim_path
, removable_media_path
)
100 efi_img
.insert_file(grub_path
, grub_dest
)
101 super().__init
__(efi_img
)