LVM test

Did some LVM test, recorded the procedure,

I have a disk having space as 160G,  showing as:

[root@localhost ~]# fdisk -l


Disk /dev/sda: 160.0 GB, 160041885696 bytes, 312581808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x210edd27


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    83891429    41944691   82  Linux swap / Solaris
/dev/sda2        83891430   167782859    41945715    7  HPFS/NTFS/exFAT
/dev/sda3       167782860   251674289    41945715    7  HPFS/NTFS/exFAT
/dev/sda4       251674290   312576704    30451207+   c  W95 FAT32 (LBA)


1, create a VG(volume group), the PE(physical extend) as 16M, name as xiongvg, then add the sda4 to the VG

[root@localhost ~]# vgcreate -s 16M xiongvg /dev/sda{1,2,3}
  Volume group "xiongvg" successfully created

[root@localhost ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "xiongvg" using metadata type lvm2

[root@localhost ~]# pvscan
  PV /dev/sda1   VG xiongvg         lvm2 [40.00 GiB / 40.00 GiB free]
  PV /dev/sda2   VG xiongvg         lvm2 [40.00 GiB / 40.00 GiB free]
  PV /dev/sda3   VG xiongvg         lvm2 [40.00 GiB / 40.00 GiB free]
  PV /dev/sda4                      lvm2 [29.04 GiB]
  Total: 4 [149.04 GiB] / in use: 3 [120.00 GiB] / in no VG: 1 [29.04 GiB]

[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               xiongvg
  System ID
  Format                lvm2
  Metadata Areas        3
  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                3
  Act PV                3
  VG Size               120.00 GiB
  PE Size               16.00 MiB
  Total PE              7680
  Alloc PE / Size       0 / 0
  Free  PE / Size       7680 / 120.00 GiB
  VG UUID               grCIPp-lbvS-OLMH-TiQO-mJ0L-zPyR-JIBjfM

[root@localhost ~]# vgextend xiongvg /dev/sda4
  Volume group "xiongvg" successfully extended
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               xiongvg
  System ID
  Format                lvm2
  Metadata Areas        4
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                4
  Act PV                4
  VG Size               149.03 GiB
  PE Size               16.00 MiB
  Total PE              9538
  Alloc PE / Size       0 / 0
  Free  PE / Size       9538 / 149.03 GiB
  VG UUID               grCIPp-lbvS-OLMH-TiQO-mJ0L-zPyR-JIBjfM


[root@localhost ~]# pvscan
  PV /dev/sda1   VG xiongvg   lvm2 [40.00 GiB / 40.00 GiB free]
  PV /dev/sda2   VG xiongvg   lvm2 [40.00 GiB / 40.00 GiB free]
  PV /dev/sda3   VG xiongvg   lvm2 [40.00 GiB / 40.00 GiB free]
  PV /dev/sda4   VG xiongvg   lvm2 [29.03 GiB / 29.03 GiB free]
  Total: 4 [149.03 GiB] / in use: 4 [149.03 GiB] / in no VG: 0 [0   ]



2, create a LV(Logical Volume), formatted as file system and mount

[root@localhost ~]# lvcreate -l 356 -n xionglv xiongvg
WARNING: ext3 signature detected on /dev/xiongvg/xionglv at offset 1080. Wipe it? [y/n] y
  Wiping ext3 signature on /dev/xiongvg/xionglv.
  Logical volume "xionglv" created
[root@localhost ~]# ll /dev/xiongvg/xionglv
lrwxrwxrwx. 1 root root 7 Sep  3 12:28 /dev/xiongvg/xionglv -> ../dm-0
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/xiongvg/xionglv
  LV Name                xionglv
  VG Name                xiongvg
  LV UUID                YDpSjy-Wo6r-JVdx-P4hc-GxNC-O4BQ-bMd9xr
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2014-09-03 12:27:52 +0800
  LV Status              available
  # open                 0
  LV Size                5.56 GiB
  Current LE             356
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

[root@localhost ~]# mkfs -t ext3 /dev/xiongvg/xionglv
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
365040 inodes, 1458176 blocks
72908 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1493172224
45 block groups
32768 blocks per group, 32768 fragments per group
8112 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736


Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[root@localhost ~]# mkdir /mnt/lvm

[root@localhost ~]# mount /dev/xiongvg/xionglv /mnt/lvm



[root@localhost ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/sdb7                     36G  7.7G   26G  23% /
devtmpfs                     908M     0  908M   0% /dev
tmpfs                        916M   92K  916M   1% /dev/shm
tmpfs                        916M  9.0M  907M   1% /run
tmpfs                        916M     0  916M   0% /sys/fs/cgroup
/dev/sdb6                    190M  169M  7.1M  96% /boot
/dev/mapper/xiongvg-xionglv  5.4G   12M  5.1G   1% /mnt/lvm

3, LV size enlarge, LV size reduce

[root@localhost ~]# lvresize -l +179 /dev/xiongvg/xionglv
  Extending logical volume xionglv to 8.36 GiB
  Logical volume xionglv successfully resized

[root@localhost ~]# df /mnt/lvm
Filesystem                  1K-blocks  Used Available Use% Mounted on
/dev/mapper/xiongvg-xionglv   5609948 11516   5290416   1% /mnt/lvm

make change to the file system,



[root@localhost ~]# resize2fs /dev/xiongvg/xionglv
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/xiongvg/xionglv is mounted on /mnt/lvm; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/xiongvg/xionglv is now 2191360 blocks long.


[root@localhost ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/sdb7                     36G  7.7G   26G  23% /
devtmpfs                     908M     0  908M   0% /dev
tmpfs                        916M   92K  916M   1% /dev/shm
tmpfs                        916M  9.0M  907M   1% /run
tmpfs                        916M     0  916M   0% /sys/fs/cgroup
/dev/sdb6                    190M  169M  7.1M  96% /boot
/dev/mapper/xiongvg-xionglv  8.2G   13M  7.7G   1% /mnt/lvm
[root@localhost ~]#



[root@localhost ~]# resize2fs /dev/xiongvg/xionglv 6900M
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/xiongvg/xionglv is mounted on /mnt/lvm; on-line resizing required
resize2fs: On-line shrinking not supported
[root@localhost ~]# umount /mnt/lvm
[root@localhost ~]# resize2fs /dev/xiongvg/xionglv 6900M
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/xiongvg/xionglv' first.


[root@localhost ~]# e2fsck -f /dev/xiongvg/xionglv
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/xiongvg/xionglv: 11/543504 files (0.0% non-contiguous), 70123/2191360 blocks
[root@localhost ~]# resize2fs /dev/xiongvg/xionglv 6900M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/xiongvg/xionglv to 1766400 (4k) blocks.
The filesystem on /dev/xiongvg/xionglv is now 1766400 blocks long.


[root@localhost ~]# mount /dev/xiongvg/xionglv /mnt/lvm



[root@localhost ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/sdb7                     36G  7.7G   26G  23% /
devtmpfs                     908M     0  908M   0% /dev
tmpfs                        916M   92K  916M   1% /dev/shm
tmpfs                        916M  9.0M  907M   1% /run
tmpfs                        916M     0  916M   0% /sys/fs/cgroup
/dev/sdb6                    190M  169M  7.1M  96% /boot
/dev/mapper/xiongvg-xionglv  6.6G   13M  6.2G   1% /mnt/lvm



你可能感兴趣的:(Linux,lvm,linux,logic,volume)