make factory reset GRUB entry chainload into reset partition GRUB
This commit is contained in:
parent
5a301bcdd6
commit
cf91a281fa
|
@ -509,18 +509,16 @@ class InstallController(SubiquityController):
|
||||||
return new_casper_uuid
|
return new_casper_uuid
|
||||||
|
|
||||||
@with_context(description="configuring grub menu entry for factory reset")
|
@with_context(description="configuring grub menu entry for factory reset")
|
||||||
async def configure_rp_boot_grub(self, context, rp: Partition, casper_uuid: str):
|
async def configure_rp_boot_grub(self, context, rp: Partition):
|
||||||
# Add a grub menu entry to boot from the RP
|
# Add a grub menu entry to boot from the RP
|
||||||
cp = await self.app.command_runner.run(
|
cp = await self.app.command_runner.run(
|
||||||
["lsblk", "-n", "-o", "UUID,PARTUUID", rp.path], capture=True
|
["lsblk", "-n", "-o", "UUID", rp.path], capture=True
|
||||||
)
|
)
|
||||||
fs_uuid, rp_uuid = cp.stdout.decode("ascii").strip().split()
|
fs_uuid = cp.stdout.decode("ascii").strip()
|
||||||
conf = grub_reset_conf.format(
|
conf = grub_reset_conf.format(
|
||||||
HEADER=generate_timestamped_header(),
|
HEADER=generate_timestamped_header(),
|
||||||
PARTITION=rp.number,
|
PARTITION=rp.number,
|
||||||
FS_UUID=fs_uuid,
|
FS_UUID=fs_uuid,
|
||||||
CASPER_UUID=casper_uuid,
|
|
||||||
RP_UUID=rp_uuid,
|
|
||||||
)
|
)
|
||||||
with open(self.tpath("etc/grub.d/99_reset"), "w") as fp:
|
with open(self.tpath("etc/grub.d/99_reset"), "w") as fp:
|
||||||
os.chmod(fp.fileno(), 0o755)
|
os.chmod(fp.fileno(), 0o755)
|
||||||
|
@ -597,9 +595,7 @@ class InstallController(SubiquityController):
|
||||||
|
|
||||||
async def configure_rp_boot(self, context, rp: Partition, casper_uuid: str):
|
async def configure_rp_boot(self, context, rp: Partition, casper_uuid: str):
|
||||||
if self.model.target is not None and not self.opts.dry_run:
|
if self.model.target is not None and not self.opts.dry_run:
|
||||||
await self.configure_rp_boot_grub(
|
await self.configure_rp_boot_grub(context=context, rp=rp)
|
||||||
context=context, rp=rp, casper_uuid=casper_uuid
|
|
||||||
)
|
|
||||||
if self.app.opts.dry_run and not is_uefi_bootable():
|
if self.app.opts.dry_run and not is_uefi_bootable():
|
||||||
# Can't even run efibootmgr in this case.
|
# Can't even run efibootmgr in this case.
|
||||||
return
|
return
|
||||||
|
@ -906,8 +902,7 @@ set -e
|
||||||
cat << EOF
|
cat << EOF
|
||||||
menuentry "Restore Ubuntu to factory state" {{
|
menuentry "Restore Ubuntu to factory state" {{
|
||||||
search --no-floppy --hint '(hd0,{PARTITION})' --set --fs-uuid {FS_UUID}
|
search --no-floppy --hint '(hd0,{PARTITION})' --set --fs-uuid {FS_UUID}
|
||||||
linux /casper/vmlinuz uuid={CASPER_UUID} rp-partuuid={RP_UUID} nopersistent
|
chainloader /EFI/boot/bootx64.efi
|
||||||
initrd /casper/initrd
|
|
||||||
}}
|
}}
|
||||||
EOF
|
EOF
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -364,14 +364,10 @@ class TestInstallController(unittest.IsolatedAsyncioTestCase):
|
||||||
async def test_configure_rp_boot_grub(self):
|
async def test_configure_rp_boot_grub(self):
|
||||||
fsuuid, partuuid = "fsuuid", "partuuid"
|
fsuuid, partuuid = "fsuuid", "partuuid"
|
||||||
self.setup_rp_test(f"{fsuuid}\t{partuuid}".encode("ascii"))
|
self.setup_rp_test(f"{fsuuid}\t{partuuid}".encode("ascii"))
|
||||||
await self.controller.configure_rp_boot_grub(
|
await self.controller.configure_rp_boot_grub(rp=self.part)
|
||||||
rp=self.part, casper_uuid="casper-uuid"
|
|
||||||
)
|
|
||||||
with open(self.controller.tpath("etc/grub.d/99_reset")) as fp:
|
with open(self.controller.tpath("etc/grub.d/99_reset")) as fp:
|
||||||
cfg = fp.read()
|
cfg = fp.read()
|
||||||
self.assertIn("--fs-uuid fsuuid", cfg)
|
self.assertIn("--fs-uuid fsuuid", cfg)
|
||||||
self.assertIn("rp-partuuid=partuuid", cfg)
|
|
||||||
self.assertIn("uuid=casper-uuid", cfg)
|
|
||||||
|
|
||||||
@patch("platform.machine", return_value="s390x")
|
@patch("platform.machine", return_value="s390x")
|
||||||
@patch("subiquity.server.controllers.install.arun_command")
|
@patch("subiquity.server.controllers.install.arun_command")
|
||||||
|
|
Loading…
Reference in New Issue