You are at the terminal, trying to partition a disk, and you get hit with The location XXMB is outside of the device /dev/xxx. It is one of the most annoying errors in Linux system administration because it feels like a math problem you didn't sign up for. Usually, this happens because you are trying to force a partition to end at a specific megabyte that physically does not exist or is reserved by the partition table itself.

The good news is that you do not need to pull out a calculator to fix this. The issue usually stems from the difference between decimal (1000KB) and binary (1024KB) calculations, or simply ignoring the space required for the secondary GPT header at the end of the disk. Here is how to bypass the math and get your partition created.

Method 1: The Lazy Fix (Using Percentages)

This is the most reliable way to solve the problem. Instead of telling parted exactly which megabyte to start and stop at, you tell it to use percentages of the disk. This forces the tool to calculate the exact available sectors for you, automatically leaving room for the GPT backup header at the end of the drive.

If you are trying to use the whole disk for a single partition, run this command:

mkpart primary ext4 0% 100%

Here is why this works better than manual numbers:

  • 0%: Automatically aligns the start of the partition for optimal performance (usually starting at 2048 sectors), preventing warning messages about alignment.
  • 100%: Tells the system to go to the very end of the usable space, not the physical end of the block device. This avoids the "outside of device" error perfectly.

If you are scripting this or setting up servers related to operating systems, using percentages makes your scripts portable across disks of slightly different sizes.

Method 2: The Precision Fix (Using Sectors)

Sometimes you cannot use percentages because you need specific partition sizes. The problem with using unit MB or GB is that they are imprecise. To parted, 10GB might mean 10,000MB or 10,240MB depending on the context.

To fix this, switch your unit to sectors (s). Sectors are the atomic units of the disk (usually 512 bytes), and they remove all ambiguity.

First, set the unit to sectors and print the free space:

unit s
print free

You will see an output looking something like this:

Number  Start       End          Size         Type     File system  Flags
        34s         2047s        2014s        Free Space
 1      2048s       1000000s     997953s      primary  ext4
        1000001s    2097151s     1097151s     Free Space

Now, look at the End column of the "Free Space" row. That is your absolute limit. If you try to create a partition that ends even one sector after that number, you will get the error. When creating your partition, use that exact number for your end point.

Why Disk Size vs Usable Size is Different

Understanding the root cause helps you avoid this in the future. When you initialize a disk with a GPT (GUID Partition Table), the system writes metadata to the beginning of the disk (LBA 0-33) and a backup copy to the very end of the disk.

If you have a 10GB drive, you do not actually have 10GB of writeable space for partitions. You have 10GB minus the space reserved for that secondary GPT header. When you calculate partitions manually and try to use every single byte up to the limit, you overwrite that backup header. parted blocks this action to prevent corruption, triggering the outside of the device error.

If you are troubleshooting this on a live system and need to check system logs for other disk-related errors, the linux tail command is your best friend for monitoring kernel messages in real-time.

Cleaning the Disk Structure

In some cases, the error persists even when your math is correct. This often happens if the disk was previously part of a RAID array or had a different partition table format (like MBR) that was not completely wiped. The tool sees "ghost" metadata and gets confused about the drive's actual size.

Before you give up, try wiping the partition table signatures. While many users default to dd, the wipefs command is safer and more targeted:

sudo wipefs -a /dev/sdX

Warning: This deletes all partition table signatures. Make sure you are targeting the correct device. If you are unsure about the device path, you can double-check device nodes. For locating specific configuration files related to your storage mounts, knowing how to find a directory on linux is essential.

After wiping, create a fresh label:

mklabel gpt

Then try the percentage method again. This usually clears up any conflicting geometry data that causes the error.

Dealing with Alignment Warnings

After fixing the "outside of device" error, you might immediately hit a "The resulting partition is not properly aligned for best performance" warning. This is not an error, but it degrades disk speed, especially on SSDs.

If you used the 0% start point suggested in Method 1, parted handles this for you. However, if you are manually specifying start points in MB or sectors, ensure your start sector is a multiple of 2048. This aligns the partition payload with the physical 4K blocks of modern drives, ensuring you get the full I/O speed your hardware is capable of.