63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
import sys
|
|
import os
|
|
import subprocess
|
|
import SystemLib
|
|
import FileSystemLib
|
|
import DiskLib
|
|
import Boot
|
|
|
|
#!/usr/bin/env python3
|
|
# Script de ejemplo para arrancar un sistema operativo instalado.
|
|
# Nota: se usa como base para el programa de arranque de OpenGnsys Admin.
|
|
|
|
def main():
|
|
prog = os.path.basename(__file__)
|
|
if len(sys.argv) < 3 or len(sys.argv) > 6:
|
|
SystemLib.ogRaiseError(1, f"Formato: {prog} ndisco nfilesys [str_kernel str_initrd str_kernelparams]")
|
|
|
|
disk = sys.argv[1]
|
|
filesystem = sys.argv[2]
|
|
|
|
try:
|
|
part = DiskLib.ogDiskToDev(disk, filesystem)
|
|
except Exception as e:
|
|
sys.exit(1)
|
|
|
|
try:
|
|
mntdir = FileSystemLib.ogMount(disk, filesystem)
|
|
except Exception as e:
|
|
sys.exit(1)
|
|
|
|
print("[0] Inicio del proceso de arranque.")
|
|
|
|
mount_output = subprocess.getoutput(f"mount | grep -q '{mntdir}.*(rw'")
|
|
if mount_output:
|
|
SystemLib.ogEcho("log", "session", "MSG_WARNING: MSG_MOUNTREADONLY")
|
|
FileSystemLib.ogUnmount(disk, filesystem)
|
|
FileSystemLib.ogCheckFs(disk, filesystem)
|
|
|
|
part = DiskLib.ogDiskToDev(disk, filesystem)
|
|
os.makedirs(mntdir, exist_ok=True)
|
|
subprocess.run(["ntfs-3g", "-o", "remove_hiberfile", part, mntdir])
|
|
SystemLib.ogEcho("log", "session", "Particion desbloqueada")
|
|
|
|
FileSystemLib.ogUnmount(disk, filesystem)
|
|
FileSystemLib.ogMount(disk, filesystem)
|
|
|
|
if subprocess.call("which bootOsCustom", shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0:
|
|
print("[10] Configuración personalizada del inicio.")
|
|
subprocess.run(["bootOsCustom"] + sys.argv[1:])
|
|
|
|
print("[70] Desmontar todos los sistemas de archivos.")
|
|
subprocess.run(["sync"])
|
|
for i in range(1, len(DiskLib.ogDiskToDev(disk, filesystem).split())):
|
|
FileSystemLib.ogUnmountAll(i)
|
|
|
|
print("[80] Desmontar cache local.")
|
|
FileSystemLib.ogUnmount_cache()
|
|
print("[90] Arrancar sistema operativo.")
|
|
BootLib.ogBoot(sys.argv[1:])
|
|
|
|
if __name__ == "__main__":
|
|
main()
|