List Partitions:
fdisk -l - will provide a list of partitions for all devices in the system
fdisk -l /dev/sda - will list all partitions for disk sda
Alternatively, you can use parted, like this:
parted - once inside the parted shell, type:
print all
In order to list the partitions in a single device, once inside the parted shell, simply type:
parted /dev/sdb
or while inside the parted shell:
select /dev/sdb
Note, that you could run the commands outside the parted command shell, like this: parted -l
Create Partitions:
First we'll use fdisk, note that this is for a blank disk, if the disk already contains partitions then there will be limitations, e.g. if you already have 4 primary partitions you'll only be able to create an extended partition.
- Start fdisk (note that you can type m for help) - fdisk /dev/sdb or fdisk -u /dev/sdb for sizes in sectors instead of cylinders
- Type n and you'll get the following options
- Type p
- Type 1, to make this the first partition
- The next option is where to start your partition, I normally accept the default, so I hit Enter
- The last option is where to end your partition. If you want just one partition accept the default, otherwise just select your partition size, e.g. say you want a 1 GB partition, you need type +1G
- type w, to write your changes to the partition table and exit fdisk.
Command action
e extended
p primary partition (1-4)
Now, let's turn to parted.
- Start parted (note that you can type help for help)- parted /dev/sdb
- Type makepart
- You'll get a choice of primary or extended, type primary
- Select the file type, e.g. ext4
- Select the start for the partition, note that unlike fdisk, you have to type something here, e.g. 1 for the partition to start at the beginning of the disk
- Select the end of the partition
- You might get a warning that the partition is not best aligned for performance, if you set the start at 0.
- Exit parted.
- Alternatively, you can just type parted /dev/sdb primary ext4 1 1000M from the command shell
Using parted only, and assuming that the disk is 8 GB and has a 1 GB primary partition:
- First make an extended partition - parted /dev/sdb mkpart extended 1000M 8000M
- Then make a logical partition - parted /dev/sdb mkpart logical 1001M 4000M
- output from: parted /dev/sdb print
Model: VMware Virtual disk (scsi)Note how the logical partition has a number of 5
Disk /dev/sdb: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 1000MB 999MB primary ext4
2 1000MB 8000MB 6999MB extended lba
5 1001MB 4000MB 2999MB logical
Delete partitions:
For fdisk.
- fdisk /dev/sdb
- Type d
- Type the number of the partition you want to delete
- Type w
- parted /dev/sdb
- rm n - where n is the number of the partition you want to delete.
- Alternatively, parted /dev/sdb rm n - where n is the number of the partition you want to delete.
This is relatively simple for fdisk.
- fdisk /dev/sdb
- Type t
- Type the partition number you want to use
- If you know the code, then type it, otherwise type L to get a list of partition codes
- Let's say we want to make it a swap partition, so type 82
- Type w
You can do parted /dev/sdb 5 set lvm on, to set the lvm label on, but I don't know how to change the partition type to say VMWare VMFS.
No comments:
Post a Comment