小于2TB的磁盘用fdisk命令;大于2TB的磁盘用parted命令,且转换磁盘的GPT格式
一.fdisk命令分区(mbr)
将sdb硬盘分区(20G)
- 1个主分区 (2G)
- 1个扩展分区 (剩下的全给他) 18G
- 2个逻辑分区
- 逻辑分区1,10G
- 逻辑分区2,剩下的都给他 8G
[root@localhost ~]# fdisk /dev/sdb
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +2G
Partition 1 of type Linux and of size 2 GiB is set
###
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): e
Partition number (2-4, default 2):
First sector (4196352-41943039, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-41943039, default 41943039):
Using default value 41943039
Partition 2 of type Extended and of size 18 GiB is set
###
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (4198400-41943039, default 4198400):
Using default value 4198400
Last sector, +sectors or +size{K,M,G} (4198400-41943039, default 41943039): +10G
Partition 5 of type Linux and of size 10 GiB is set
###
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (25171968-41943039, default 25171968):
Using default value 25171968
Last sector, +sectors or +size{K,M,G} (25171968-41943039, default 41943039):
Using default value 41943039
Partition 6 of type Linux and of size 8 GiB is set
###
w write table to disk and exit
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
最终看到的分区应该是
[root@localhost ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb5 /dev/sdb6
1.partx刷新分区
[root@localhost ~]# partx /dev/sdb
NR START END SECTORS SIZE NAME UUID
1 2048 4196351 4194304 2G
2 4196352 41943039 37746688 18G
5 4198400 25169919 20971520 10G
6 25171968 41943039 16771072 8G
最后看到的结果应该是这样的
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 2G 0 part
├─sdb2 8:18 0 1K 0 part
├─sdb5 8:21 0 10G 0 part
└─sdb6 8:22 0 8G 0 part
sr0 11:0 1 4.4G 0 rom
2.查看磁盘的分区表类型
看到dos就是mbr类型
fdisk -l
二.parted命令分区为GPT类型(GUID类型)
1.删除/dev/sdb分区的信息
fdisk /dev/sdb
使用d指令,删除原有所有的mbr分区表下的分区信息
[root@localhost ~]# fdisk /dev/sdb
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.
Command (m for help): d
Partition number (1,2,5,6, default 6):
Partition 6 is deleted
Command (m for help): d
Partition number (1,2,5, default 5):
Partition 5 is deleted
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 is deleted
Command (m for help): d
Selected partition 1
Partition 1 is deleted
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
看到已经复原
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
sr0 11:0 1 4.4G 0 rom
2.parted命令
使用parted命令,可以修改硬盘的分区表类型
ms-doc 这是mbr类型的名字
gpt 这是GUID分区表的类型名字
parted /dev/sdb
[root@localhost ~]# parted /dev/sdb
修改当前硬盘的分区表类型,改为gpt,注意如下操作会摧毁原有的数据
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted)
使用print指令,查看分区表信息,以及分区表类型
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
退出
(parted) quit
Information: You may need to update /etc/fstab.
这时候查看已经是GPT模式了
3.gdisk命令
因为parted没有太多交互式的提醒,不用它进行分区了,换为gdisk命令去操作超过2TB的硬盘分区动作
1.需要额外安装操作
yum install gdisk -y
[root@localhost ~]# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-41943006, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}: 10G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): n
Partition number (2-128, default 2): 2
First sector (34-41943006, default = 20973568) or {+-}size{KMGTP服务器托管网}:
Last sector (20973568-41943006, default = 41943006) or {+-}size{KMGTP}: +5G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): BD470BF9-F4D6-4808-8A94-F0E79FCE9EBA
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 10487740 sectors (5.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 20971520 10.0 GiB 8300 Linux filesystem
2 20973568 31459327 5.0 GiB 8300 Linux filesystem
Command (? for help): n
Partition number (3-128, default 3):
First sector (34-41943006, default = 31459328) or {+-}size{KMGTP}:
Last sector (31459328-41943006, default = 41943006) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 10G 0 part
├─sdb2 8:18 0 5G 0 part
└─sdb3 8:19 0 5G 0 part
sr0 11:0 1 4.4G 0 rom
三.文件系统类型
四.mkfs格式化文件系统与挂载
1.使用mkfs命令可以进行分区,文件系统格式化
给这个分区,分别格式化xfs文件系统
[root@localhost ~]# mkf
mkfifo mkfs mkfs.btrfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs
[root@localhost ~]# mkfs.xfs /dev/sdc1
meta-data=/dev/sdc1 isize=512 agcount=4, agsize=1310656 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5242624, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
2.挂载一个目录,到这个分区,即可使用该分区,存储数据了
查看挂载情况mount -l
[root@localhost ~]# mkdir /opt/my_sdc
[root@localhost ~]# mount /dev/sdc1 /opt/my_sdc/
[root@localhost ~]# mount -l|grep sdc1
/dev/sdc1 on /opt/my_sdc type xfs (rw,relatime,attr2,inode64,noquota)
3.设置永久挂载
上述的mount挂载命令是临时生效,需要开机就让系统自动挂载,方可实现永久生效
编辑 /etc/fstab文件即可
[root@localhost ~]# tail -1 /etc/fstab
/dev/sdc1 /opt/my_sdc xfs defaults 0 0
重启机器,查看是否开机就能自动挂载,读取到/dev/sdc1磁盘服务器托管网的数据 ,再次使用mount -l |grep sdc 查看磁盘的挂载情况 ,以及去访问挂载点,是否能读到分区的数据
[root@localhost ~]# mount -l|grep sdc
/dev/sdc1 on /opt/my_sdc type xfs (rw,relatime,attr2,inode64,noquota)
4.取消挂载
取消挂载注意:该挂载点无人使用才可以取消挂载
umount 挂载点
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
相关推荐: 【Redis】Redis性能优化:理解与使用Redis Pipeline
原创不易,注重版权。转载请注明原作者和原文链接 文章目录 Pipeline介绍 原生批命令(MSET, MGET) VS Pipeline Pipeline的优缺点 一些疑问 Pipeline代码实现 当我们谈论Redis数据处理和存储的优化方法时,「 Red…