5

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
4
  • What FS is used for sdb1? ext4 or xfs? Dec 5, 2019 at 13:17
  • Hey, it's an ext4
    – Kingourou
    Dec 5, 2019 at 13:53
  • Your best bet would be to backup, re-format, and restore the data. If that is not possible, you might be able to re-arrange things in your filesystem and mount sdb somewhere that works out.
    – Bert
    Dec 5, 2019 at 14:05
  • check this serverfault.com/questions/509468/… Dec 5, 2019 at 16:19

2 Answers 2

9

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.

1
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .