久久青草精品A片狠狠,日韩欧美视频一区二区,亚洲国码AV日韩,国产精品黄在

幫助中心 >  技術知識庫 >  云服務器 >  服務器教程 >  MBR分區擴容——以ext4文件系統為例

MBR分區擴容——以ext4文件系統為例

2024-11-20 15:42:25 4230

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

 

藍隊云官網上擁有完善的技術支持庫可供參考,大家可自行查閱,更多技術問題,可以直接咨詢。同時,藍隊云整理了運維必備的工具包免費分享給大家使用,需要的朋友可以直接咨詢。

更多技術知識,藍隊云期待與你一起探索。

 


提交成功!非常感謝您的反饋,我們會繼續努力做到更好!

這條文檔是否有幫助解決問題?

非常抱歉未能幫助到您。為了給您提供更好的服務,我們很需要您進一步的反饋信息:

在文檔使用中是否遇到以下問題: