{"id":362,"date":"2012-06-19T16:23:47","date_gmt":"2012-06-19T08:23:47","guid":{"rendered":"http:\/\/rmohan.com\/?p=362"},"modified":"2012-06-19T16:23:47","modified_gmt":"2012-06-19T08:23:47","slug":"lvm","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=362","title":{"rendered":"LVM"},"content":{"rendered":"<p><strong>LVM<\/strong><\/p>\n<p>First LVM Setup<\/p>\n<p>1)  fdisk \/dev\/sdb<\/p>\n<p>WARNING: DOS-compatible mode is deprecated. It&#8217;s strongly recommended to<br \/>\n         switch off the mode (command &#8216;c&#8217;) and change display units to<br \/>\n         sectors (command &#8216;u&#8217;).<\/p>\n<p>Command (m for help): n<br \/>\nCommand action<br \/>\n   e   extended<br \/>\n   p   primary partition (1-4)<br \/>\np<br \/>\nPartition number (1-4): 1<br \/>\nFirst cylinder (1-13054, default 1):<br \/>\nUsing default value 1<br \/>\nLast cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054):<br \/>\nUsing default value 13054<\/p>\n<p>Command (m for help): t<br \/>\nSelected partition 1<br \/>\nHex code (type L to list codes): 8e<br \/>\nChanged system type of partition 1 to 8e (Linux LVM)<\/p>\n<p>Command (m for help): w<br \/>\nThe partition table has been altered!<\/p>\n<p>Calling ioctl() to re-read partition table.<br \/>\nSyncing disks.<\/p>\n<p>fdisk \/dev\/sdc<\/p>\n<p>fdisk \/dev\/sdd<\/p>\n<p>fdisk \/dev\/sde<\/p>\n<p>2) Now we prepare our new partitions for LVM:<\/p>\n<p>[root@localhost ~]# pvcreate \/dev\/sdb1 \/dev\/sdc1 \/dev\/sdd1<br \/>\n  Writing physical volume data to disk &#8220;\/dev\/sdb1&#8221;<br \/>\n  Physical volume &#8220;\/dev\/sdb1&#8221; successfully created<br \/>\n  Writing physical volume data to disk &#8220;\/dev\/sdc1&#8221;<br \/>\n  Physical volume &#8220;\/dev\/sdc1&#8221; successfully created<br \/>\n  Writing physical volume data to disk &#8220;\/dev\/sdd1&#8221;<br \/>\n  Physical volume &#8220;\/dev\/sdd1&#8221; successfully created<\/p>\n<p>Revert this last action <\/p>\n<p>[root@localhost ~]# pvremove \/dev\/sdb1 \/dev\/sdc1 \/dev\/sdd1<br \/>\n  Labels on physical volume &#8220;\/dev\/sdb1&#8221; successfully wiped<br \/>\n  Labels on physical volume &#8220;\/dev\/sdc1&#8221; successfully wiped<br \/>\n  Labels on physical volume &#8220;\/dev\/sdd1&#8221; successfully wiped<\/p>\n<p>To create again <\/p>\n<p>pvcreate \/dev\/sdb1 \/dev\/sdc1 \/dev\/sdd1<\/p>\n<p>[root@localhost ~]# pvcreate \/dev\/sdb1 \/dev\/sdc1 \/dev\/sdd1<br \/>\n  Writing physical volume data to disk &#8220;\/dev\/sdb1&#8221;<br \/>\n  Physical volume &#8220;\/dev\/sdb1&#8221; successfully created<br \/>\n  Writing physical volume data to disk &#8220;\/dev\/sdc1&#8221;<br \/>\n  Physical volume &#8220;\/dev\/sdc1&#8221; successfully created<br \/>\n  Writing physical volume data to disk &#8220;\/dev\/sdd1&#8221;<br \/>\n  Physical volume &#8220;\/dev\/sdd1&#8221; successfully created<\/p>\n<p>Let dispay the   current physical volumes <\/p>\n<p>[root@localhost ~]# pvdisplay <\/p>\n<p>3 ) create our volume group  datashare <\/p>\n<p>vgcreate datashare  \/dev\/sdb1 \/dev\/sdc1 \/dev\/sdd1 <\/p>\n<p>[root@localhost ~]# vgcreate datashare  \/dev\/sdb1 \/dev\/sdc1 \/dev\/sdd1<br \/>\n  Volume group &#8220;datashare&#8221; successfully created<\/p>\n<p>Dispaly the volume groups<br \/>\nvolume groups:  [root@localhost ~]# vgdisplay<\/p>\n<p>Dispaly the volume groups <\/p>\n<p>[root@localhost ~]# vgscan<br \/>\n  Reading all physical volumes.  This may take a while&#8230;<br \/>\n  Found volume group &#8220;datashare&#8221; using metadata type lvm2<br \/>\n  Found volume group &#8220;VolGroup&#8221; using metadata type lvm2<\/p>\n<p>let&#8217;s rename our volumegroup datashare into fileshare:<\/p>\n<p>vgrename datashare  fileshare<\/p>\n<p>[root@localhost ~]# vgrename datashare  fileshare<br \/>\n  Volume group &#8220;datashare&#8221; successfully renamed to &#8220;fileshare&#8221;<\/p>\n<p>[root@localhost ~]# vgscan<br \/>\n  Reading all physical volumes.  This may take a while&#8230;<br \/>\n  Found volume group &#8220;fileshare&#8221; using metadata type lvm2<br \/>\n  Found volume group &#8220;VolGroup&#8221; using metadata type lvm2<\/p>\n<p>let&#8217;s delete our volume group  fileshare<\/p>\n<p>vgremove fileshare<\/p>\n<p>[root@localhost ~]# vgremove fileshare<br \/>\n  Volume group &#8220;fileshare&#8221; successfully removed<\/p>\n<p>[root@localhost ~]# vgcreate datashare  \/dev\/sdb1 \/dev\/sdc1 \/dev\/sdd1<br \/>\n  Volume group &#8220;datashare&#8221; successfully created<\/p>\n<p>4) Next we create our logical volumes storage (40GB), backup (5GB), and data (1GB) in the volume group datashare<\/p>\n<p>lvcreate &#8211;name storage &#8211;size 30G datashare<\/p>\n<p>lvcreate &#8211;name backup  &#8211;size 20G datashare<\/p>\n<p>lvcreate &#8211;name data    &#8211;size  10G datashare<\/p>\n<p>[root@localhost ~]# lvcreate &#8211;name storage &#8211;size 30G datashare<br \/>\n  Logical volume &#8220;storage&#8221; created<br \/>\n[root@localhost ~]# lvcreate &#8211;name backup  &#8211;size 20G datashare<br \/>\n  Logical volume &#8220;backup&#8221; created<br \/>\n[root@localhost ~]# lvcreate &#8211;name data    &#8211;size  10G datashare<br \/>\n  Logical volume &#8220;data&#8221; created<\/p>\n<p>check using command :  lvdisplay  <\/p>\n<p>[root@localhost ~]# lvdisplay<br \/>\n\/dev\/datashare\/storage<br \/>\n\/dev\/datashare\/backup<br \/>\n\/dev\/datashare\/data<\/p>\n<p>[root@localhost ~]# lvscan<br \/>\n  ACTIVE            &#8216;\/dev\/datashare\/storage&#8217; [30.00 GiB] inherit<br \/>\n  ACTIVE            &#8216;\/dev\/datashare\/backup&#8217; [20.00 GiB] inherit<br \/>\n  ACTIVE            &#8216;\/dev\/datashare\/data&#8217; [10.00 GiB] inherit<br \/>\n  ACTIVE            &#8216;\/dev\/VolGroup\/lv_root&#8217; [48.62 GiB] inherit<br \/>\n  ACTIVE            &#8216;\/dev\/VolGroup\/lv_home&#8217; [50.63 GiB] inherit<br \/>\n  ACTIVE            &#8216;\/dev\/VolGroup\/lv_swap&#8217; [1.97 GiB] inherit<\/p>\n<p>5) Next let&#8217;s delete the logical volume data  <\/p>\n<p> lvremove  \/dev\/datashare\/data<\/p>\n<p>[root@localhost ~]#  lvremove  \/dev\/datashare\/data<br \/>\nDo you really want to remove active logical volume data? [y\/n]: y<br \/>\n  Logical volume &#8220;data&#8221; successfully removed<\/p>\n<p>Now let create  logical volume servershare <\/p>\n<p>lvcreate &#8211;name servershare &#8211;size  5G  datashare<\/p>\n<p>[root@localhost ~]# lvcreate &#8211;name servershare &#8211;size  5G  datashare<br \/>\n  Logical volume &#8220;servershare&#8221; created<\/p>\n<p>Now let&#8217;s enlarge servershare to 10 G <\/p>\n<p>lvextend  -L10G \/dev\/datashare\/servershare<\/p>\n<p>root@localhost ~]# lvextend  -L10G \/dev\/datashare\/servershare<br \/>\n  Extending logical volume servershare to 10.00 GiB<br \/>\n  Logical volume servershare successfully resized<\/p>\n<p>Let&#8217;s shrink it to 5GB Again <\/p>\n<p>lvreduce  -L5G \/dev\/datashare\/servershare<\/p>\n<p>root@localhost ~]# lvreduce  -L5G \/dev\/datashare\/servershare<br \/>\n  WARNING: Reducing active logical volume to 5.00 GiB<br \/>\n  THIS MAY DESTROY YOUR DATA (filesystem etc.)<br \/>\nDo you really want to reduce servershare? [y\/n]: Y<br \/>\n  Reducing logical volume servershare to 5.00 GiB<br \/>\n  Logical volume servershare successfully resized<\/p>\n<p>6) Lets format and mount the partition <\/p>\n<p>[root@localhost ~]# mkfs.ext4 \/dev\/datashare\/storage<br \/>\nmke2fs 1.41.12 (17-May-2010)<br \/>\nFilesystem label=<br \/>\nOS type: Linux<br \/>\nBlock size=4096 (log=2)<br \/>\nFragment size=4096 (log=2)<br \/>\nStride=0 blocks, Stripe width=0 blocks<br \/>\n1966080 inodes, 7864320 blocks<br \/>\n393216 blocks (5.00%) reserved for the super user<br \/>\nFirst data block=0<br \/>\nMaximum filesystem blocks=0<br \/>\n240 block groups<br \/>\n32768 blocks per group, 32768 fragments per group<br \/>\n8192 inodes per group<br \/>\nSuperblock backups stored on blocks:<br \/>\n        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,<br \/>\n        4096000<\/p>\n<p>Writing inode tables: done<br \/>\nCreating journal (32768 blocks): done<br \/>\nWriting superblocks and filesystem accounting information: done<\/p>\n<p>This filesystem will be automatically checked every 26 mounts or<br \/>\n180 days, whichever comes first.  Use tune2fs -c or -i to override.<\/p>\n<p>same case<\/p>\n<p>mkfs.ext4 \/dev\/datashare\/backup<br \/>\nmkfs.ext4 \/dev\/datashare\/servershare<\/p>\n<p>7) mkdir storage backup  servershare  in \/ <\/p>\n<p>   mount the logical volumes<\/p>\n<p>   mount \/dev\/datashare\/backup  \/backup<br \/>\n   mount \/dev\/datashare\/servershare  \/servershare<br \/>\n   mount \/dev\/datashare\/storage     \/storage<\/p>\n<p>[root@localhost \/]# df -TH<br \/>\nFilesystem    Type     Size   Used  Avail Use% Mounted on<br \/>\n\/dev\/mapper\/VolGroup-lv_root<br \/>\n              ext4      52G   2.6G    47G   6% \/<br \/>\ntmpfs        tmpfs     528M      0   528M   0% \/dev\/shm<br \/>\n\/dev\/sda1     ext4     508M    32M   450M   7% \/boot<br \/>\n\/dev\/mapper\/VolGroup-lv_home<br \/>\n              ext4      54G   189M    51G   1% \/home<br \/>\n\/dev\/mapper\/datashare-backup<br \/>\n              ext4      22G   181M    20G   1% \/backup<br \/>\n\/dev\/mapper\/datashare-servershare<br \/>\n              ext4     5.3G   145M   4.9G   3% \/servershare<br \/>\n\/dev\/mapper\/datashare-storage<br \/>\n              ext4      32G   181M    30G   1% \/storage<\/p>\n<p>Add in the fstab  to in order mount after the reboot <\/p>\n<p>8)  Resize Logical Volumes And Their Filesystems<\/p>\n<p>     Now let&#8217;s enlarge share from 30GB to 40GB:<\/p>\n<p>[root@localhost \/]# lvextend -L50G \/dev\/datashare\/storage<br \/>\n  Extending logical volume storage to 50.00 GiB<br \/>\n  Logical volume storage successfully resized<\/p>\n<p>we have enlarged only storage, but not the ext4 filesystem on share. <\/p>\n<p>we can do it by <\/p>\n<p>[root@localhost \/]# e2fsck -f \/dev\/datashare\/storage<br \/>\ne2fsck 1.41.12 (17-May-2010)<br \/>\nPass 1: Checking inodes, blocks, and sizes<br \/>\nPass 2: Checking directory structure<br \/>\nPass 3: Checking directory connectivity<br \/>\nPass 4: Checking reference counts<br \/>\nPass 5: Checking group summary information<br \/>\n\/dev\/datashare\/storage: 11\/1966080 files (0.0% non-contiguous), 167409\/7864320 blocks<\/p>\n<p>Make a note of the total amount of blocks (7864320) we need it when we shrink storage later on.<br \/>\n[root@localhost \/]# resize2fs \/dev\/datashare\/storage<br \/>\nresize2fs 1.41.12 (17-May-2010)<br \/>\nResizing the filesystem on \/dev\/datashare\/storage to 13107200 (4k) blocks.<br \/>\nThe filesystem on \/dev\/datashare\/storage is now 13107200 blocks long.<\/p>\n<p>Let is mount we will have  50 GB <\/p>\n<p>[root@localhost \/]# mount \/dev\/datashare\/storage \/storage\/<\/p>\n<p>[root@localhost \/]# df -TH<br \/>\nFilesystem    Type     Size   Used  Avail Use% Mounted on<br \/>\n\/dev\/mapper\/VolGroup-lv_root<br \/>\n              ext4      52G   2.6G    47G   6% \/<br \/>\ntmpfs        tmpfs     528M      0   528M   0% \/dev\/shm<br \/>\n\/dev\/sda1     ext4     508M    32M   450M   7% \/boot<br \/>\n\/dev\/mapper\/VolGroup-lv_home<br \/>\n              ext4      54G   189M    51G   1% \/home<br \/>\n\/dev\/mapper\/datashare-backup<br \/>\n              ext4      22G   181M    20G   1% \/backup<br \/>\n\/dev\/mapper\/datashare-servershare<br \/>\n              ext4     5.3G   145M   4.9G   3% \/servershare<br \/>\n\/dev\/mapper\/datashare-storage<br \/>\n              ext4      53G   189M    50G   1% \/storage<\/p>\n<p>Lets is Umount the backup and reduce the disk space  14G<\/p>\n<p>umount \/backup\/<\/p>\n<p>\/dev\/mapper\/datashare-backup<\/p>\n<p>e2fsck -f \/dev\/datashare\/backup<\/p>\n<p>root@localhost \/]# e2fsck -f \/dev\/datashare\/backup<br \/>\ne2fsck 1.41.12 (17-May-2010)<br \/>\nPass 1: Checking inodes, blocks, and sizes<br \/>\nPass 2: Checking directory structure<br \/>\nPass 3: Checking directory connectivity<br \/>\nPass 4: Checking reference counts<br \/>\nPass 5: Checking group summary information<br \/>\n\/dev\/datashare\/backup: 11\/1310720 files (0.0% non-contiguous), 126289\/5242880 blocks<\/p>\n<p>[root@localhost \/]# resize2fs \/dev\/datashare\/backup  3242880<br \/>\nresize2fs 1.41.12 (17-May-2010)<br \/>\nResizing the filesystem on \/dev\/datashare\/backup to 3242880 (4k) blocks.<br \/>\nThe filesystem on \/dev\/datashare\/backup is now 3242880 blocks long.<\/p>\n<p>[root@localhost \/]# lvreduce -L14G \/dev\/datashare\/backup<br \/>\n  WARNING: Reducing active logical volume to 14.00 GiB<br \/>\n  THIS MAY DESTROY YOUR DATA (filesystem etc.)<br \/>\nDo you really want to reduce backup? [y\/n]: y<br \/>\n  Reducing logical volume backup to 15.00 GiB<br \/>\n  Logical volume backup successfully resized<br \/>\n[root@localhost \/]# mount \/dev\/datashare\/backup \/backup\/<br \/>\n[root@localhost \/]# df -TH<br \/>\nFilesystem    Type     Size   Used  Avail Use% Mounted on<br \/>\n\/dev\/mapper\/VolGroup-lv_root<br \/>\n              ext4      52G   2.6G    47G   6% \/<br \/>\ntmpfs        tmpfs     528M      0   528M   0% \/dev\/shm<br \/>\n\/dev\/sda1     ext4     508M    32M   450M   7% \/boot<br \/>\n\/dev\/mapper\/VolGroup-lv_home<br \/>\n              ext4      54G   189M    51G   1% \/home<br \/>\n\/dev\/mapper\/datashare-servershare<br \/>\n              ext4     5.3G   145M   4.9G   3% \/servershare<br \/>\n\/dev\/mapper\/datashare-storage<br \/>\n              ext4      53G   189M    50G   1% \/storage<br \/>\n\/dev\/mapper\/datashare-backup<br \/>\n              ext4      14G   177M    13G   2% \/backup<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LVM<\/p>\n<p>First LVM Setup<\/p>\n<p>1) fdisk \/dev\/sdb<\/p>\n<p>WARNING: DOS-compatible mode is deprecated. It&#8217;s strongly recommended to switch off the mode (command &#8216;c&#8217;) and change display units to sectors (command &#8216;u&#8217;).<\/p>\n<p>Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-13054, default 1): Using default [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/362"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=362"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/362\/revisions"}],"predecessor-version":[{"id":363,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/362\/revisions\/363"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}