Ejemplo n.º 1
0
def populate_rootfs(content_dir, root_disk, partition, rootfs_type,
                    rootfs_id, should_create_swap, swap_size,
                    mmc_device_id, partition_offset, os_release_id,
                    board_config=None):
    """Populate the rootfs and make the necessary tweaks to make it usable.

    This consists of:
      1. Create a directory on the path specified by root_disk
      2. Mount the given partition onto the created directory.
      3. Setup an atexit handler to unmount the partition mounted above.
      4. Move the contents of content_dir to that directory.
      5. If should_create_swap, then create it with the given size.
      6. Add fstab entries for the / filesystem and swap (if created).
      7. Create a /etc/flash-kernel.conf containing the target's boot device.
    """
    print "\nPopulating rootfs partition"
    print "Be patient, this may take a few minutes\n"
    # Create a directory to mount the rootfs partition.
    os.makedirs(root_disk)

    with partition_mounted(partition, root_disk):
        move_contents(content_dir, root_disk)

        mount_options = rootfs_mount_options(rootfs_type)
        fstab_additions = ["%s / %s  %s 0 1" % (
            rootfs_id, rootfs_type, mount_options)]
        if should_create_swap:
            print "\nCreating SWAP File\n"
            if has_space_left_for_swap(root_disk, swap_size):
                proc = cmd_runner.run([
                    'dd',
                    'if=/dev/zero',
                    'of=%s/SWAP.swap' % root_disk,
                    'bs=1M',
                    'count=%s' % swap_size], as_root=True)
                proc.wait()
                proc = cmd_runner.run(
                    ['mkswap', '%s/SWAP.swap' % root_disk], as_root=True)
                proc.wait()
                fstab_additions.append("/SWAP.swap  none  swap  sw  0 0")
            else:
                print ("Swap file is bigger than space left on partition; "
                       "continuing without swap.")

        append_to_fstab(root_disk, fstab_additions)

        if os_release_id == 'debian' or os_release_id == 'ubuntu' or \
                os.path.exists('%s/etc/debian_version' % root_disk):
            print "\nCreating /etc/flash-kernel.conf\n"
            create_flash_kernel_config(
                root_disk, mmc_device_id, 1 + partition_offset)

            if board_config is not None:
                print "\nUpdating /etc/network/interfaces\n"
                update_network_interfaces(root_disk, board_config)
Ejemplo n.º 2
0
def populate_partition(content_dir, root_disk, partition):
    os.makedirs(root_disk)
    with partition_mounted(partition, root_disk):
        move_contents(content_dir, root_disk)