0% found this document useful (0 votes)
44 views5 pages

USB Partitioning

The document provides a detailed guide on using the 'parted' command for partitioning disks and USB drives in a Linux environment. It covers commands for displaying disk information, creating and managing partitions, and emphasizes the importance of unmounting devices before making changes. Additionally, it includes troubleshooting tips for common errors encountered during partitioning operations.

Uploaded by

naveenthumati095
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views5 pages

USB Partitioning

The document provides a detailed guide on using the 'parted' command for partitioning disks and USB drives in a Linux environment. It covers commands for displaying disk information, creating and managing partitions, and emphasizes the importance of unmounting devices before making changes. Additionally, it includes troubleshooting tips for common errors encountered during partitioning operations.

Uploaded by

naveenthumati095
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

You can open the terminal using (Ctrl+Alt+t).

There are many commands to partition a disk/USB like cfdisk, fdisk, partx, lsblk, wipefs. Parted is
most popular because of its advanced functionalities. You can take the help by looking its manual
$man lsblk. This will display all the functionalities of lsblk

When you plugin a pendrive it will automatically mount. Login as a administrator/superuser using
$sudo su

$ fdisk -l
This will display your system and mount locations of disk/USB. The bottom line display mount
location of your USB drive i.e. /dev/sdxx. Here xx vary according to systems so you can replace
with your system’s value. For example the xx value is b1 so my device location is /dev/sdb1.

You may also get the device location with $ df -h. In the bottom line you will get your usb device
location /dev/sdxx

sonal@sonal-hp:~$ umount /dev/sdb1


Before starting any operation on USB you have to unmount the USB. This command will unmount
your USB.

Parted is pre-installed in many ubuntu versions. If it is not installed then you can install it
sonal@sonal-hp:~$ sudo apt-get install parted

sonal@sonal-hp:~$ sudo parted /dev/sdb1


GNU Parted 3.2
Using /dev/sdb1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: Unknown (unknown)
Disk /dev/sdb1: 8004MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number Start End Size File system Flags


1 0.00B 8004MB 8004MB fat32
print command display the usb information. This usb have single parition, partition start and end,
size of the usb and its file system.

Create a Partition Table


If you are happy with your existing partition table, you can skip the part create partition table. If you
want to change your partition table type, you have to follow the commands of create partition table.
In previous section your can see USB partition table type is loop.

(parted) mklabel
New disk label type? gpt
Warning: The existing disk label on /dev/sdb1 will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? Yes
Error: Partition(s) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64 on /dev/sdb1 have been written, but we have been
unable to inform the kernel of the change, probably because it/they are in use.
As a result, the old partition(s) will remain in use. You should reboot now
before making further changes.
Ignore/Cancel? Ignore
(parted)

The possible options with maklabel like gpt, msdos, loop etc. can be seen with man parted
Note: if you mklabel the partition and plug out the pendrive and reinsert it then parted will give
some error on performing other operations. Since your mount location may change with reinsertion.
May be new location is /dev/sdc1 that is different then your previous location /dev/sdb1. So you
need to start again with parted.

sonal@sonal-hp:~$ sudo [Link] /dev/sdb1


sonal@sonal-hp:~$ sudo parted /dev/sdb1
GNU Parted 3.2
Using /dev/sdb1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: Unknown (unknown)
Disk /dev/sdb1: 8004MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number Start End Size File system Flags


1 0.00B 8004MB 8004MB fat32

mklabel label-type
Create a new disklabel (partition table) of label-type.
label-type should be one of "aix", "amiga", "bsd", "dvh",
"gpt", "loop", "mac", "msdos", "pc98", or "sun".
mkpart part-type [fs-type] start end
Make a part-type partition for filesystem fs-type (if
specified), beginning at start and ending at end (by
default in megabytes). part-type should be one of "pri‐
mary", "logical", or "extended".

(parted) help mklabel

sonal@sonal-hp:~$ sudo parted /dev/sdc1


[sudo] password for sonal:
GNU Parted 3.2
Using /dev/sdc1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: Unknown (unknown)
Disk /dev/sdc1: 8004MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags

Now you can see that we have only partition table. No partitions are created on disk. So there is no
other information display about the USB partitions.

Create Single Partitions


(parted) mkpart
Partition name? []? primary
File system type? [ext2]? ext2
Start? 0%
End? -1s
Warning: You requested a partition from 0.00B to 8004MB (sectors 0..15633344).
The closest location we can manage is 17.4kB to 8004MB (sectors 34..15633311).
Is this still acceptable to you?
Yes/No? Yes
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore
Error: Partition(s) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64 on /dev/sdc1 have been written, but we have been
unable to inform the kernel of the change, probably because it/they are in use.
As a result, the old partition(s) will remain in use. You should reboot now
before making further changes.
Ignore/Cancel? Ignore
(parted) print
Model: Unknown (unknown)
Disk /dev/sdc1: 8004MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags


1 17.4kB 8004MB 8004MB ext2 primary

select device
Choose device as the current device to edit. device
should usually be a Linux hard disk device, but it can be
a partition, software raid device, or an LVM logical vol‐
ume if necessary.

set partition flag state


Change the state of the flag on partition to state. Sup‐
ported flags are: "boot", "root", "swap", "hidden",
"raid", "lvm", "lba", "legacy_boot", "irst", "esp" and
"palo". state should be either "on" or "off".
Resize Partitions
(parted) resizepart
Partition number? 1
End? [8004MB]? 4002
Warning: Shrinking a partition can cause data loss, are you sure you want to
continue?
Yes/No? Yes
Error: Partition(s) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64 on /dev/sdc1 have been written, but we have been
unable to inform the kernel of the change, probably because it/they are in use.
As a result, the old partition(s) will remain in use. You should reboot now
before making further changes.
Ignore/Cancel? Ignore
(parted) print
Model: Unknown (unknown)
Disk /dev/sdc1: 8004MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags


1 17.4kB 4002MB 4002MB ext2 primary

Create Multiple Partitions


(parted) mkpart
Partition name? []? extended
File system type? [ext2]? ext3
Start? 4003
End? 8004
Error: Partition(s) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64 on /dev/sdc1 have been written, but we have been
unable to inform the kernel of the change, probably because it/they are in use.
As a result, the old partition(s) will remain in use. You should reboot now
before making further changes.
Ignore/Cancel? Ignore
(parted) print
Model: Unknown (unknown)
Disk /dev/sdc1: 8004MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags


1 17.4kB 4002MB 4002MB ext2 primary
2 4003MB 8004MB 4000MB ext3 extended

Remove Partitions
(parted) rm 2
Error: Partition(s) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64 on /dev/sdc1 have been written, but we have been
unable to inform the kernel of the change, probably because it/they are in use.
As a result, the old partition(s) will remain in use. You should reboot now
before making further changes.
Ignore/Cancel? Ignore
(parted) print
Model: Unknown (unknown)
Disk /dev/sdc1: 8004MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags


1 17.4kB 4002MB 4002MB ext2 primary

(parted) quit
sonal@sonal-hp:~$

quit command exit you from the parted.

References:
1. Parted Basic Tutorial: [Link]
2. Using Parted Command in Linux: [Link]

You might also like