Data Disk - Create New Partition and Merge to /

This tutorial is about how to create partition on data disk and merge it with OS disk to extend the size of /.

We will make the disk structure to:

/dev/vda – os disk
— /dev/vda1 – /boot
— /dev/vda2 – LVM (/ included)
/dev/vdb – data disk
— /dev/vdb1 – LVM (extend to /)
/dev/vdc – initialization file

Warning: Reinstallation will destroy the data!

Please remove the partition before reinstalling OS. (Run fdisk /dev/vdb and type d)


1. Update and install related software

Debian & Ubuntu:

apt-get update
apt-get -y install kpartx lvm2

CentOS & Fedora:

yum -y install kpartx lvm2

2. Create partition

fdisk /dev/vdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x1ea1ca70.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won’t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n #type n to create new partition
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): #type p, or press Enter, to create primary partition (max 4)
Using default response p
Partition number (1-4, default 1): #press Enter
Using default value 1
First sector (2048-67108863, default 2048): #press Enter
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-67108863, default 67108863): #press Enter or use customized size
Using default value 67108863

Command (m for help): #type t, to change partition type
Selected partition 1 #it will be automatically selected if there is only 1 partition, otherwise you need to type it manually
Hex code (type L to list codes): 8e #type 8e (Linux LVM)
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): #type w, to save. Warning: type q to quit if there is something wrong.
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

3. Create PV

pvcreate -yff /dev/vdb1

4. Extend new PV to /

Get the existed VG Name:

VGNAME=`vgdisplay | grep "VG Name" | awk '{print $3}'`

Extend / with /dev/vdb1:

vgextend $VGNAME /dev/vdb1

5. Resize /

5.1. Check free PE Size

PESIZE=`vgdisplay $VGNAME | grep "Free  PE / Size" | awk '{print $5}'`

5.2. Check the location of /

df / | egrep "^/dev" | awk '{print $1}'

Please copy the output, this will be the location of /. It is /dev/mapper/debian-root in this tutorial.

5.3. Resize the LV where / located [1]

lvresize -l +$PESIZE  /dev/mapper/debian-root 

5.4. Resize the partition where / located

resize2fs /dev/mapper/debian-root

Please wait since it may take several minutes. [2]

6. Validation

df -h


You will see the new size of your disk. Example output:

Filesystem Size Used Avail Use% Mounted on
rootfs 54G 807M 51G 2% /
udev 10M 0 10M 0% /dev
tmpfs 101M 224K 101M 1% /run
/dev/mapper/debian-root 54G 807M 51G 2% /
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 201M 0 201M 0% /run/shm
/dev/vda1 472M 28M 420M 7% /boot

Possible errors
[1]

Path required for Logical Volume "dm-0"
Please provide a volume group name
Run `lvresize --help' for more information.

1.1. Find the real path of "dm-0":

dmsetup ls --tree

Example Output:

debian--vg-root (253:0)
├─ (254:17)
└─ (254:5)
debian--vg-swap_1 (253:1)
└─ (254:5)

1.2. Then re-run the command:

lvresize -l +$PESIZE /dev/mapper/debian--vg-root


[2]

resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.

2.1. try the following command

fsadm resize /dev/mapper/debian-root
  • 154 utilizatori au considerat informația utilă
Răspunsul a fost util?

Articole similare

How to install OS via ISO on KVM VPS

When you ordered a KVM VPS from us, you will have access to our KVM control panel. The buttons...

How to use Data Disk

StarryDNS offers KVM VPS with disk structure as follows: /dev/vda – os disk — /dev/vda1 – /boot...

Data Disk - Create New Partition and Mount to /home

This tutorial will help you create new partition on data disk and mount it to /home in our KVM...

Data Disk - Use Data Disk as SWAP

This tutorial helps you create swap in data disk. We will make disk structure to: /dev/vda – os...

Operating System Templates and ISOs

KVM VPS Templates: Debian 12 x64 Debian 11 x64 Ubuntu 22.04 x64 Ubuntu 20.04 x64 AlmaLinux...