the linux ( OS ) installed on sda

and machine also have additional disk - sdb

sdb                8:16   0    20G  0 disk 

but we want to add two new partitions as sdb1 and sdb2

as the following:

sdb                8:16   0    20G  0 disk 
├─sdb1             8:1    0   500M  0 part 
└─sdb2             8:2    0   500M  0 part 

how to create the disk to be parted with partitions - sdb1 and sdb2?


Assuming GNU parted, and assuming the snippets you are showing are from the output of lsblk, here is a minimal set of actions you can perform to accomplish what you are asking for:

Running parted as root, select the device you want to act upon:

(parted) select /dev/sdb

Create a MBR partition table (no particular reason for choosing this type; in parted, type help mklabel for a list of available types):

(parted) mklabel msdos

Then, create the partitions:

(parted) unit MiB
(parted) mkpart primary 1 501
(parted) mkpart primary 501 1000

parted is instructed here to use the mebibyte as unit because that is the default for lsblk. This way you can outright type the same numbers posted in your question.

The starting point of the first partition is arbitrarily at 1 MiB because 1) it cannot be at 0 and 2) 1 MiB is a relatively lazy but safe choice for alignment. A discussion on partition alignment seems out of scope here.

You can then check your changes with:

(parted) print

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.