How can I create one logical volume over two disks using LVM?
Solution 1
You should have a look at this detailed answer.
Here's a summary of it:
- Create a physical volume on the first hard drive, and another physical volume on the second hard drive.
- Create a new volume group, assigning both physical volumes to it.
- Create a new logical volume in that volume group.
- Create a new ext3 filesystem in that logical volume.
The diagram I copied from this answer visualises this (but with three filesystems, rather than just one):
As you can see, creating an ext3 filesystem is the last step, not the first. If you have an existing ext3 partition that isn't in LVM, you can't migrate it to LVM. You'll have to backup the partition, delete the partition, setup LVM, and then copy the files back.
Solution 2
Don't do it, unless you've got another 2 3TB disks to use in a 4-disk array in RAID10.
Simply combining the two as a single large partition without any means of back-up of the data, is not a good idea. The data will be interleaved across both disks, and if any part of either disk goes bad, you could end up losing all 6TB of data (assuming you had that much data), rather than only half at most.
It'll be much safer to use both as separate partitions, rather than a very large array partition.
Solution 3
One easy way to use LVM is :
-
create physical volumes with the "pvcreate" command:
pvcreate /dev/sdc
pvcreate /dev/sdd
pvcreate /dev/sde
- ...
use
system-config-lvm
which is a GUI tool available in the Ubuntu Software Center
the new LVM partition might be owned by root but it's easy to set it back to your user with:
sudo chown -R username:username /path/to/your/lvm
Solution 4
On Debian, using lvm2:
-
Install lvm2 using
sudo apt install lvm2
and start it using/etc/init.d/lvm2 start
-
List all the volumes using
lsblk
-
Create physical volumes
/sbin/pvcreate <volume from prev list>
-
Then to list the volumes use
/sbin/lvmdiskscan
-
Create a volume group (vg)
/sbin/vgcreate <name> /dev/vdb
-
Format the volume group
/sbin/mkfs.ext4 /dev/mapper/Vol_group
-
Change fstab if you want to map this vg to some filesystem
/dev/mapper/vg /var/lib/folder ext4 rw,user
-
Mount the volume using
mount -a
Related videos on Youtube
Hydrosine
Updated on September 18, 2022Comments
-
Hydrosine over 1 year
Hi. I've got a working Ubuntu 12.04 server, which is going to serve as media server. I've added two disks of size 3TB to put my data on, and I wish to combine these as one 6TB logical volume which I could mount under
/media
.So far, I have created one partition on each disks with
fdisk
and formatted them to ext3. But now I am stuck on how to continue. Do I use Mdadm to create a Jbod array? Or do I use LVM to make a logical volume of these two disks? I can't seem to find the documentation I need, it's mostly about extending existing volumes or installing a fresh system which I don't need.My OS is on
/dev/sdc1
(it's a USB thumb-drive), and the two newly created partitions are on/dev/sda1
and/dev/sdb1
.Hope you can give me some directions.
-
Hydrosine over 11 yearsThe data will not be very important. I know that if i create a JBOD i will lose all data if one crashes. but is this also true for a Logical Volume? I'm willing to take the risk of losing all data if one disk fails btw :)
-
Hydrosine over 11 yearsFound some more about it. LVM is unable to initialize if one disk is missing. I'm going for 2 mountpoints /media and /media1.
-
Hydrosine over 11 yearsVery clear how LVM is working :) step 1 "pvcreate /dev/sda && pvcreate /dev/sdb" then "vgcreate data /dev/sda /dev/sdb" final step "lvcreate video".
-
psusi over 11 yearsNote that LVM is capable of striping data, but so is
mdadm
.mdadm
can also do raid10, sacrificing space for redundancy so you can have a drive fail and still work without it. You can also use mdadm to handle the raid parts, then stack LVM on top of it if you wish, just to carve up the space into volumes and add abilities like snapshots. -
max over 9 yearsI just noticed you can also initialize the volumes with the GUI using the "initialize entity" button