安装Linux的第一步就是创建磁盘系统,而创建系统主要分为成两个步骤:

1. 创建分区,2.创建文件系统

创建分区:

常用三个命令fdisk,parted

fdisk:是最常用的

限制:

1. fdisk不支持gpt磁盘, 也就是说它不能划分大于2T的分区 (例如下图)

2. 最多划分15个分区

# fdisk /dev/sdb Warning: invalid flag 0x0000 of partition table 4 willbe corrected by w(rite) WARNING: The size of this disk is 5.9 TB (5908688535552bytes).DOS partition table format can not be used on drivesfor volumeslarger than (2199023255040 bytes) for 512-byte sectors.Use parted(1) and GUIDpartition table format (GPT).

如果需要划分大于2T的分区,需要用到命令parted下文会有介绍

我们通过下面的例子来划分个新的分区并且介绍一些常用参数

  1. 查看系统上说有可识别的磁盘, 通过grep命令来过滤所有磁盘信息.

[root@centos~]# fdisk -l | grep "Disk /dev/sd.*"Disk/dev/sda: 53.7 GB, 53687091200 bytesDisk/dev/sdb: 21.5 GB, 21474836480 bytes

 

 2.选择要分区的硬盘

[root@centos ~]# fdisk /dev/sdb WARNING: DOS-compatible mode is deprecated. It'sstrongly recommended to         switchoff the mode (command 'c') and change display units to         sectors(command 'u'). Command (m for help):

 

3.      依次通过命令n(创建一个新的分区), 4(选择第几个分区), +500M(这个分区大小为500M),w(存储并且退出)

在输入w前可以用p命令查看结果,如果不满意可以直接q退出而不用保存.

Command (m for help): nCommand action   e   extended   p   primary partition (1-4)pSelected partition 4First cylinder (147-2610, default 147): 4Value out of range.First cylinder (147-2610, default 147):Using default value 147Last cylinder, +cylinders or +size{K,M,G} (147-2610,default 2610): +500M Command (m for help): wThe partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed witherror 16: Device or resource busy.The kernel still uses the old table. The new table willbe used atthe next reboot or after you run partprobe(8) orkpartx(8)Syncing disks.

 

parted命令

查看所有当前分区

[root@centos ~]# parted /dev/sdbGNU Parted 2.1Using /dev/sdbWelcome to GNU Parted! Type 'help' to view a list ofcommands.(parted) print                                                           Model: VMware, VMware Virtual S (scsi)Disk /dev/sdb: 21.5GBSector size (logical/physical): 512B/512BPartition Table: msdos Number Start   End     Size  Type     File system  Flags 1      32.3kB 115MB   115MB  primary ext4 2      115MB  658MB   543MB  primary ext4 3      658MB  1201MB  543MB  primary ext3 4      1201MB 1736MB  535MB  primary

改变显示单位为TB

(parted) unit TB

 

格式化的时候一定要先上一步print出来,这样就知道从哪里开始格式化.

(parted) mkpartfs                                                        WARNING: you are attempting to use parted to operate on(mkpartfs) a file system.parted's file system manipulation code is not as robustas what you'll find indedicated, file-system-specific packages likee2fsprogs.  We recommendyou use parted only to manipulate partition tables,whenever possible.Support for performing most operations on most types offile systemswill be removed in an upcoming release.Partition type? primary/extended? primary                               File system type? [ext2]?                                               Start? 17367End? 18367                                                                Warning: WARNING: the kernel failed to re-read thepartition table on /dev/sdb (Device or resourcebusy).  As aresult, it may not reflect all of your changes until after reboot.

 

创建文件系统,

我们可以用–t ext2 ext3 来选择格式化成不同的文件类型

[root@centos ~]# mke2fs -t ext4 /dev/sdb3