Encountering the error "The location XXMB is outside of the device /dev/xxx" when using parted
can be both confusing and frustrating. This guide breaks down the issue, explains why it happens, and provides clear steps to fix it. By the end of this article, you’ll understand the root causes and learn how to create partitions without running into this problem.
What Does This Error Mean?
This error occurs when you attempt to create a partition or perform an operation on a storage device, but the specified location exceeds the actual size of the device. For example, if your device is 32GB, trying to create a partition ending at 40GB will cause this error.
-
Device Size: The total storage capacity of the device, such as an SD card or hard drive.
-
Partition: A segment of the storage device that is formatted and used separately.
-
Location: The starting and ending points of the partition in MB, GB, or other units.
Why Does This Error Happen?
This error can be caused by several factors, and understanding them is key to avoiding frustration and successfully partitioning your device. Below, we will explore the most common reasons behind this issue and provide insights into how you can prevent it.
1. Incorrect Partition Size Specification
If the size you specify for a partition exceeds the physical size of the device, parted
cannot complete the operation. For example:
sudo parted -s /dev/sda mkpart primary 32MB 512MB
If the device is only 100MB, trying to create a partition ending at 512MB will fail.
2. Improper Alignment or Unit Usage
parted
supports various units like MB, MiB, GB, and GiB. Mixing up these units can cause alignment issues and result in errors.
-
MB refers to megabytes (decimal).
-
MiB refers to mebibytes (binary).
Using MB instead of MiB might create unexpected offsets, leading to out-of-bounds locations.
3. Formatting Mistakes in Commands
The syntax or parameters might be incorrect, leading parted
to interpret the command improperly. For instance, adding unnecessary labels or flags.
4. Corrupt or Misidentified Devices
Sometimes, the device may not be correctly recognized due to previous partitioning errors, hardware issues, or incomplete wiping of the device. These factors can interfere with parted
’s ability to identify the device’s actual size or structure, leading to errors during partitioning.
Steps to Fix the Error
Here’s how to address and resolve the issue step-by-step.
Step 1: Verify the Device Size
Before creating partitions, check the actual size of your device:
lsblk
Example output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 1 119.4G 0 disk
Ensure your partition commands do not exceed the SIZE
shown for your device.
Step 2: Use the Correct Units
When specifying locations, use MiB for precise alignment:
sudo parted -s /dev/sda mkpart primary fat32 1MiB 512MiB
This command creates a partition starting at 1MiB and ending at 512MiB.
Step 3: Check Free Space
Use parted
to check available space:
sudo parted /dev/sda unit mib print free
This will display the free and used space on the device, ensuring your commands are within bounds.
Step 4: Wipe the Device
If the device has existing partitions or formatting issues, wipe it clean before starting:
sudo dd if=/dev/zero of=/dev/sda bs=1M count=32
This clears the first 32MB of the device, resetting its partition table.
Step 5: Update parted
Ensure you are using the latest version of parted
. Outdated versions might have bugs or lack support for newer features.
Example Scenario
You have an SD card with a capacity of 32GB, and you want to create partitions for a Linux distro. If the SD card is only 100MB, this command fails because 512MB exceeds the device size.
sudo parted -s /dev/sda mkpart primary fat32 32MB 512MB
Solution: Check the device size using lsblk
. Adjust the command based on available space:
sudo parted -s /dev/sda mkpart primary fat32 1MiB 100MiB
Conclusion
Understanding how parted
works and why errors like The location XXMB is outside of the device occur can save time and frustration. By following these steps, you’ll be able to troubleshoot and fix such issues effectively.