Saturday, April 5, 2014

Use LVM to create file system on CentOS

[root@centos ~]# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cb3f1

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        1045     7875584   8e  Linux LVM

Disk /dev/sdb: 268 MB, 268435456 bytes
255 heads, 63 sectors/track, 32 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/sdc: 268 MB, 268435456 bytes
255 heads, 63 sectors/track, 32 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_centos-lv_root: 7205 MB, 7205814272 bytes
255 heads, 63 sectors/track, 876 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_centos-lv_swap: 855 MB, 855638016 bytes
255 heads, 63 sectors/track, 104 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Use the whole disk to create PV physical volume

[root@centos ~]# pvcreate -f /dev/sdb
  Physical volume "/dev/sdb" successfully created
[root@centos ~]# pvdisplay /dev/sdb
  "/dev/sdb" is a new physical volume of "256.00 MiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name
  PV Size               256.00 MiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               K98U9x-b5pF-qeZx-h0US-f3qA-zjiu-ZBsFHe

[root@centos ~]# pvs
  PV         VG        Fmt  Attr PSize   PFree
  /dev/sda2  vg_centos lvm2 a--    7.51g      0
  /dev/sdb             lvm2 a--  256.00m 256.00m

Create another PV physical volume

[root@centos ~]# pvcreate -f /dev/sdc
  Physical volume "/dev/sdc" successfully created
[root@centos ~]# pvdisplay /dev/sdc
  "/dev/sdc" is a new physical volume of "256.00 MiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc
  VG Name
  PV Size               256.00 MiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               cWtHVh-I6d9-vXGg-CD46-rk8U-9q8o-tlmIjx

[root@centos ~]# pvs
  PV         VG        Fmt  Attr PSize   PFree
  /dev/sda2  vg_centos lvm2 a--    7.51g      0
  /dev/sdb             lvm2 a--  256.00m 256.00m
  /dev/sdc             lvm2 a--  256.00m 256.00m

Now PVs are ready. We can create VG volume group.

[root@centos ~]# vgcreate vg1 /dev/sdb /dev/sdc
  Volume group "vg1" successfully created
[root@centos ~]# vgdisplay -v vg1
    Using volume group(s) on command line
    Finding volume group "vg1"
  --- Volume group ---
  VG Name               vg1
  System ID
  Format                lvm2
  Metadata Areas        2
  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                2
  Act PV                2
  VG Size               504.00 MiB
  PE Size               4.00 MiB
  Total PE              126
  Alloc PE / Size       0 / 0
  Free  PE / Size       126 / 504.00 MiB
  VG UUID               DAuthU-edqB-OPpM-KdZn-OqLM-HsxI-OhNnrA

  --- Physical volumes ---
  PV Name               /dev/sdb
  PV UUID               K98U9x-b5pF-qeZx-h0US-f3qA-zjiu-ZBsFHe
  PV Status             allocatable
  Total PE / Free PE    63 / 63

  PV Name               /dev/sdc
  PV UUID               cWtHVh-I6d9-vXGg-CD46-rk8U-9q8o-tlmIjx
  PV Status             allocatable
  Total PE / Free PE    63 / 63

[root@centos dev]# vgs
  VG        #PV #LV #SN Attr   VSize   VFree
  vg1         2   0   0 wz--n- 504.00m 504.00m
  vg_centos   1   2   0 wz--n-   7.51g      0

Now create mirrored LV logical volume

[root@centos dev]# lvcreate -L 50M -m 1 -n lvol1 vg1
  Rounding up size to full physical extent 52.00 MiB
  Logical volume "lvol1" created

[root@centos dev]# lvs
  LV      VG        Attr       LSize   Pool Origin Data%  Move Log        Cpy%Sync Convert
  lvol1   vg1       mwi-a-m---  52.00m                         lvol1_mlog   100.00
  lv_root vg_centos -wi-ao----   6.71g                                          
  lv_swap vg_centos -wi-ao---- 816.00m                                          

[root@centos dev]# lvdisplay -v /dev/vg1/lvol1
    Using logical volume(s) on command line
  --- Logical volume ---
  LV Path                /dev/vg1/lvol1
  LV Name                lvol1
  VG Name                vg1
  LV UUID                4YGNqt-VcUr-kvec-AV9N-9nBR-HLGR-96Q8bi
  LV Write Access        read/write
  LV Creation host, time centos, 2014-04-05 13:10:09 -0400
  LV Status              available
  # open                 0
  LV Size                52.00 MiB
  Current LE             13
  Mirrored volumes       2
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:5

lrwxrwxrwx. 1 root root 7 Apr  5 13:17 /dev/vg1/lvol1 -> ../dm-5

[root@centos dev]# ls -ld /dev/dm-5
brw-rw----. 1 root disk 253, 5 Apr  5 13:17 /dev/dm-5  (block special device node)


[root@centos dev]# mkfs -t ext3 /dev/vg1/lvol1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
13328 inodes, 53248 blocks
2662 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=54525952
7 block groups
8192 blocks per group, 8192 fragments per group
1904 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Now mount the file system

vi /etc/fstab and add the following line :
/dev/vg1/lvol1          /ap1                    ext3    defaults        0 0


[root@centos dev]# mkdir /ap1
[root@centos dev]# mount /ap1
[root@centos dev]# df -h /ap1
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/vg1-lvol1   51M  4.9M   43M  11% /ap1

Check the output from tune2fs

# tune2fs -l /dev/mapper/vg1-lvol1
tune2fs 1.41.12 (17-May-2010)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          83def42c-7412-4115-ae58-2c34acefb1db
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery sparse_super
Filesystem flags:         signed_directory_hash
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              13328
Block count:              53248
Reserved block count:     2662
Free blocks:              46604
Free inodes:              13317
First block:              1
Block size:               1024
Fragment size:            1024
Reserved GDT blocks:      207
Blocks per group:         8192
Fragments per group:      8192
Inodes per group:         1904
Inode blocks per group:   238
Filesystem created:       Sat Apr  5 13:17:10 2014
Last mount time:          Sat Apr  5 13:24:32 2014
Last write time:          Sat Apr  5 13:24:32 2014
Mount count:              1 (-C mount-count)
Maximum mount count:      26 (-c max-mount-counts)
Last checked:             Sat Apr  5 13:17:10 2014
Check interval:           15552000 (6 months)
Next check after:         Thu Oct  2 13:17:10 2014
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               128
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      c0487ec4-6718-4ec5-b761-c6308d0c3c18
Journal backup:           inode blocks



No comments:

Post a Comment