gensprep - Linux


Overview

gensprep prepares a block device for use with a guest operating system by formatting the device, creating a file system, and setting up basic storage layers. It primarily initializes a block device for use in a virtual machine or container environment.

Syntax

gensprep [-f] [-E] [-r] [-a] [-q] [-t TYPE] [-w] [-z] [-h] [-V] [DEVICE]

Options/Flags

  • -f: Force formatting, overriding any existing partition or file system.
  • -E: Enable encryption. Requires specifying a password during the process.
  • -r: Read-only mode. Only shows information about the device without making changes.
  • -a: Automatically detect and use the optimal partition layout and file system type.
  • -q: Quiet mode. Suppresses output, except for errors.
  • -t TYPE: Specify the file system type to use (e.g., ext4, xfs).
  • -w: Wipe the entire device before preparing it.
  • -z: Zero out the device before preparing it.
  • -h: Show help and usage information.
  • -V: Show version information.

Examples

Basic Usage

Format a USB drive (/dev/sdb) as ext4 with a GPT partition table:

gensprep /dev/sdb

Encrypt and Prepare a Virtual Hard Disk

Encrypt and prepare a virtual hard disk (/path/to/disk.vhd) as LUKS with ext4:

gensprep -E /path/to/disk.vhd -t ext4

Skip Partitioning and Create ZFS Filesystem

Prepare a device (/dev/md0) with a ZFS filesystem without partitioning:

gensprep -a -t zfs /dev/md0

Common Issues

  • Error: Device is already in use: Ensure the device is not mounted or being used by another process before preparing it.
  • Error: Failed to create file system: Check if the specified file system type is supported by the device and if there is sufficient space available.

Integration

gensprep can be used in conjunction with other commands:

  • mkfs to create a file system manually after partitioning.
  • cryptsetup to manage LUKS encryption.
  • fdisk to adjust partition tables.

Related Commands

  • fdisk
  • mkfs
  • cryptsetup