前几天收到需求,在阿里云上购买5台服务器,配置为32G,8核,3T
问题主要是卡在这里,阿里云的公共镜像里 Centos 7.3 默认为 EXT4 文件系统,和官方的不同,官网默认文件系统为 XFS 。而 EXT4 文件系统默认最大只支持最大分区为2TB,这里有3TB,如果用 EXT4 文件系统,就表示剩余的1TB空间会被浪费…

1
2
3
4
5
6
7
8
[root@bigdata1 ~]# fdisk -l /dev/vdb
Disk /dev/vdb: 3298.5 GB, 3298534883328 bytes, 6442450944 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
[root@bigdata1 ~]#

这时默认的fdisk分区工具将无法使用了,因为它不能满足我们的需求,这里就需要用到 parted 分区工具了

1
2
3
4
5
6
7
8
9
10
11
#分区命令
parted /dev/vdb
mklabel
gpt
mkpart
xfs
0G
3299GB
p
quit

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
[root@bigdata1 ~]# parted /dev/vdb
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Error: /dev/vdb: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 3299GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
(parted) help
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found
partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted
(parted) mklabel
New disk label type? gpt
(parted) p
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 3299GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
(parted) mkpart
Partition name? []? ?
File system type? [ext2]? xfs
Start? 0G
End? 3299GB
(parted) p
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 3299GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 3299GB 3299GB ?
(parted) quit
Information: You may need to update /etc/fstab.
[root@bigdata1 ~]#

然后格式化为 xfs 文件系统后挂载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@bigdata1 ~]# mkfs.xfs /dev/vdb1
meta-data=/dev/vdb1 isize=512 agcount=4, agsize=201326464 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=805305856, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=393215, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@bigdata1 ~]#
[root@bigdata1 ~]# blkid /dev/vdb1
/dev/vdb1: UUID="32687403-bcc8-425f-8544-ddf710186d53" TYPE="xfs" PARTLABEL="?" PARTUUID="580a257e-18e2-4d57-99cf-b5be5b6
9557a" [root@bigdata1 ~]#
[root@bigdata1 ~]# mkdir /data
[root@bigdata1 ~]# tail -1 /etc/fstab
UUID="32687403-bcc8-425f-8544-ddf710186d53" /data xfs defaults 0 0
[root@bigdata1 ~]# mount -a

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@bigdata1 ~]# fdisk -l /dev/vdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/vdb: 3298.5 GB, 3298534883328 bytes, 6442450944 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: gpt
# Start End Size Type Name
1 2048 6442448895 3T Microsoft basic ?
[root@bigdata1 ~]#
[root@bigdata1 ~]# df -T /dev/vdb1
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/vdb1 xfs 3219650564 32944 3219617620 1% /data
[root@bigdata1 ~]#

这时我们就可以在 Centos 7.3(默认为ext4)上使用大磁盘了(超过2TB)

参考:https://help.aliyun.com/document_detail/34377.html


本文出自”Jack Wang Blog”:http://www.yfshare.vip/2017/07/15/怎么在Linux划分大磁盘分区/