MBR 分区表和 GPT 分区表的区别:
创建步骤:
服务器上有一块 3 TB 的硬盘,位于 /dev/sdb ,现打算在这块 3 TB 的硬盘上分出一个 3 TB 大小的分区。
1 、当前服务器的操作系统版本为:
[root@host ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) [root@host ~]#
2 、安装 gdisk :
[root@host ~]# yum -y install gdisk
3 、umount 挂载点(如果 3 TB 的硬盘已经有分区,而且分区 mount 到了某个目录,那么才需要 umount 掉,这里以 mount 到了 /www 目录为例):
这里需要注意的是卸载前请先关闭运行在 /www 里的所有程序,否则会报以下错误:
[root@host ~]# umount /www umount: /www: target is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1)) [root@host ~]#
可使用 lsof 命令来查看当前有哪些程序正在使用 /www 这个目录:
[root@host ~]# lsof | grep www nginx 25245 root cwd DIR 8,2 4096 134852 /www/www.test.com/file nginx 25245 root 15w REG 8,2 22029 399660 /www/accesslog/access.log nginx 25532 nobody cwd DIR 8,2 4096 134852 /www/www.test.com/file nginx 25532 nobody 15w REG 8,2 22029 399660 /www/accesslog/access.log nginx 25533 nobody cwd DIR 8,2 4096 134852 /www/www.test.com/file nginx 25533 nobody 15w REG 8,2 22029 399660 /www/accesslog/access.log nginx 25534 nobody cwd DIR 8,2 4096 134852 /www/www.test.com/file nginx 25534 nobody 15w REG 8,2 22029 399660 /www/accesslog/access.log nginx 25535 nobody cwd DIR 8,2 4096 134852 /www/www.test.com/file nginx 25535 nobody 15w REG 8,2 22029 399660 /www/accesslog/access.log bash 26812 root cwd DIR 8,2 4096 131775 /www lsof 26827 root cwd DIR 8,2 4096 131775 /www grep 26828 root cwd DIR 8,2 4096 131775 /www lsof 26829 root cwd DIR 8,2 4096 131775 /www [root@host ~]#
卸载成功是没有提示的:
[root@host ~]# umount /www [root@host ~]#
4 、使用 gdisk 命令创建分区:
[root@host ~]# gdisk /dev/sdb GPT fdisk (gdisk) version 0.8.6 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Command (? for help): ? b back up GPT data to a file c change a partition's name d delete a partition i show detailed information on a partition l list known partition types n add a new partition o create a new empty GUID partition table (GPT) p print the partition table q quit without saving changes r recovery and transformation options (experts only) s sort partitions t change a partition's type code v verify disk w write table to disk and exit x extra functionality (experts only) ? print this menu Command (? for help): o This option deletes all partitions and creates a new protective MBR. Proceed? (Y/N): Y Command (? for help): p Disk /dev/sdb: 5857345536 sectors, 2.7 TiB Logical sector size: 512 bytes Disk identifier (GUID): 66EDFDC8-D796-4790-9EDB-8FF0C6E9532D Partition table holds up to 128 entries First usable sector is 34, last usable sector is 5857345502 Partitions will be aligned on 2048-sector boundaries Total free space is 5857345469 sectors (2.7 TiB) Number Start (sector) End (sector) Size Code Name Command (? for help): n Partition number (1-128, default 1): First sector (34-5857345502, default = 2048) or {+-}size{KMGTP}: Last sector (2048-5857345502, default = 5857345502) 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): p Disk /dev/sdb: 5857345536 sectors, 2.7 TiB Logical sector size: 512 bytes Disk identifier (GUID): 66EDFDC8-D796-4790-9EDB-8FF0C6E9532D Partition table holds up to 128 entries First usable sector is 34, last usable sector is 5857345502 Partitions will be aligned on 2048-sector boundaries Total free space is 2014 sectors (1007.0 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 5857345502 2.7 TiB 8300 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. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot. The operation has completed successfully. [root@host ~]#
5 、分区后用 partprobe -s 命令更新 kernel 分区表:
[root@host ~]# partprobe -s /dev/sda: msdos partitions 1 2 3 4 <5 6> /dev/sdb: gpt partitions 1 [root@host ~]#
6 、命令 parted /dev/xxx print 可查看分区表类型:
[root@host ~]# parted /dev/sdb print
Model: Dell VIRTUAL DISK (scsi)
Disk /dev/sdb: 2999GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2999GB 2999GB xfs Linux filesystem
[root@host ~]#
7 、重新格式化分区和重新挂载分区:
[root@host ~]# umount /www [root@host ~]# [root@host ~]# mkfs.xfs /dev/sdb1 -f meta-data=/dev/sdb1 isize=512 agcount=4, agsize=183041983 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=732167931, imaxpct=5 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=357503, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@host ~]# [root@host ~]# mount /dev/sdb1 /www
8 、使用 df -h 命令可以查看到这个分区了:
[root@host ~]# df -h | grep www /dev/sdb1 2.8T 33M 2.8T 1% /www [root@host ~]#
9、此时可能还需要修改 /etc/fstab 文件,这样下次开机时 CentOS Linux 才能自动地将相应的分区挂载到对应的目录:
( 1 )先查看分区 /dev/sdb1 的 UUID :
[root@host ~]# blkid /dev/sdb1
/dev/sdb1: UUID="1ea02da5-xxxx-xxxx-xxxx-xxxx28d304d3" TYPE="xfs" PARTLABEL="Linux filesystem" PARTUUID="4544d025-YYYY-YYYY-YYYY-YYYYa9a21a1a"
[root@host ~]#
记录下这个值:1ea02da5-xxxx-xxxx-xxxx-xxxx28d304d3
( 2 )在命令行界面输入:
[root@host ~]# vi /etc/fstab # # /etc/fstab # Created by anaconda on Wed Apr 4 13:57:00 2018 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=63be06ea-zzzz-zzzz-zzzz-zzzzb42001a1 / xfs defaults 0 0 UUID=d6a35b10-zzzz-zzzz-zzzz-zzzza170bbc0 /boot xfs defaults 0 0 UUID=6782acf9-yyyy-yyyy-yyyy-yyyy27aaec82 /www xfs defaults 0 0 UUID=f1f7ae41-zzzz-zzzz-zzzz-zzzz82dbcc1b swap swap defaults 0 0
键入小写字母 i ,进入编辑模式,再将文件改成如下的格式:
[root@host ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Apr 4 13:57:00 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=63be06ea-zzzz-zzzz-zzzz-zzzzb42001a1 / xfs defaults 0 0
UUID=d6a35b10-zzzz-zzzz-zzzz-zzzza170bbc0 /boot xfs defaults 0 0
UUID=1ea02da5-xxxx-xxxx-xxxx-xxxx28d304d3 /www xfs defaults 0 0
UUID=f1f7ae41-zzzz-zzzz-zzzz-zzzz82dbcc1b swap swap defaults 0 0
按一次 ESC 键退出编辑模式,然后键入 “ :wq ” 保存并退出。
重启服务器后也是没有问题的(如果不方便可以暂时不用重启服务器)。
发表评论?