ยง2024-07-08
Correct, using LVM with RAID 0 does not provide redundancy. RAID 0 is used for performance by striping data across multiple disks, but if one disk fails, all data in the array is lost. To have redundancy along with LVM, consider using RAID 1 (mirroring) or RAID 5/6 (striping with parity).
However, if you still want to extend your /var
partition with a RAID 0 setup using LVM, follow these steps:
Prerequisites
- Ensure you have backups of your data.
- Ensure
mdadm
(the software RAID management tool) is installed:sudo apt-get install mdadm
Steps
-
Prepare the New Disks: Partition
/dev/sda2
and/dev/sdb1
(or any other disks you want to use in the RAID 0 array).sudo fdisk /dev/sda
- Use
n
to create a new partition. - Select the partition number (e.g., 2).
- Specify the start and end (default values should be fine if you're using the entire space).
- Use
t
to change the partition type tofd
(Linux RAID autodetect). - Use
w
to write the changes.
Repeat the process for
/dev/sdb
to create/dev/sdb1
. - Use
-
Create a New RAID 0 Array:
sudo mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sda2 /dev/sdb1
-
Create a Physical Volume (PV) on the RAID device:
sudo pvcreate /dev/md0
-
Extend the Volume Group (VG): Add the new RAID device to your existing volume group.
sudo vgextend <VG Name> /dev/md0
-
Extend the Logical Volume (LV): Identify the logical volume for
/var
and extend it to include the new space.sudo lvextend -l +100%FREE <LV Path>
-
Resize the Filesystem: Finally, resize the filesystem to use the newly allocated space.
sudo resize2fs <LV Path>
Example
Assuming the VG name is vg0
and the LV path is /dev/vg0/var
:
sudo mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sda2 /dev/sdb1
sudo pvcreate /dev/md0
sudo vgextend vg0 /dev/md0
sudo lvextend -l +100%FREE /dev/vg0/var
sudo resize2fs /dev/vg0/var
Verifying
You can verify the changes by checking the disk space:
df -h /var
This should show the increased size for /var
.
Notes
- Be cautious with RAID 0 as it offers no redundancy; if one drive fails, all data in the array is lost.
- The exact commands may vary slightly based on your Linux distribution.
- Ensure no processes are using
/var
heavily during this operation to avoid issues.
If you require redundancy, consider using RAID 1, RAID 5, or RAID 6 setups, which can be integrated with LVM to provide both redundancy and flexibility.