Partition and format hard drives

There are many tools for partitioning hard disks, including graphical interfaces, command-line interfaces, commercial ones, and
open source ones, and there are always dozens of them. We chose to use one of the most classic tools: fdisk.
The fdisk command has a long history and is widely used,
appearing in various versions of Unix, Linux and Windows.
Enter fdisk /dev/sdb in the command line to enter the interface of fdisk partitioning /dev/sdb.
fdisk will output some prompts and warnings, which can be ignored directly. The last line is the shortcut prompt line of fdisk,
after ":" You can enter the shortcut keys of fdisk to perform partition operations. If you do not know the shortcut keys of fdisk
, you can press “m” to view the help document, or you can check the
reference table of “Shortcut keys in fdisk” provided in this task. .
[root @localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xa04d9ff7.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off
the mode (command 'c') and change display units to sectors (command 'u ').
Command (m for help):
Next we will create the first partition:
Command (m for help): n #Enter n to create a new partition
Command action
e extended
p primary partition (1-4)
p
#fdisk will When asked whether to create a main partition or an extended partition, we choose p, the main partition
Partition number (1-4): 1
#Enter the partition number, which must be less than 4, because we have already mentioned in the previous item 1, we choose 1
First cylinder ( 1-65270, default 1): 1

important
Shortcuts in fdisk:
 a set boot partition ID
 d delete a partition
 l list ID numbers of all supported partition types
 m list shortcut help
 n add a new partition
 p list partition table
 q quit without executing task
 t change a partition type
 w execute task and quit


#Enter the starting cylinder number of the partition, usually the default is
Last cylinder, +cylinders or +size{K,M,G} (1-65270, default 65270): +100G #Enter
the ending cylinder number of the partition , of course, you can also directly enter the size of the partition, pay attention to add the "+" sign
Command (m for help): p
#List the partition table, we can see that the first partition is already in
Disk /dev/sdb: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xaddf3d95
Device Boot Start End Blocks Id System
/dev/sdb1 1 13055 104864256 83 Linux
# Device Boot partition name, Start start cylinder, End end cylinder, Blocks means block, not formatted
For #specific partition type, all block sizes are 1KB, Id System identifies the partition type and id number, the default is 83
#Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re- read partition table.
Syncing disks.
# Enter w to write the new partition into the partition table. If you press q to exit at this time, the changes will not be written to the partition
table . Create all subsequent partitions:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
# Enter e, which means to create an extended partition
Partition number (1-4): 2
First cylinder (13056-65270, default 13056):
Using default value 13056
Last cylinder, +cylinders or +size{K,M,G} (13056-65270, default 65270):
Using default value 65270
Command (m for help): n
Command action
Notice
If a partition of the disk you are operating on is in use (typically, the disk includes the root partition
), then it is very likely that your partition operation on the disk will not
be . Partition unmount (umount) or restart, the information of the new partition can be written to the partition
table.


l logical (5 or over)
p primary partition (1-4)
l
# If an extended partition is established, e will no longer appear in the selection partition type, and replace it with l, indicating
that
# logical partition can be established, We enter l here to create a logical partition
First cylinder (13056-65270, default 13056):
Using default value 13056
Last cylinder, +cylinders or +size{K,M,G} (13056-65270, default 65270): +64G
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (21412-65270, default 21412):
Using default value 21412
Last cylinder, +cylinders or +size{K ,M,G} (21412-65270, default 65270): +64G
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (29768-65270, default 29768):
Using default value 29768
Last cylinder, +cylinders or +size{K,M,G} (29768-65270, default 65270):
Using default value 65270
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
查看建立好的分区:
[root @localhost ~]# fdisk –l /dev/sdb
Disk /dev/sdb: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2f7e945a
Device Boot Start End Blocks Id System
/dev/sdb1 1 13055 104864256 83 Linux
/dev /sdb2 13056 65270 419416987+ 5 Extended
/dev/sdb5 13056 21411 67119538+ 83 Linux
/dev/sdb6 21412 29767 67119538+ 83 Linux /
dev/sdb7 29768 65270 285177 816
The logical partition established in this extended partition, pay special attention to
# The partition serial number of the logical partition starts from 5, because 1-4 are reserved for the primary partition and the extended partition.
Of course , if there is an error, such as the size of the partition, the partition number When the input is wrong, we can directly press
q to exit fdisk, all previous operations will not be written to the partition table
of . For example, we can delete the partition sdb7 just now and repartition it.
Command sequence error! No text in the specified style in the document. -1
[root @localhost ~]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): d
Partition number (1-7): 7
# 输入 d, 表示删除一个分区,随后输入要删除的分区号 7
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root @localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2f7e945a
Device Boot Start End Blocks Id System
Notice
In the last field of the partition table listed in fdisk, Id System indicates the type of the partition,
but before formatting the partition, this field is not the real type of the partition, it is just an
identification.


/dev/sdb1 1 13055 104864256 83 Linux
/dev/sdb2 13056 65270 419416987+ 5 Extended
/dev/sdb5 13056 21411 67119538+ 83 Linux
/dev/sdb6 21412 29767 67119538+ 83 Linux
[root @localhost ~]#
careful
In the process of partitioning the disk with fdisk, if the operation is wrong, you can press the q key to leave directly.
All previous operations will not be written to the disk partition table. If you confirm that all the operations are correct, press the w
key to write the operation. Disk partition table.
 
Order
Usage: fdisk[options]... Disk device name..
View/modify disk partition table
 -l View partition table


 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325071789&siteId=291194637