Linux Study之--Linux下使用PARTED对大于2T磁盘分区
在生产环境中,我们会遇到分区大于2T的磁盘(比如:添加一个10TB的存储),由于MBR分区表只支持2T磁盘,所以大于2T的磁盘必须使用GPT分区表,而我们在做raid时会划分多个VD来进行装系统,但系统安装完后无法将磁盘全部识别出来,这时就需要手动对GPT分区进行挂载,那么如何在linux中对大于2T的磁盘进行挂载?
注意:
GPT格式的磁盘相当于原来MBR磁盘中原来保留4个partition table的4*16个字节,只留第一个16个字节,类似于扩展分区,真正的partition table在512字节之后,GPT磁盘没有四个主分区的限制。
而fdisk是不支持GPT分区的,我们可以使用parted来对GPT磁盘操作。parted功能很强大,既可用命令行也可以用于交互式,在提示符下输入parted就会进入交互式模式,如果有多个磁盘的话,我们需要运行select sdX(X为磁盘)来进行磁盘的选择,也可直接用parted /dev/sdX指定相应的硬盘。
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
|
parted 工具使用:
[root@RH6 ~]# parted /dev/sdc
GNU Parted
2.1
Using /dev/sdc
Welcome to GNU Parted! Type
'help'
to view a list of commands.
(parted) help
align-check TYPE N check partition N
for
TYPE(min|opt) alignment
check NUMBER do a simple check
on
the file system
cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition
help [COMMAND] print general help,
or
help
on
COMMAND
mklabel,mktable LABEL-TYPE create a
new
disklabel (partition table)
mkfs NUMBER FS-TYPE make a FS-TYPE file system
on
partition NUMBER
mkpart PART-TYPE [FS-TYPE] START END make a partition
mkpartfs PART-TYPE FS-TYPE START END make a partition
with
a file system
move NUMBER START END move partition NUMBER
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
resize NUMBER START END resize partition NUMBER
and
its file system
rm NUMBER
delete
partition NUMBER
select DEVICE choose the device to edit
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
|
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@server ~]# fdisk -l
Disk /dev/sda:
21.4
GB,
21474836480
bytes
255
heads,
63
sectors/track,
2610
cylinders Units = cylinders of
16065
*
512
=
8225280
bytes
Device Boot Start End Blocks Id System
/dev/sda1 *
1
16
128488
+
83
Linux
/dev/sda2
17
49
265072
+
82
Linux swap / Solaris
/dev/sda3
50
2610
20571232
+
83
Linux
Disk /dev/sdb:
2190.4
GB,
2190433320960
bytes
255
heads,
63
sectors/track,
266305
cylinders Units = cylinders of
16065
*
512
=
8225280
bytes
Disk /dev/sdb doesn't contain a valid partition table
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
[root@server ~]# parted
GNU Parted
1.8.
1
Using /dev/sda Welcome to GNU Parted! Type
'help'
to view a list of commands.
(parted)
select /dev/sdb
//选择磁盘sdb
Using /dev/sdb
(parted) mklabel gpt
//将MBR磁盘格式化为GPT
(parted) mkpart primary
0
-1
//将整块磁盘分成一个分区
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 2190GB Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number
Start End Size File system Name Flags
1
17.
4kB 2190GB 2190GB primary
(parted) quit
Information: Don't forget to update /etc/fstab,
if
necessary.
|
PS:在Linux系统中挂载SCSI盘阵,且分区大小超过2TB时,无法使用mk2fs命令进行格式化,而在使用mkfs.ext3命令格式化时,需要增加-T largefile参数,否则格式化过程将非常缓慢,对于添加一个10TB的存储,如果linux下直接格式化是一个很漫长的过程,10TB,估计少了30小时是完不成的。
[root@server ~]# mkfs.ext3 -T largefile /dev/sdb1
[root@server ~]# e2label /dev/sdb1 /data1 //对/dev/sdb1添加(修改)标签为/data1
[root@server ~]# e2label /dev/sdb1 //查看分区的标签
/data1
[root@server ~]# mkdir /data1 //在/分区下创建一个配额的挂载点
[root@server ~]# mount /dev/sdb1 /data1 //对该分区进行手动挂载
这样分区完成并挂载成功,用df –h就可以看到该磁盘的大小
[root@server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 20G 3.9G 15G 22% /
/dev/sda1 122M 12M 104M 10% /boot
tmpfs 62M 0 62M 0% /dev/shm
/dev/sdb1 2.0T 199M 1.9T 1% /data1
最后只需在fstab中添加如下一行,就能完成分区的自动挂载
[root@server ~]# vi /etc/fstab
/dev/sdb1 /data1 ext3 defaults 0 0
案例分析:
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
[root@RH6 ~]# fdisk -l
Disk /dev/sdd doesn't contain a valid partition table
Disk /dev/dm
-0
:
30.1
GB,
30098325504
bytes
255
heads,
63
sectors/track,
3659
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:
0x00000000
对磁盘分区:
[root@RH6 ~]# parted /dev/sdd
GNU Parted
2.1
Using /dev/sdd
Welcome to GNU Parted! Type
'help'
to view a list of commands.
(parted) help
align-check TYPE N check partition N
for
TYPE(min|opt) alignment
check NUMBER do a simple check
on
the file system
cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition
help [COMMAND] print general help,
or
help
on
COMMAND
mklabel,mktable LABEL-TYPE create a
new
disklabel (partition table)
mkfs NUMBER FS-TYPE make a FS-TYPE file system
on
partition NUMBER
mkpart PART-TYPE [FS-TYPE] START END make a partition
mkpartfs PART-TYPE FS-TYPE START END make a partition
with
a file system
move NUMBER START END move partition NUMBER
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
resize NUMBER START END resize partition NUMBER
and
its file system
rm NUMBER
delete
partition NUMBER
select DEVICE choose the device to edit
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) select
New device? [/dev/sdd]?
Using /dev/sdd
(parted) mklabel gpt
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdd:
21.
5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number
Start End Size File system Name Flags
(parted) mkpart primary
0
10240
//建立从0M开始的10g的分区
Warning: The resulting partition is
not
properly aligned
for
best performance.
Ignore/Cancel? i
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdd:
21.
5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number
Start End Size File system Name Flags
1
17.
4kB
10.
2GB
10.
2GB primary
(parted) mkpart primary
10240
-1
//建立从10g开始,剩下所有的空间都建立分区
(parted) p
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdd:
21.
5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number
Start End Size File system Name Flags
1
17.
4kB
10.
2GB
10.
2GB primary
2
10.
2GB
21.
5GB
11.
2GB primary
(parted) quit
Information: You may need to update /etc/fstab.
对分区进行格式化:
[root@RH6 ~]# mkfs.ext3 -T largefile /dev/sdd1
mke2fs
1.41.
12
(
17
-May
-2010
)
Filesystem label=
OS type: Linux
Block size=
4096
(log=
2
)
Fragment size=
4096
(log=
2
)
Stride=
0
blocks, Stripe width=
0
blocks
9856
inodes,
2499995
blocks
124999
blocks (
5.00
%) reserved
for
the
super
user
First data block=
0
Maximum filesystem blocks=
2562719744
77
block groups
32768
blocks per group,
32768
fragments per group
128
inodes per group
Superblock backups stored
on
blocks:
32768
,
98304
,
163840
,
229376
,
294912
,
819200
,
884736
,
1605632
Writing inode tables: done
Creating journal (
32768
blocks): done
Writing superblocks
and
filesystem accounting information: done
This filesystem will be automatically checked every
31
mounts
or
180
days, whichever comes
first
. Use tune2fs -c
or
-i to
override
.
[root@RH6 ~]# mkfs.ext3 -T largefile /dev/sdd2
mke2fs
1.41.
12
(
17
-May
-2010
)
Filesystem label=
OS type: Linux
Block size=
4096
(log=
2
)
Fragment size=
4096
(log=
2
)
Stride=
0
blocks, Stripe width=
0
blocks
10752
inodes,
2742528
blocks
137126
blocks (
5.00
%) reserved
for
the
super
user
First data block=
0
Maximum filesystem blocks=
2810183680
84
block groups
32768
blocks per group,
32768
fragments per group
128
inodes per group
Superblock backups stored
on
blocks:
32768
,
98304
,
163840
,
229376
,
294912
,
819200
,
884736
,
1605632
,
2654208
Writing inode tables: done
Creating journal (
32768
blocks): done
Writing superblocks
and
filesystem accounting information: done
This filesystem will be automatically checked every
32
mounts
or
180
days, whichever comes
first
. Use tune2fs -c
or
-i to
override
.
mount分区:
[root@RH6 ~]# mkdir /gpt1 /gpt2
[root@RH6 ~]# mount /dev/sdd1 /gpt1
[root@RH6 ~]# mount /dev/sdd2 /gpt2
[root@RH6 ~]# df -h
Filesystem Size Used Avail Use% Mounted
on
/dev/mapper/vg_rh6-lv_root
28G 20G
6.
5G
76
% /
tmpfs 590M 88K 590M
1
% /dev/shm
/dev/sda1 485M 28M 432M
7
% /boot
/dev/mapper/oravg-lv_data1
9.
9G
2.
9G
6.
5G
31
% /dsk1
/dev/mapper/oravg-lv_data2
9.
9G 312M
9.
1G
4
% /dsk2
/dev/mapper/oravg-lv_data3
9.
9G 151M
9.
2G
2
% /dsk3
/dev/mapper/oravg-lv_data4
11G
3.
0G
6.
8G
31
% /dsk4
/dev/mapper/datavg-lv_dat1
9.
9G 151M
9.
2G
2
% /dsk5
/dev/mapper/datavg-lv_dat2
7.
9G 146M
7.
4G
2
% /dsk6
/dev/sdd1
9.
6G 150M
9.
0G
2
% /gpt1
/dev/sdd2 11G 155M
9.
8G
2
% /gpt2
[root@RH6 ~]#
|