咨询热线:4006-75-4006
售前:9:00-23:30 备案:9:00-18:00 技术:7*24h
MBR分区扩容——以ext4文件系统为例
欢迎来到蓝队云技术小课堂,每天分享一个技术小知识。今天分享的是如何对服务器分区扩容,以下将以MBR分区、ext4文件系统为例演示
扩容已有MBR分区
fdisk命令主要用于 MBR分区表的操作
MBR:MBR 分区表支持最多四个主分区,其中一个可以是扩展分区,该扩展分区可以包含多个逻辑分区。由于 MBR 使用32位的扇区偏移值来寻址,因此 MBR 分区表的最大容量为2 TB
(1)分区后扩容
/dev/sdb有10G,只有一个分区/dev/sdb1。将其扩大至20G,将新增的10G划分至已有的/dev/sdb1内
ext为例
[root@localhost ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 8.9M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 36G 4.9G 31G 14% /
/dev/sda1 xfs 1014M 150M 865M 15% /boot
tmpfs tmpfs 379M 0 379M 0% /run/user/0
/dev/sdb1 ext4 9.8G 37M 9.2G 1% /www
执行以下命令,安装growpart扩容工具
yum install cloud-utils-growpart -y
#如果数据盘扩容后容量大小未变执行此命令让内核扫描并重新识别连接到sdb磁盘的所有磁盘驱动器
echo 1 > /sys/block/sdb/device/rescan
[root@localhost ~]# growpart /dev/sdb 1
CHANGED: partition=1 start=2048 old: size=20969472 end=20971520 new: size=41940959 end=41943007
[root@localhost ~]# resize2fs /dev/sdb1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/sdb1 is mounted on /data; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/sdb1 is now 5242619 blocks long.
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 12M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 53G 3.2G 50G 6% /
/dev/sda1 xfs 797M 151M 647M 19% /boot
tmpfs tmpfs 378M 0 378M 0% /run/user/0
/dev/sdb1 ext4 20G 44M 19G 1% /data
如果不使用growpart命令 手动扩容如下
[root@itgank ~]# 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): p #查看分区
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x2e714d05
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20971519 10484736 83 Linux
Command (m for help): d #删除当前1分区 切记不要w保存退出 会造成数据丢失
Selected partition 1
Partition 1 is deleted
Command (m for help): n #选择分区类型
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): 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):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x2e714d05
Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 83 Linux
Command (m for help): w #以上操作保存退出 如果中途命令输入错误 ctrl+c回退所有命令 重头再开始
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@itgank ~]# partprobe
[root@itgank ~]# resize2fs /dev/sdb1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/sdb1 is mounted on /data; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/sdb1 is now 5242624 blocks long.
[root@itgank ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 12M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 53G 3.2G 50G 6% /
/dev/sda1 xfs 797M 151M 647M 19% /boot
tmpfs tmpfs 378M 0 378M 0% /run/user/0
/dev/sdb1 ext4 20G 44M 19G 1% /data
蓝队云官网上拥有完善的技术支持库可供参考,大家可自行查阅,更多技术问题,可以直接咨询。同时,蓝队云整理了运维必备的工具包免费分享给大家使用,需要的朋友可以直接咨询。
更多技术知识,蓝队云期待与你一起探索。