This tutorial will help you create new partition on data disk and mount it to /home in our KVM VPS.
We will make the disk structure to
/dev/vda – os disk
— /dev/vda1 – /boot
— /dev/vda2 – LVM (/ included)
/dev/vdb – data disk
— /dev/vdb1 – /home
/dev/vdc – initialization file
In this structure, data in data disk will not be destroyed if OS is re-installed. Please scroll down to read what you should do after reinstallation.
For New Installation
Warning: this will cause all data lost in /dev/vdb, make sure you are operating a new VPS. Please scroll down if you would like to know how to mount it after re-installation.
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. Clean partition table of /dev/vdb
kpartx -d /dev/vdb dd if=/dev/zero of=/dev/vdb bs=512 count=1
3. Create new partition in /dev/vdb
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): #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): t #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): 83 #type 83 (Linux partition)
Changed system type of partition 1 to 83 (Linux)
Command (m for help): w #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.
4. Format the partition to ext4, change it if you prefer other formats.
mkfs.ext4 /dev/vdb1
5. Edit fstab
echo "/dev/vdb1 /home ext4 defaults 0 1" >> /etc/fstab
6. Mount the partition
mount -a
7. Validation
df -h
You will see new mouting point /home
Filesystem Size Used Avail Use% Mounted on
rootfs 4.5G 801M 3.5G 19% /
udev 10M 0 10M 0% /dev
tmpfs 101M 224K 101M 1% /run
/dev/mapper/debian-root 4.5G 801M 3.5G 19% /
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 201M 0 201M 0% /run/shm
/dev/vda1 472M 28M 420M 7% /boot
/dev/vdb1 50G 180M 47G 1% /home
What you should do after reinstallation
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. Edit fstab
echo "/dev/vdb1 /home ext4 defaults 0 1" >> /etc/fstab
3. Mount the partition
mount -a
4. Validation
df -h
You will see mouting point /home
Filesystem Size Used Avail Use% Mounted on
rootfs 4.5G 801M 3.5G 19% /
udev 10M 0 10M 0% /dev
tmpfs 101M 224K 101M 1% /run
/dev/mapper/debian-root 4.5G 801M 3.5G 19% /
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 201M 0 201M 0% /run/shm
/dev/vda1 472M 28M 420M 7% /boot
/dev/vdb1 50G 180M 47G 1% /home
Feel free to contact us if you have any questions