Extending LVM and LVM configuration backup
How I screwed things on my own...
Recently I was supposed add new disks of 3 TBs ( 5 Physical 750GB disks) to an existing Linux LVM. A new big disk of 3TB was created from the array of disks. Used "parted" to create a big partition for the whole disk size( normal partitions bigger than 2TB are not supported via fdisk) and went ahead adding the new disk space to LVM. things went fine , when i finally checked with lvmdisplay the new size was increased in the target lvm.... but , vgdisplay and pvdisplay didn't report it appropriately :-(
No issues, since i remembered the previous size, i shirked it using lvextend -L -3TB.
then any command that i issued was throwing error. and things got screwed.
Goggled a lot to get a resolution and didn't land to any right spot. then browsed through all the commands that get installed with the lvm RPM. then found 2 important commands vgcfgbackup and vgcfgrestore.
What I learnt.
the /etc/lvm folder is quite important. backup, cache, and archive sub-folders hold important data. normally before any real ( without -t parameter ) lvm related command gets executed that changes, PV or VG or LVM ,the current configuration is taken as a backup and gets stored in the the backup directory, and many such subsequent operations would move backup configuration to archive folder.
Thankfully i had unmounted the target LVM before things were setup wrongly. Its a good practice so that one doesn't screw the actual data.
I had then used " vgcfgrestore -f " command to restore the right lvm config before i screwed the file system, and did a restart and things went back to normalcy. Gosh...
How to extend LVM disk size.
Then the big 3TB disk was removed and physical disks were clubbed configured as 2, 2 and 1 as /dev/sdd, /dev/sde and /dev/sdf.
I would put the steps for one disk addition ( /dev/sdd) and similar gets applied to subsequent disks.
Login as root or use "su" and umount the target lvm mount.( unmount is not so necessary if you are not going to screw anything)
use "n" to create a new partition, give "p" to set the partition as primary partition. Select starting and ending point ( default for entire disk space). issue "p" to print the partition information and then then issue "t" to toggle the patition type from Linux to Linux LVM. "8e" is the HEX code for linux lvm. Use "p" to print the partition table and "w" to save and exit fdisk.
Once exited from fdisk issue fdisk -l to confirm that /dev/sdd1 is created with Linux LVM partition.
Note: It would be advised to use the test "-t" switch on commands that would change the lvm system and check for anomaly before doing something disastrous. Take a backup of lvm metadata using vgcfgbackup
I still would like to know how to create a bigger partition with parted and have linux lvm as fs type for that parition. I am tired of googling that and got into other busy things. Would be grateful if you can point me out to some good place.
Recently I was supposed add new disks of 3 TBs ( 5 Physical 750GB disks) to an existing Linux LVM. A new big disk of 3TB was created from the array of disks. Used "parted" to create a big partition for the whole disk size( normal partitions bigger than 2TB are not supported via fdisk) and went ahead adding the new disk space to LVM. things went fine , when i finally checked with lvmdisplay the new size was increased in the target lvm.... but , vgdisplay and pvdisplay didn't report it appropriately :-(
No issues, since i remembered the previous size, i shirked it using lvextend -L -3TB.
then any command that i issued was throwing error. and things got screwed.
Goggled a lot to get a resolution and didn't land to any right spot. then browsed through all the commands that get installed with the lvm RPM. then found 2 important commands vgcfgbackup and vgcfgrestore.
What I learnt.
the /etc/lvm folder is quite important. backup, cache, and archive sub-folders hold important data. normally before any real ( without -t parameter ) lvm related command gets executed that changes, PV or VG or LVM ,the current configuration is taken as a backup and gets stored in the the backup directory, and many such subsequent operations would move backup configuration to archive folder.
Thankfully i had unmounted the target LVM before things were setup wrongly. Its a good practice so that one doesn't screw the actual data.
I had then used " vgcfgrestore -f " command to restore the right lvm config before i screwed the file system, and did a restart and things went back to normalcy. Gosh...
How to extend LVM disk size.
Then the big 3TB disk was removed and physical disks were clubbed configured as 2, 2 and 1 as /dev/sdd, /dev/sde and /dev/sdf.
I would put the steps for one disk addition ( /dev/sdd) and similar gets applied to subsequent disks.
Login as root or use "su" and umount the target lvm mount.( unmount is not so necessary if you are not going to screw anything)
- Create primary partition on the newly created disk.
use "n" to create a new partition, give "p" to set the partition as primary partition. Select starting and ending point ( default for entire disk space). issue "p" to print the partition information and then then issue "t" to toggle the patition type from Linux to Linux LVM. "8e" is the HEX code for linux lvm. Use "p" to print the partition table and "w" to save and exit fdisk.
Once exited from fdisk issue fdisk -l to confirm that /dev/sdd1 is created with Linux LVM partition.
- Create a Physical volume to be used by the lvm subsystem. we do this using the pvcreate command.
- Extend existing volume group to include newly created Physical volume. Assume that the existing volume group is called "vghome" ( /dev/vghom in fs)
- Extend existing logical volume to include new space. Assume that the volume group "vghome" contains "lvhome" as one of the lvm.
- Increase the file system after mounting - If you have unmounted the lvm you will have to mount it back. before you mount check for sanity with pvdisplay, vgdisplay and lvdisplay. If you have many vgs and lvs any error displayed on the first few lines of the these command outputs can go unnoticed. ( use more in pipe ). you can use lvmdiskscan also. The ext2online tool resizes ext2 file systems while they are mounted and in use by the system. It is OK to resize the filesystem even while programs have open files and are writing into the filesystem. It is only possible to enlarge a mounted filesystem. It would take a little while depending upon the size of the file system.
Note: It would be advised to use the test "-t" switch on commands that would change the lvm system and check for anomaly before doing something disastrous. Take a backup of lvm metadata using vgcfgbackup
I still would like to know how to create a bigger partition with parted and have linux lvm as fs type for that parition. I am tired of googling that and got into other busy things. Would be grateful if you can point me out to some good place.
Comments