Change an LVM partition to a RAID partition

Home > Search
  by

In this tutorial, we use an example where one solid state drive (SSD) and two hard disk drives (HDD) are connected to the computer, where HDD1 is configured with type LVM, and HDD2 is configured with type RAID. We will change HDD1 to type RAID, so that both HDD1 and HDD2 can be used in a RAID array.

 

The fdisk -l command can be used to view the partition type. In this example, there are a variety of partition types, including an LVM partition and a RAID partition.

[root@server1 ~]# disk -l | less
/dev/sda1   83  Linux
/dev/sdb1   8e  Linux LVM
/dev/sdc1   fd  Linux raid autodetect

 

The df command can be used to view where each filesystem is mounted. This shows that data is stored.

[root@server1 ~]# df
/dev/mapper/centos-root    /         15%
/dev/mapper/centos-var     /var      25%
/dev/sda1                  /boot      3%

 

In this example, we need to change /dev/sdb1 from Linux LVM to RAID. First we need to remove /dev/sdb1 from LVM. Use the pvdisplay command to view the LVM physical volume. In this example, /dev/sdb1 is an LVM physical volume.

[root@server1 ~]# pvdisplay
PV Name    /dev/sdb1

 

Display information about the current volume group. Notice the volume group name is centos, and notice the free size is 0.

[root@server1 ~]# vgdisplay
--- Volume group ---
VG Name            centos
VG Size            2.0 TiB
Alloc PE / Size    474623 / 2.0 TiB
Free PE / Size     0 / 0

 

Add the /dev/md0 physical volume to the volume group named centos.

[root@server1 ~]# vgextend centos /dev/md0
Volume group "centos" successfully extended

 

View the volume group again, and notice the volume group size has doubled and the free size is now 2 TB.

[root@server1 ~]# vgdisplay
--- Volume group ---
VG Name            centos
VG Size            4.0 TiB
Alloc PE / Size    474623 / 2.0 TiB
Free PE / Size     471858 / 2.0 TiB

 

/dev/sda (SSD), /dev/sdb (HDD1), and /dev/md0 (HDD2) are now members of volume group "centos." Now we move the /dev/sdb physical volume into /dev/md0, so that both /dev/sdb (HDD1) and /dev/sdc (HDD2) are part of /dev/md0.

[root@server1 ~]# pvmove /dev/sdb1 /dev/md0

 

Display information about the current logical volumes.

[root@server1 ~]# lvdisplay
--- Logical volume ---
LV Path        /dev/centos/root
LV Name        root
VG Name        centos
LV Size        2.0 TiB

 

The lvcreate command with the -n or --name and -L or --size can be used to create a new logical volume. In this example, a new 2TB logical volume named MyLogicalVolume is created in MyVolumeGroup.

[root@server1 ~]# lvcreate --name MyLogicalVolume --size 2TB MyVolumeGroup
--name mirror --
size 2TB MyLogicalVolume

 

lvscan shows a simple summary of the logical volumes.

[root@server1 ~]# lvscan
ACTIVE    /dev/centos
/root   [2.0 TiB] inherit
ACTIVE    /dev/centos
/mirror [2.0 TiB] inherit

 

There is now a logical volume /dev/centos/root which used 2TB of capacity from physical volume /dev/sdb. Also, there is a logical volume /dev/centos/mirror which uses 2TB of capacity from /dev/sdc.

 

Determine the file system type for the first HDD. In this example, the first HDD is using the ext4 filesystem.

[root@server1 ~]# df -T
/dev/mapper/centos-root     ext4

 

Use the same filesystem type for the second HDD.  In /dev/centos/mirror, "centos" is the name of the volume group, and "mirror" is the name of the logical volume.

[root@server1 ~]# mkfs.ext4 /dev/centos/mirror

 

fdisk -l should now have a listing for /dev/mapper/centos-mirror.

 

Add an entry to /etc/fstab.

/dev/mapper/centos-root    /            ext4    defaults  1 1
/dev/mapper/centos-mirror  /mnt/test    ext4    defaults  1 1

 

Reboot the OS.

[root@server1 ~]# reboot

 

Both the first HDD (/dev/mapper/centos-root) and second HDD (/dev/mapper/centos-mirror) should be listed in the output of the df -T command.

[root@server1 ~]# df -T
/dev/mapper/centos-root     ext4
/dev/mapper/centos-mirror   ext4

 

Sources

"A Beginner's Guide To LVM - Page 6 - Page 6." A Beginner's Guide To LVM - Page 6 - Page 6. HowtoForge, n.d. Web. 26 Mar. 2016. <https://www.howtoforge.com/linux_lvm_p6>.

 

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments