MBR分區(qū)擴(kuò)容——以ext4文件系統(tǒng)為例
歡迎來(lái)到藍(lán)隊(duì)云技術(shù)小課堂,每天分享一個(gè)技術(shù)小知識(shí)。今天分享的是如何對(duì)服務(wù)器分區(qū)擴(kuò)容,以下將以MBR分區(qū)、ext4文件系統(tǒng)為例演示
擴(kuò)容已有MBR分區(qū)
fdisk命令主要用于 MBR分區(qū)表的操作
(1)分區(qū)后擴(kuò)容
/dev/sdb有10G,只有一個(gè)分區(qū)/dev/sdb1。將其擴(kuò)大至20G,將新增的10G劃分至已有的/dev/sdb1內(nèi)
ext為例
[root@localhost ~]# df -Th
文件系統(tǒng) 類型 容量 已用 可用 已用% 掛載點(diǎn)
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
執(zhí)行以下命令,安裝growpart擴(kuò)容工具
yum install cloud-utils-growpart -y
#如果數(shù)據(jù)盤擴(kuò)容后容量大小未變執(zhí)行此命令讓內(nèi)核掃描并重新識(shí)別連接到sdb磁盤的所有磁盤驅(qū)動(dòng)器
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命令 手動(dòng)擴(kuò)容如下
[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 #查看分區(qū)
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 #刪除當(dāng)前1分區(qū) 切記不要w保存退出 會(huì)造成數(shù)據(jù)丟失
Selected partition 1
Partition 1 is deleted
Command (m for help): n #選擇分區(qū)類型
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p #選擇主分區(qū)
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 #以上操作保存退出 如果中途命令輸入錯(cuò)誤 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
藍(lán)隊(duì)云官網(wǎng)上擁有完善的技術(shù)支持庫(kù)可供參考,大家可自行查閱,更多技術(shù)問(wèn)題,可以直接咨詢。同時(shí),藍(lán)隊(duì)云整理了運(yùn)維必備的工具包免費(fèi)分享給大家使用,需要的朋友可以直接咨詢。
更多技術(shù)知識(shí),藍(lán)隊(duì)云期待與你一起探索。