Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIHugging Face LMArena Human Preference 140K

I have shrinked a btrfs partition to 256G, it's inside LUKS, now how do I resize LUKS…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Qwenqwen-max-2025-01-25’s answer.
  1. User

    I have shrinked a btrfs partition to 256G, it's inside LUKS, now how do I resize LUKS and the partition correctly?

  2. Assistant

    You have a Btrfs filesystem inside a LUKS-encrypted container, and you've already shrunk the Btrfs filesystem to 256G. Now you want to resize the underlying LUKS container and the partition to match the smaller size.

    Here's the general approach and important considerations:


    Important Notes Before Proceeding

    • Backup your data! Resizing encrypted containers and partitions is risky and can lead to data loss.
    • Make sure the Btrfs filesystem is clean and properly shrunk before resizing LUKS.
    • You cannot resize the LUKS container larger than the underlying partition.
    • The order of operations is:
      1. Shrink the filesystem (done)
      2. Shrink the LUKS container
      3. Shrink the partition

    Step-by-step guide

    1. Shrink the Btrfs filesystem (already done)

    You mentioned you have already shrunk the Btrfs filesystem to 256G. Just to confirm, the command to shrink Btrfs is:

    btrfs filesystem resize 256G /mount/point
    

    or

    btrfs filesystem resize -256G /mount/point
    

    Make sure the filesystem is clean and unmounted or mounted read-only before shrinking.


    2. Shrink the LUKS container

    The LUKS container size is defined by the underlying block device (partition). You cannot directly shrink the LUKS container itself, but you can resize the underlying block device (partition) and then resize the LUKS container header to match.

    However, LUKS2 supports resizing the container header with cryptsetup resize. This command resizes the LUKS device to the size of the underlying block device.

    So the process is:

    • Shrink the partition (block device)
    • Run cryptsetup resize to resize the LUKS container to the new partition size

    3. Shrink the partition

    You need to shrink the partition that holds the LUKS container.

    • Use a partitioning tool like fdisk, parted, or gdisk to shrink the partition.

    Example with parted:

    parted /dev/sdX
    (parted) print
    (parted) resizepart N 256G
    (parted) quit
    

    Where /dev/sdX is your disk and N is the partition number.

    Important: Make sure the new partition size is at least as large as the LUKS container size (which should be >= 256G).


    4. Resize the LUKS container to match the partition

    After shrinking the partition, run:

    cryptsetup resize <luks_name>
    

    This resizes the LUKS container to the size of the underlying block device (partition).


    5. Verify everything

    • Open the LUKS container:
    cryptsetup open /dev/sdXN luks_name
    
    • Check the Btrfs filesystem size:
    btrfs filesystem show /dev/mapper/luks_name
    
    • Mount and verify data integrity.

    Summary

    1. Shrink Btrfs filesystem (done)
    2. Shrink partition holding LUKS container (using parted/fdisk/gdisk)
    3. Run cryptsetup resize <luks_name> to resize LUKS container to new partition size
    4. Open LUKS container and verify Btrfs filesystem

    If you want, I can provide exact commands tailored to your setup if you provide:

    • Disk device name (e.g., /dev/sda)
    • Partition number (e.g., 3)
    • LUKS container name (e.g., cryptroot)
    • Mount point of Btrfs filesystem

    Be very careful and backup before proceeding!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.