ITPub博客

首页 > Linux操作系统 > Linux操作系统 > LV使用详解

LV使用详解

原创 Linux操作系统 作者:SUNBLAZE 时间:2010-08-27 15:22:06 0 删除 编辑
Last login: Thu Aug 26 09:41:01 2010

--建立PV
[root@sunblaze ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created
[root@sunblaze ~]# pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created
 
[root@sunblaze ~]# vgcreate test_vg /dev/sdb /dev/sdc
  Volume group "test_vg" successfully created
[root@sunblaze ~]# vgdisplay test_vg
  --- Volume group ---
  VG Name               test_vg
  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               9.99 GB
  PE Size               4.00 MB
  Total PE              2558
  Alloc PE / Size       0 / 0  
  Free  PE / Size       2558 / 9.99 GB
  VG UUID               LgzO5P-bxEs-qSWR-OZhe-lZBj-FXw1-hRV86Q
   --创建VG
[root@sunblaze ~]# vgchange -a y  test_vg
  0 logical volume(s) in volume group "test_vg" now active
[root@sunblaze ~]# vg
vgcfgbackup   vgchange      vgconvert     vgdisplay     vgextend      vgmerge       vgreduce      vgrename      vgscan
vgcfgrestore  vgck          vgcreate      vgexport      vgimport      vgmknodes     vgremove      vgs           vgsplit
-- 创建lv 驴。。
[root@sunblaze ~]# lvcreate -n lv_test -L 1024M test_vg ;
  Logical volume "lv_test" created
[root@sunblaze ~]# ls /dev/test_vg/
lv_test
[root@sunblaze ~]# ls -l /dev/test_vg/
total 0
lrwxrwxrwx  1 root root 27 Aug 26 10:25 lv_test -> /dev/mapper/test_vg-lv_test
格式化后即可使用
[root@sunblaze ~]# mkfs.ext3 /dev/test_vg/lv_test
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
131072 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

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

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@sunblaze ~]# ll
total 34228
-rw-r--r--  1 root root     1241 Oct  9  2009 anaconda-ks.cfg
drwxr-xr-x  2 root root     4096 Oct 10  2009 Desktop
-rw-r--r--  1 root root    53419 Oct  9  2009 install.log
-rw-r--r--  1 root root    41299 Oct  9  2009 install.log.syslog
-r--r--r--  1 root root 17630341 May 10  2008 VMwareTools-1.0.6-91891.i386.rpm
-r--r--r--  1 root root 17234767 May 10  2008 VMwareTools-1.0.6-91891.tar.gz
drwxr-xr-x  7 root root     4096 May 10  2008 vmware-tools-distrib
[root@sunblaze ~]# mkdir /test_vg-folder
--挂载一下。当然如想永久挂载,还是编辑/etc/fstab
[root@sunblaze ~]# mount /test_vg-folder/ /dev/test_vg/lv_test
mount: /test_vg-folder/ is not a block device
[root@sunblaze ~]# mount  /dev/test_vg/lv_test  /test_vg-folder/
[root@sunblaze ~]# cd /test_vg-folder/
[root@sunblaze test_vg-folder]# ll
total 16
drwx------  2 root root 16384 Aug 26 10:28 lost+found
[root@sunblaze test_vg-folder]# touch aaaa.txt
[root@sunblaze test_vg-folder]# ll
total 16
-rw-r--r--  1 root root     0 Aug 26 10:30 aaaa.txt
drwx------  2 root root 16384 Aug 26 10:28 lost+found
[root@sunblaze test_vg-folder]# vi aaaa.txt

dsaiasdasdadadada
~                                                                                                                                  
~                                                                                                                                  
~                                                                                                                                  
                                                                                                      
~                                                                                                                                  
"aaaa.txt" 1L, 18C written                                                                                       
[root@sunblaze test_vg-folder]# ll
total 20
-rw-r--r--  1 root root    18 Aug 26 10:30 aaaa.txt
drwx------  2 root root 16384 Aug 26 10:28 lost+found
[root@sunblaze test_vg-folder]# lvdisplay /dev/test_vg/lv_test
  --- Logical volume ---
  LV Name                /dev/test_vg/lv_test
  VG Name                test_vg
  LV UUID                XdCaDR-p900-i9fA-jc3c-y7nc-KcDE-ltRnKy
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.00 GB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0
扩展LV大小
[root@sunblaze test_vg-folder]# lvextend -L 2G /dev/test_vg/lv_test
  Extending logical volume lv_test to 2.00 GB
  Logical volume lv_test successfully resized
[root@sunblaze test_vg-folder]# lvdisplay  /dev/test_vg/lv_test
  --- Logical volume ---
  LV Name                /dev/test_vg/lv_test
  VG Name                test_vg
  LV UUID                XdCaDR-p900-i9fA-jc3c-y7nc-KcDE-ltRnKy
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                2.00 GB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0
  
[root@sunblaze test_vg-folder]# l
-bash: l: command not found
[root@sunblaze test_vg-folder]# ll
total 20
-rw-r--r--  1 root root    18 Aug 26 10:30 aaaa.txt
drwx------  2 root root 16384 Aug 26 10:28 lost+found

[root@sunblaze test_vg-folder]# cd /
[root@sunblaze /]# umount  /test_vg-folder/

如要减小已分配的LV空间,需要先行卸载
警告:缩小空间可能造成数据丢失。所以需要先行备份。
[root@sunblaze /]# ls
bin   dev  home    lib         media  mnt  proc  sbin     srv  test_vg-folder  usr
boot  etc  initrd  lost+found  misc   opt  root  selinux  sys  tmp             var
[root@sunblaze /]# lvreduce /dev/test_vg/lv_test -L 500M
  WARNING: Reducing active logical volume to 500.00 MB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_test? [y/n]: y
  Reducing logical volume lv_test to 500.00 MB
  Logical volume lv_test successfully resized
[root@sunblaze /]# lvdisplay  /dev/test_vg/lv_test
  --- Logical volume ---
  LV Name                /dev/test_vg/lv_test
  VG Name                test_vg
  LV UUID                XdCaDR-p900-i9fA-jc3c-y7nc-KcDE-ltRnKy
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                500.00 MB
  Current LE             125
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0
  
[root@sunblaze /]# mount /dev/
Display all 273 possibilities? (y or n)
[root@sunblaze /]# mount /dev/test_vg/lv_test /test_vg-folder/
[root@sunblaze /]# cd /etc/
[root@sunblaze etc]# cd ..
[root@sunblaze /]# cd /test_vg-folder/
[root@sunblaze test_vg-folder]# ll
total 20
-rw-r--r--  1 root root    18 Aug 26 10:30 aaaa.txt
drwx------  2 root root 16384 Aug 26 10:28 lost+found
[root@sunblaze test_vg-folder]# vi aaaa.txt

dsaiasdasdadadada
~                                                                                                                                  
~                                                                                                                                  
 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12474069/viewspace-672000/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: TOP 命令实解
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2008-08-22

  • 博文量
    35
  • 访问量
    88066