http://www.howtoforge.com/linux_lvm_p1 ===== utilities apt-get install lvm2 dmsetup mdadm reiserfsprogs xfsprogs ===== LVM commands pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 pvremove /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 pvdisplay lvdisplay vgrename fileserver data vgscan lvcreate --name share --size 40G fileserver lvcreate --name backup --size 5G fileserver lvcreate --name media --size 1G fileserver lvscan ACTIVE '/dev/fileserver/share' [40.00 GB] inherit ACTIVE '/dev/fileserver/backup' [5.00 GB] inherit ACTIVE '/dev/fileserver/media' [1.00 GB] inherit ----- rename our logical volume media into films lvrename fileserver media films lvscan ACTIVE '/dev/fileserver/share' [40.00 GB] inherit ACTIVE '/dev/fileserver/backup' [5.00 GB] inherit ACTIVE '/dev/fileserver/films' [1.00 GB] inherit ----- enlarge media from 1GB to 1.5GB lvextend -L1.5G /dev/fileserver/media ===== create file system mkfs.ext3 /dev/fileserver/share mkfs.xfs /dev/fileserver/backup mkfs.reiserfs /dev/fileserver/media mkdir /var/media /var/backup /var/share ----- /etc/fstab /dev/fileserver/share /var/share ext3 rw,noatime 0 0 /dev/fileserver/backup /var/backup xfs rw,noatime 0 0 /dev/fileserver/media /var/media reiserfs rw,noatime 0 0 ===== enlarge share from 40GB to 50GB umount /var/share lvextend -L50G /dev/fileserver/share we have enlarged only share, but not the ext3 filesystem on share. This is what we do now e2fsck -f /dev/fileserver/share Make a note of the total amount of blocks (10485760) because we need it when we shrink share later on resize2fs /dev/fileserver/share mount /dev/fileserver/share /var/share ===== shrinking a logical volume When resizing an ext3 filesystem to a certain size (instead of all available space), resize2fs takes the number of blocks as argument (you can as well specify the new size in MB, etc. resize2fs /dev/fileserver/share 10485760 lvreduce -L40G /dev/fileserver/share We can ignore the warning that data might be destroyed because we have shrinked the filesystem before mount /dev/fileserver/share /var/share ===== Adding A Hard Drive And Removing Another One create partion(s) pvcreate /dev/sdf1 ----- add /dev/sdf1 to our fileserver volume group vgextend fileserver /dev/sdf1 vgdisplay /dev/sdf1 has been added to the fileserver volume group ----- let's remove /dev/sdb1. First we must copy all data on it to /dev/sdf1 pvmove /dev/sdb1 /dev/sdf1 vgreduce fileserver /dev/sdb1 pvdisplay pvremove /dev/sdb1 ===== RAID-1 RAID array /dev/md0 from the partitions /dev/sdb1 + /dev/sdc1, and the RAID array /dev/md1 from the partitions /dev/sdd1 + /dev/sde1. /dev/md0 and /dev/md1 will then be the physical volumes for LVM pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 vgcreate fileserver /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 lvcreate --name share --size 40G fileserver lvcreate --name backup --size 5G fileserver lvcreate --name media --size 1G fileserver mkfs.ext3 /dev/fileserver/share mkfs.xfs /dev/fileserver/backup mkfs.reiserfs /dev/fileserver/media mount /dev/fileserver/share /var/share mount /dev/fileserver/backup /var/backup mount /dev/fileserver/media /var/media move the contents of /dev/sdc1 and /dev/sde1 (/dev/sdc1 is the second partition of our future /dev/md0, /dev/sde1 the second partition of our future /dev/md1) to the remaining partitions, because we will afterwards remove them from LVM and format them with the type fd (Linux RAID autodetect) and move them to /dev/md0 resp. /dev/md1 modprobe dm-mirror pvmove /dev/sdc1 vgreduce fileserver /dev/sdc1 pvremove /dev/sdc1 pvdisplay pvmove /dev/sde1 vgreduce fileserver /dev/sde1 pvremove /dev/sde1 pvdisplay ----- format /dev/sdc1 with the type fd (Linux RAID autodetect) fdisk /dev/sdc fdisk /dev/sde add /dev/sdc1 to /dev/md0 and /dev/sde1 to /dev/md1. Because the second nodes (/dev/sdb1 and /dev/sdd1) are not ready yet, we must specify missing in the following commands mdadm --create /dev/md0 --auto=yes -l 1 -n 2 /dev/sdc1 missing mdadm --create /dev/md1 --auto=yes -l 1 -n 2 /dev/sde1 missing ----- prepare /dev/md0 and /dev/md1 for LVM pvcreate /dev/md0 /dev/md1 ----- extend our fileserver volume group vgextend fileserver /dev/md0 /dev/md1 pvdisplay vgdisplay move the contents of /dev/sdb1 to /dev/md0 and the contents of /dev/sdd1 to /dev/md1, then we remove /dev/sdb1 and /dev/sdd1 from LVM pvmove /dev/sdb1 /dev/md0 pvmove /dev/sdd1 /dev/md1 only /dev/md0 and /dev/md1 should be left as physical volumes pvdisplay format /dev/sdb1 with fd (Linux RAID autodetect) fdisk /dev/sdb fdisk /dev/sdd add /dev/sdb1 to /dev/md0 and /dev/sdd1 to /dev/md1 mdadm --manage /dev/md0 --add /dev/sdb1 mdadm --manage /dev/md1 --add /dev/sdd1 cat /proc/mdstat pvdisplay you will see that 2 * 23.29GB = 46.58GB are available, however only 40GB (share) + 5GB (backup) + 1GB (media) = 46GB are used which means we could extend one of our logical devices with about 0.5GB. I've already shown how to extend an ext3 logical volume (share), so we will resize media now which uses reiserfs. reiserfs filesystems can be resized without unmounting: lvextend -L1.5G /dev/fileserver/media resize_reiserfs /dev/fileserver/media logical volumes to be mounted automatically at boot time, we must modify /etc/fstab /dev/fileserver/share /var/share ext3 rw,noatime 0 0 /dev/fileserver/backup /var/backup xfs rw,noatime 0 0 /dev/fileserver/media /var/media reiserfs rw,noatime 0 0 ===== Replacing The Hard Disks With Bigger Ones First we remove /dev/sdb and /dev/sdd from the RAID arrays, replace them with bigger hard disks, put them back into the RAID arrays, and then we do the same again with /dev/sdc and /dev/sde ----- we mark /dev/sdb1 as failed mdadm --manage /dev/md0 --fail /dev/sdb1 cat /proc/mdstat ----- remove /dev/sdb1 from the RAID array /dev/md0 mdadm --manage /dev/md0 --remove /dev/sdb1 same for /dev/sdd1 mdadm --manage /dev/md1 --fail /dev/sdd1 mdadm --manage /dev/md1 --remove /dev/sdd1 On a real system you would now shut it down, pull out the 25GB /dev/sdb and /dev/sdd and replace them with 80GB ones we must format /dev/sdb and /dev/sdd. We must create a /dev/sdb1 resp. /dev/sdd1 partition, type fd (Linux RAID autodetect), size 25GB (the same settings as on the old hard disks), and a /dev/sdb2 resp. /dev/sdd2 partition, type fd, that cover the rest of the hard disks. As /dev/sdb1 and /dev/sdd1 are still present on our hard disks, we only have to create /dev/sdb2 and /dev/sdd2 in this special example fdisk /dev/sdb fdisk /dev/sdd add /dev/sdb1 to /dev/md0 again and /dev/sdd1 to /dev/md1 mdadm --manage /dev/md0 --add /dev/sdb1 mdadm --manage /dev/md1 --add /dev/sdd1 cat /proc/mdstat do the same process again, this time replacing /dev/sdc and /dev/sde mdadm --manage /dev/md0 --fail /dev/sdc1 mdadm --manage /dev/md0 --remove /dev/sdc1 mdadm --manage /dev/md1 --fail /dev/sde1 mdadm --manage /dev/md1 --remove /dev/sde1 fdisk /dev/sdc fdisk /dev/sde mdadm --manage /dev/md0 --add /dev/sdc1 mdadm --manage /dev/md1 --add /dev/sde1 cat /proc/mdstat Wait until the synchronization has finished create the RAID arrays /dev/md2 from /dev/sdb2 and /dev/sdc2 as well as /dev/md3 from /dev/sdd2 and /dev/sde2 mdadm --create /dev/md2 --auto=yes -l 1 -n 2 /dev/sdb2 /dev/sdc2 mdadm --create /dev/md3 --auto=yes -l 1 -n 2 /dev/sdd2 /dev/sde2 new RAID arrays must be synchronized before we go on, so you should check cat /proc/mdstat After the synchronization has finished, we prepare /dev/md2 and /dev/md3 for LVM: pvcreate /dev/md2 /dev/md3 pvdisplay vgdisplay lvdisplay If your outputs look similar, you have successfully replaced your small hard disks with bigger ones. Now that we have more disk space (2* 23.29GB + 2 * 56.71GB = 160GB) we could enlarge our logical volumes ----- enlarge our backup logical volume now which uses xfs lvextend -L10G /dev/fileserver/backup xfs_growfs /dev/fileserver/backup ===== pvdisplay| egrep -i "Name|Size" lvdisplay | egrep -i "LV|VG"