How to create LVM partition with partition alignment in Virtual machine (VM)
Request vmware team to provide the new disk to VM
# cat /proc/partitions major minor #blocks name 253 0 20971520 vda 253 1 104391 vda1 253 2 20860402 vda2 252 0 18776064 dm-0 252 1 2064384 dm-1
Scan from the available host to detect the new disk
#echo " - - - " >> /sys/class/scsi_host/host0/scan #echo " - - - " >> /sys/class/scsi_host/host1/scan
Run cat /proc/partitions again to locate the new disk. From the below output hda is new 5 GB disk
# cat /proc/partitions major minor #blocks name 3 0 5242880 hda 253 0 20971520 vda 253 1 104391 vda1 253 2 20860402 vda2 252 0 18776064 dm-0 252 1 2064384 dm-1
Format the new with partitiion alignment
# fdisk /dev/hda Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-652, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-652, default 652): Using default value 652 Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): x Expert command (m for help): b Partition number (1-4): 1 New beginning of data (63-10474379, default 63): 128 Expert command (m for help): r Command (m for help): p Disk /dev/hda: 5368 MB, 5368709120 bytes 255 heads, 63 sectors/track, 652 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/hda1 1 652 5237126 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. You have new mail in /var/spool/mail/root
Validate the disk successfully partitioned with partition alignment
# fdisk -ul /dev/hda Disk /dev/hda: 5368 MB, 5368709120 bytes 255 heads, 63 sectors/track, 652 cylinders, total 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Device Boot Start End Blocks Id System /dev/hda1 128 10474379 5237126 8e Linux LVM
Run partprobe command to make the partition visible to the OS.
# partprobe /dev/hda # partprobe /dev/hda1 # fdisk -ul /dev/hda Disk /dev/hda: 5368 MB, 5368709120 bytes 255 heads, 63 sectors/track, 652 cylinders, total 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Device Boot Start End Blocks Id System /dev/hda1 128 10474379 5237126 8e Linux LVM
Add the disk to Physical volume (PV)
# pvs PV VG Fmt Attr PSize PFree /dev/vda2 VolGroup00 lvm2 a-- 19.88G 0 # pvcreate /dev/hda1 Writing physical volume data to disk "/dev/hda1" Physical volume "/dev/hda1" successfully created # pvs PV VG Fmt Attr PSize PFree /dev/hda1 lvm2 a-- 4.99G 4.99G /dev/vda2 VolGroup00 lvm2 a-- 19.88G 0
Create new Volume Group or extend the existing volume group using new disk
# vgs VG #PV #LV #SN Attr VSize VFree VolGroup00 1 2 0 wz--n- 19.88G 0 # vgcreate vg0 /dev/hda1 Volume group "vg0" successfully created # vgs VG #PV #LV #SN Attr VSize VFree VolGroup00 1 2 0 wz--n- 19.88G 0 vg0 1 0 0 wz--n- 4.99G 4.99G
Create new Logical Volume (LV)
# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert LogVol00 VolGroup00 -wi-ao 17.91G LogVol01 VolGroup00 -wi-ao 1.97G # lvcreate -L4G -n lvm1 vg0 Logical volume "lvm1" created ]# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert LogVol00 VolGroup00 -wi-ao 17.91G LogVol01 VolGroup00 -wi-ao 1.97G lvm1 vg0 -wi-a- 4.00G
Make the LV as ext3 partition.
# mkfs.ext3 /dev/vg0/lvm1 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 524288 inodes, 1048576 blocks 52428 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1073741824 32 block groups 32768 blocks per group, 32768 fragments per group 16384 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 28 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
Create the new directory to mount the newly created LVM
# mkdir /data
Make an enty in /etc/fstab for new lVM
# vim /etc/fstab # cat /etc/fstab /dev/VolGroup00/LogVol00 / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/VolGroup00/LogVol01 swap swap defaults 0 0 /dev/vg0/lvm1 /data ext3 defaults 0 0
Mount newly created lvm
# mount /data/
Run df -h command and Validate that filesystem is successfully mounted.
# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 18G 2.3G 15G 14% / /dev/vda1 99M 13M 82M 14% /boot tmpfs 502M 0 502M 0% /dev/shm /dev/mapper/vg0-lvm1 4.0G 137M 3.7G 4% /data
Goto the directory and create some files to make sure that new filesystem is writable.
# cd /data/ # touch 1 2 3 4 # ll total 16 -rw-r--r-- 1 root root 0 Nov 3 11:30 1 -rw-r--r-- 1 root root 0 Nov 3 11:30 2 -rw-r--r-- 1 root root 0 Nov 3 11:30 3 -rw-r--r-- 1 root root 0 Nov 3 11:30 4 drwx------ 2 root root 16384 Nov 3 11:22 lost+found #