def CreateArchImage(args, aur_packages):
  logging.info('Creating Arch Image')
  logging.info('========================')
  image_path = os.path.join(os.getcwd(), IMAGE_FILE)
  CreateBlankImage(image_path, size_gb=int(args.size_gb), fs_type=args.fs_type)
  mount_path = utils.CreateTempDirectory(base_dir='/')
  image_mapping = utils.ImageMapper(image_path, mount_path)
  try:
    image_mapping.InstallLoopback()
    image_mapping.Map()
    primary_mapping = image_mapping.GetFirstMapping()
    image_mapping_path = primary_mapping['path']
    FormatImage(image_mapping_path)
    try:
      image_mapping.Mount()
      utils.CreateDirectory('/run/shm')
      utils.CreateDirectory(os.path.join(mount_path, 'run', 'shm'))
      InstallArchLinux(mount_path)
      disk_uuid = SetupFileSystem(mount_path, image_mapping_path, args.fs_type)
      ConfigureArchInstall(
          args, mount_path, primary_mapping['parent'], disk_uuid, aur_packages)
      utils.DeleteDirectory(os.path.join(mount_path, 'run', 'shm'))
      PurgeDisk(mount_path)
    finally:
      image_mapping.Unmount()
    ShrinkDisk(image_mapping_path)
  finally:
    image_mapping.Unmap()
  utils.Run(['parted', image_path, 'set', '1', 'boot', 'on'])
  utils.Sync()
  logging.info('========================')
  return image_path
Example #2
0
def main():
    args = utils.DecodeArgs(sys.argv[1])
    utils.SetupLogging(quiet=args['quiet'], verbose=args['verbose'])
    logging.info('Setup Bootstrapper Environment')
    utils.SetupArchLocale()
    InstallPackagesForStagingEnvironment()
    image_path = os.path.join(os.getcwd(), IMAGE_FILE)
    CreateImage(image_path, size_gb=int(args['size_gb']))
    mount_path = utils.CreateTempDirectory(base_dir='/')
    image_mapping = utils.ImageMapper(image_path, mount_path)
    try:
        image_mapping.Map()
        primary_mapping = image_mapping.GetFirstMapping()
        image_mapping_path = primary_mapping['path']
        FormatImage(image_mapping_path)
        try:
            image_mapping.Mount()
            utils.CreateDirectory('/run/shm')
            utils.CreateDirectory(os.path.join(mount_path, 'run', 'shm'))
            InstallArchLinux(mount_path)
            disk_uuid = SetupFileSystem(mount_path, image_mapping_path)
            ConfigureArchInstall(args, mount_path, primary_mapping['parent'],
                                 disk_uuid)
            utils.DeleteDirectory(os.path.join(mount_path, 'run', 'shm'))
            PurgeDisk(mount_path)
        finally:
            image_mapping.Unmount()
        ShrinkDisk(image_mapping_path)
    finally:
        image_mapping.Unmap()
    utils.Run(['parted', image_path, 'set', '1', 'boot', 'on'])
    utils.Sync()
def FormatImage(image_mapping_path):
  utils.LogStep('Format Image')
  utils.Run(['mkfs', image_mapping_path])
  utils.Sync()