Create a new LVM Group
From Admin-SIG
| Table of contents |
Create the physical volume on new LVM Partition
pvcreate /dev/sda4
This isn't working for me, I still got
Device /dev/sda4 not found (or ignored by filtering).
Try rebooting... I dunno what filtering is... now it works.
Check the new physical volume:
# pvdisplay
--- NEW Physical volume ---
PV Name /dev/evms/sda4
VG Name
PV Size 224.02 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 6MFehO-M5s9-dZx9-sD73-fPd7-eB9z-xHG3cp
Create the physical volume group
# vgcreate EW1 /dev/evms/sda4
Volume group "EW1" successfully created
Now it has stuff:
# pvdisplay
--- Physical volume ---
PV Name /dev/evms/sda4
VG Name EW1
PV Size 224.02 GB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 57349
Free PE 57349
Allocated PE 0
PV UUID 6MFehO-M5s9-dZx9-sD73-fPd7-eB9z-xHG3cp
Activate this volume:
# vgchange -a y EW1
0 logical volume(s) in volume group "EW1" now active
Check Virtual Group:
# vgdisplay EW1
--- Volume group ---
VG Name EW1
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 224.02 GB
PE Size 4.00 MB
Total PE 57349
Alloc PE / Size 0 / 0
Free PE / Size 57349 / 224.02 GB
VG UUID y2OYz0-HV7j-cM7p-gUVQ-E5NY-I0pp-kRkiAM
Create Logical Volumes
I want to move some larger areas to the new LVM area instead of /. Note that it would be tricky to move the real core stuff there, so I'm leaving things like /bin, /sbin, /lib alone. Here are my candidates:
# du -h -s /home /opt /tmp /usr /var 46M /home 25M /opt 56K /tmp 2.4G /usr 692M /var
The bulk of my / is in /usr, and /var, neither of which are needed early in the boot process. They are safe to move to LVM.
Create Linear logical volumes (linear is fine, since we have only one physical group here).
# lvcreate -L8000 -nusrlv EW1
Logical volume "usrlv" created
# lvcreate -L8000 -nvarLV EW1
Logical volume "varLV" created
# lvcreate -L128000 -ndataLV EW1
Logical volume "dataLV" created
Now we have our new block devices to use:
# ls -l /dev/E* total 0 lrwxrwxrwx 1 root root 22 2006-09-11 08:50 dataLV -> /dev/mapper/EW1-dataLV lrwxrwxrwx 1 root root 21 2006-09-11 08:42 usrlv -> /dev/mapper/EW1-usrlv lrwxrwxrwx 1 root root 21 2006-09-11 08:49 varLV -> /dev/mapper/EW1-varLV # ls -l /dev/mapper/ total 0 crw-rw---- 1 root root 10, 63 2006-09-11 08:14 control brw------- 1 root root 253, 8 2006-09-11 08:50 EW1-dataLV brw------- 1 root root 253, 6 2006-09-11 08:42 EW1-usrlv brw------- 1 root root 253, 7 2006-09-11 08:49 EW1-varLV
Create File Systems
Create the filesystems on these new logical volumes. I like ext3.
My future /data area is for large files like audio and video, so I am setting a large block size. I also like to check for bad blocks first use, even though it takes a long time:
# mke2fs -j -b 4096 -c -L dataVol /dev/EW1/dataLV # mke2fs -j -c -L usrVol /dev/EW1/usrlv # mke2fs -j -c -L varVol /dev/EW1/varLV
Mount Logical Volumes
My new /data area is easiest, since it is new. We will use /data to hold backups of the areas I want to migrate into LVM.
# mkdir /data # mount -t ext3 /dev/EW1/dataLV /data
Move Critical data
This can be tricky on a running system, but I've done it before. I'll try again. Try to take a big tar of the old volumes.
Make backups of critical areas:
# cd / # tar cvf /data/backups/earwig/usr1.tar usr # apt-get clean # clean debian package cache # tar cvf /data/backups/earwig/var1.tar var
Switch to using new Logical Volumes
Manually mount LVM areas, and copy over data.
# mount -t ext3 /dev/EW1/usrlv /mnt # cd /mnt # tar xvf /data/backups/earwig/usr1.tar # cd usr; mv * .. # cd .. ; rmdir usr # cd / ; umount /mnt # mount -t ext3 /dev/EW1/varLV /mnt # cd /mnt ; tar xvf /data/backups/earwig/var1.tar # cd var; mv * .. # cd .. ; rmdir var # cd / ; umount /mnt
The next two steps are very dangerous. Be very careful. If they are not done EXACTLY correct, you can get a corrupt system. DO NOT ATTEMPT THIS unless you are comfortable with booting to recovery mode to correct any errors made here.
Add these entries to fstab:
/dev/EW1/usrLV /usr ext3 defaults,errors=remount-ro 0 0 /dev/EW1/varLV /var ext3 defaults,errors=remount-ro 0 0 /dev/EW1/dataLV /data ext3 defaults,errors=remount-ro 0 0
Move the old volumes to new names, so we can reclaim this disk space for / later, and reboot to start using the new logical volumes:
# cd / # mv usr /usr1 # mv var /var1 # mkdir /usr # mkdir /var # reboot
If all is working, you can now remove the old /usr and /var areas:
# \rm -rf /usr1 /var1
Now file systems look like:
# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 8064556 357020 7297880 5% / varlock 449100 4 449096 1% /var/lock udev 449100 148 448952 1% /dev devshm 449100 0 449100 0% /dev/shm lrm 449100 21540 427560 5% /lib/modules/2.6.15-23-amd64-generic/volatile /dev/sda1 45130 10556 32166 25% /boot /dev/mapper/EW1-usrlv 8063408 2637488 5016320 35% /usr /dev/mapper/EW1-varLV 8063408 357796 7296012 5% /var /dev/mapper/EW1-dataLV 129015460 2660716 119801144 3% /data /dev/hda1 7296192 6018024 1278168 83% /media/hda1 /dev/hda2 148969796 22012924 126956872 15% /media/hda2 crow:/scr 192292128 81705264 100818944 45% /mnt/scr
--Aaron 08:56, 11 Sep 2006 (MDT)

