4

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.

My issue : how to add the 200Gb in the sdb1 (edit : FS ext4) linux partition without losing the current data in it ? Do you have a tutorial which fits my case ?

When I run :

lsblk

I'm getting :

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

Thank you a lot for the help.

Cheers.

Kingourou
  • 53
  • 1
  • 1
  • 4

2 Answers2

8

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.

Nikita Kipriyanov
  • 8,033
  • 1
  • 21
  • 39
  • Thank you, that solved my issue ! – Kingourou Dec 06 '19 at 09:31
  • more detailed explanation here: https://docs.hytrust.com/DataControl/Admin_Guide-4.0/Content/Books/Admin-Guide/VM-Disk-Management/Expanding-a-Linux-Data-Partition.htm IMPORTANT: you need to match the same START sector as well as partition UNIQUE GUID. That way LVM will see the partition the same as before, just bigger. – Mladen B. Mar 04 '21 at 14:10
0

I would implement LVM. Although, this does destroy data temporarily.

  1. Backup the volume.
  2. Delete partition sdb1
  3. vgcreate vg /dev/sdb
  4. lvcreate --name lv vg
  5. Create and mount a file system on /dev/vg/lv
  6. Restore data to the mounted volume.

What you gain is LVM features, including the ability to increase the volume without partitioning. pvextend /dev/sdb then lvextend.

John Mahowald
  • 30,009
  • 1
  • 17
  • 32