大网数据广告活动
服务器运维问答

Extend linux partition size without losing any data / techniques

· 52CE 我爱测

I bought a 200G additional disk for my OVH cloud server because my initial disk was full. Now, my additional disk is almost full (as you can see below). So I added 200 extra more G in it. As you can see, sdb's size is now 400G. S…

问题原文

原帖链接 · Kingourou · CC BY-SA 4.0

I bought a 200G additional disk for my OVH cloud server because my initial disk was full.

Now, my additional disk is almost full (as you can see below). So I added 200 extra more G in it. As you can see, sdb's size is now 400G.

So, how can I add the 200Gb in the sdb1 (edit : FS ext4) linux partition without losing the current data in it?

When I run :

lsblk

I get :

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   200G  0 disk 
└─sda1   8:1    0   200G  0 part /
sdb      8:16   0   400G  0 disk 
└─sdb1   8:17   0 199.5G  0 part /mnt

已采纳解答

原帖链接 · Nikita Kipriyanov · CC BY-SA 4.0

Removing or creating a partition doesn't remove a data or a filesystem on a disk. It will only update the MBR or GPT information where partition lies and its size.

Also, if the filesystem finds itself on the device which is larger than that is stored in its superblock, it will just work as if that was small device.

Based on this knowledge, you can deduce the extension process. It is as follows:

  1. On a running system, run fdisk and carefully observe where the partition starts (p). Then remove it (d), and create (n) larger one on its place. Modern fdisk could ask about wiping signatures, if it will, say "no" (this is essential)! Pay special attention on its start, it must begin at exact same sector, but could have larger size. Exit fdisk writing changes (w).

Filesystem could be left mounted. That will not broke access to data. In fact, kernel will refuse to reload partition table, because the old parition was in use, and it will use old parition mapping. To update a partition mapping in the kernel, you can simply reboot, or use kpartx or partprobe program in case service interruption is infeasible.

Of course, you could have unmount filesystem in beforehand and remount after partition recreation, then kernel would not be blocked and partition mapping will be updated right after exit from fdisk.

  1. Resize a file system. Ext4 can be resized online (just resize2fs /dev/sdb1, it will detect mounted filesystem and run online resize). Or you can again do this while it is unmounted, if you wish.

Of course, this is still dangerous process. Have backups somewhere.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-12-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。