当前位置:   article > 正文

ubuntu数据盘扩展后初始化_mkpart opt 2048s 100%

mkpart opt 2048s 100%

查看新增数据盘

[root@ecs-test]# fdisk -l

Disk /dev/xvda: 42.9 GB, 42949672960 bytes, 83886080 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x000cc4ad

  Device Boot      Start         End      Blocks   Id  System

/dev/xvda1   *        2048     2050047     1024000   83  Linux

/dev/xvda2         2050048    22530047    10240000   83  Linux

/dev/xvda3        22530048    24578047     1024000   83  Linux

/dev/xvda4        24578048    83886079    29654016    5  Extended

/dev/xvda5        24580096    26628095     1024000   82  Linux swap / Solaris

Disk /dev/xvdb: 10.7 GB, 10737418240 bytes, 20971520 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes
  • 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

/dev/xvda”是系统盘,“/dev/xvdb”是本次新增的数据盘。

创建GPT分区

  1. 执行命令parted /dev/xvdb,进入parted分区工具。回显如下:
[root@ecs-test]# parted /dev/xvdb

GNU Parted 3.1

Using /dev/xvdb

Welcome to GNU Parted! Type 'help' to view a list of commands.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  1. 输入“p”,按“Enter”,查看当前磁盘分区形式。回显如下:
(parted) p

Error: /dev/xvdb: unrecognised disk label

Model: Xen Virtual Block Device (xvd)                                      

Disk /dev/xvdb: 10.7GB

Sector size (logical/physical): 512B/512B

Partition Table: unknown

Disk Flags:
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

“Partition Table”为“unknown”表示磁盘分区形式未知。

  1. 输入命令mklabel gpt,设置磁盘分区形式。磁盘分区形式有MBR和GPT两种,本示例中以GPT为例。

  2. 输入“p”,按“Enter”,设置分区形式后,再次查看确认磁盘分区形式。回显如下:

(parted) mklabel gpt                                              

(parted) p                                                        

Model: Xen Virtual Block Device (xvd)

Disk /dev/xvdb: 20971520s

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Disk Flags:  

Number  Start  End  Size  File system  Name  Flags
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

可以看到,“Partition Table”为“gpt”,表示磁盘分区形式已设置为GPT。

  1. 输入“unit s”,按“Enter”,设置磁盘的计量单位为磁柱。

  2. 输入“mkpart opt 2048s 100%”,按“Enter”。“2048s”表示磁盘起始容量,“100%”表示磁盘截止容量。参数仅供参考,此例中是为整个磁盘创建一个分区,您可以根据业务需要自行规划磁盘分区数量及容量。回显如下:

(parted) unit s

(parted) mkpart opt 2048s 100%

Warning: The resulting partition is not properly aligned for best performance.

Ignore/Cancel? Ignore
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

若出现以上性能优化提醒,请输入“Ignore”,忽略即可。

  1. 输入“p”,按“Enter”,查看新建分区的详细信息。回显如下:
(parted) p                                                                

Model: Xen Virtual Block Device (xvd)

Disk /dev/xvdb: 20971520s

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Disk Flags:  



Number  Start   End        Size       File system  Name  Flags

1      2048s   20969471s  20967424s               opt
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  1. 输入“q”,按“”Enter”,退出parted分区工具。分区创建完成。

  2. 执行命令lsblk,确认分区已成功创建。回显如下:

[root@ecs-test]# lsblk                                  

NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

xvda    202:0    0   40G  0 disk  

├─xvda1 202:1    0    4G  0 part [SWAP]

└─xvda2 202:2    0   36G  0 part /

xvdb    202:16   0  100G  0 disk  

└─xvdb1 202:17   0  100G  0 part
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

创建MBR分区

  1. 执行命令fdisk /dev/xvdb,进入fdisk分区工具。回显如下:
[root@ecs-test]# fdisk /dev/xvdb

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0xb00005bd.

Command (m for help):
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  1. 输入“n”,按“Enter”,开始新建分区。回显如下:
Command (m for help): n

Partition type:

  p   primary (0 primary, 0 extended, 4 free)

  e   extended
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

其中,磁盘有两种分区类型:“p”表示主要分区,“e”表示延伸分区。

  1. 以创建一个主要分区为例,输入“p”,按“Enter”,开始创建一个主分区。回显如下:
Select (default p): p

Partition number (1-4, default 1):
  • 1
  • 2
  • 3

“Partition number”表示主分区编号,可以选择1到4之间的数字。

  1. 以分区编号选择“1”为例,输入主分区编号“1”,按“Enter”。回显如下:
Partition number (1-4, default 1): 1

First sector (2048-20971519, default 2048):
  • 1
  • 2
  • 3

“First sector”表示初始磁柱区域,可以选择2048-20971519,默认为2048。

  1. 以选择默认初始磁柱编号2048为例,按“Enter”。回显如下:
First sector (2048-20971519, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):
  • 1
  • 2
  • 3
  • 4
  • 5

“Last sector”表示截止磁柱区域,可以选择2048-20971519,默认为20971519。

  1. 以选择默认截止磁柱编号20971519为例,按“Enter”。回显如下:
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):

Using default value 20971519

Partition 1 of type Linux and of size 10 GiB is set

Command (m for help):
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

表示分区完成,即为10GB的数据盘新建了1个分区。

  1. 输入“p”,按“Enter”,查看新建分区的详细信息。回显如下:
Command (m for help): p

Disk /dev/xvdb: 10.7 GB, 10737418240 bytes, 20971520 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0xb00005bd

  Device Boot      Start         End      Blocks   Id  System

/dev/xvdb1            2048    20971519    10484736   83  Linux

Command (m for help):
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  1. 输入“w”,按“Enter”,将分区结果写入分区表中。回显如下:
Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

表示分区创建完成。

如果之前分区操作有误,请输入“q”,则会退出fdisk分区工具,之前的分区结果将不会被保留。

  1. 执行命令partprobe,将新的分区表变更同步至操作系统。

创建文件系统并挂载

  1. 执行命令mkfs -t ext4 /dev/xvdb1,为新建的分区创建文件系统,本示例中创建的是ext4格式的文件系统,请根据您的业务需求选择合适的文件系统。
[root@ecs-test]# mkfs -t ext4 /dev/xvdb1

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

655360 inodes, 2621184 blocks

131059 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2151677952

80 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

       32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632



Allocating group tables: done

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done
  • 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

格式化需要等待一段时间,请观察系统运行状态,不要退出,直到显示格式化完成。

  1. 执行命令mkdir /mnt/sdc,新建挂载点。本示例中“/mnt/sdc”为挂载点。

  2. 执行命令mount /dev/xvdb1 /mnt/sdc,将新建分区挂载到新建的挂载点下。

  3. 执行命令df -TH,查看挂载结果。回显如下:

[root@ecs-test]# df -TH

Filesystem     Type      Size  Used Avail Use% Mounted on

/dev/xvda2     xfs        11G  7.4G  3.2G  71% /

devtmpfs       devtmpfs  4.1G     0  4.1G   0% /dev

tmpfs          tmpfs     4.1G   82k  4.1G   1% /dev/shm

tmpfs          tmpfs     4.1G  9.2M  4.1G   1% /run

tmpfs          tmpfs     4.1G     0  4.1G   0% /sys/fs/cgroup

/dev/xvda3     xfs       1.1G   39M  1.1G   4% /home

/dev/xvda1     xfs       1.1G  131M  915M  13% /boot

/dev/xvdb1     ext4       11G   38M  9.9G   1% /mnt/sdc
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

表示新建分区“/dev/xvdb1”已挂载至“/mnt/sdc”。

设置开机自动挂载磁盘

如果您需要在云主机系统启动时自动挂载磁盘,不能采用在 /etc/fstab直接指定 /dev/xvdb1的方法,因为云中设备的顺序编码在关闭或者开启云主机过程中可能发生改变,例如/dev/xvdb1可能会变成/dev/xvdb2。推荐使用UUID来配置自动挂载数据盘。磁盘的UUID(universally unique identifier)是Linux系统为磁盘分区提供的唯一的标识字符串。

  1. 执行命令blkid /dev/xvdb1,查询磁盘分区的UUID。回显如下:
[root@ecs-test]# blkid /dev/xvdb1

/dev/xvdb1: UUID="******-****-****-****-******" TYPE="ext4"
  • 1
  • 2
  • 3
  1. 执行命令vi /etc/fstab,使用VI编辑器打开“fstab”文件。按“i”,进入编辑模式,将光标移至文件末尾,按“Enter”,添加如下内容,其中UUID=处的内容请输入您在上一步中查询到的UUID。
UUID=******-****-****-****-****** /mnt/sdc      ext4 defaults     0   2
  • 1

按“ESC”后,输入“:wq”,按“Enter”“Enter”。保存设置并退出编辑器。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/205755
推荐阅读
相关标签
  

闽ICP备14008679号