parted /dev/loop3 targets the loop
The command parted /dev/loop3 starts the parted utility and targets the loop device /dev/loop3. This means you’re about to partition the file associated with this loop device, not a physical hard drive.
1. Loop Devices
Loop devices are virtual block devices. They allow you to mount a regular file as if it were a block device (like a hard drive partition). Before using parted /dev/loop3, you must have already set up /dev/loop3 using losetup.
Example setup:
1 | # Create a file to use as a disk image (e.g., 1GB) |
2. parted /dev/loop3
Once the loop device is set up, running sudo parted /dev/loop3 (you’ll likely need sudo) will launch the parted interactive command-line tool. You’ll see the (parted) prompt.
3. Common parted Commands
Inside the parted prompt, you can use the following commands:
mklabel <label-type>: Creates a new disk label (partition table). Common types aremsdos(for MBR partitions) andgpt(for GPT partitions).gptis recommended for modern systems. Example:mklabel gptmkpart <part-type> <fs-type> <start> <end>: Creates a new partition.<part-type>:primary,extended, orlogical(only formsdoslabels). Forgpt, it’s usuallyprimary.<fs-type>: This is informational;parteddoesn’t format the partition. Common values areext4,fat32,linux-swap.<start>and<end>: The start and end positions of the partition. You can use percentages (e.g.,0%,100%), megabytes (e.g.,0MB,500MB), or gigabytes (e.g.,0GB,1GB).
print: Displays the current partition table.rm <partition-number>: Removes a partition.resizepart <partition-number> <end>: Resizes a partition.quit: Exitsparted.
Example parted session:
1 | sudo parted /dev/loop3 |
4. After Partitioning (Important!)
parted only creates the partition table and partitions. You must then format the partition with a filesystem:
1 | sudo mkfs.ext4 /dev/loop3p1 # Format the first partition (adjust if different) |
5. Mounting the Partition
You can then mount the partition:
1 | sudo mkdir /mnt/loop3 |
6. Cleaning Up
When you’re finished, unmount the partition and detach the loop device:
1 | sudo umount /mnt/loop3 |
Key Points
losetupis essential: You must uselosetupto create the loop device before usingparted.- Formatting is required:
parteddoes not format the partitions. Usemkfs.*(e.g.,mkfs.ext4,mkfs.vfat) after partitioning. - Permissions: You’ll likely need
sudofor all these commands. - Persistence: The changes you make are written to the file you used with
losetup(mydisk.imgin the example).