工作,学习,生活,这里将会有一些记录. 备用域名:http://meisw.wdlinux.cn 注册 | 登陆

创建LVM卷

7.6.2 创建LVM卷

首先,用fdisk命令创建存储设备的物理分区,供创建逻辑分区之用。我们用的是一款32 MB的U盘,设备名为/dev/sdb:

  1. # fdisk /dev/sdb                启动管理磁盘分区的命令  
  2. Command (m for help): p         显示当前分区(未分区)  
  3.  
  4. Disk /dev/sdb: 32 MB, 32112128 bytes  
  5. 1 heads, 62 sectors/track, 1011 cylinders  
  6. Units = cylinders of 62 * 512 = 31744 bytes  
  7.  
  8.    Device Boot      Start         End      Blocks   Id  System  
  9.  
  10. Command (m for help): n         创建新分区  
  11. Command action  
  12.    e   extended  
  13.    p   primary partition (1-4)  
  14. p                               设置成主分区  
  15. Partition number (1-4): 1       指定为分区1 
  16. First cylinder (2-1011default 2): Enter  
  17. Using default value 2 
  18. Last cylinder or +size or +sizeM or +sizeK (2-1011default 1011): Enter  
  19. Using default value 1011 
  20.  
  21. Command (m for help): t                指定分区类型  
  22. Selected partition 1 
  23. Hex code (type L to list codes): 8E    设成8E(LVM分区)  
  24. Changed system type of partition 1 to 8e (Linux LVM)  
  25. Command (m for help): p                键入p查看新建分区  
  26. Disk /dev/sdb: 32 MB, 32112128 bytes  
  27. 1 heads, 62 sectors/track, 1011 cylinders  
  28. Units = cylinders of 62 * 512 = 31744 bytes  
  29.  
  30. Device Boot      Start         End      Blocks   Id  System  
  31. /dev/sdb1        2             1011     31310    8e  Linux LVM 

继续下一步操作之前,先确认对相应分区的修改正确无误。如果一切妥当,则写入新分区表,如下所示:

  1. Command (m for help): w  
  2. The partition table has been altered!  
  3. Calling ioctl() to re-read partition table.  
  4. Syncing disks.  
  5. #  

回到shell提示符,使用sfdisk命令查看U盘分区情况:

  1. # sfdisk -l /dev/sdb      查看LVM分区  
  2.  
  3. Disk /dev/sdb: 1011 cylinders, 1 heads, 62 sectors/track  
  4. Units = cylinders of 31744 bytes, blocks of 1024 bytes, counting from 0 
  5.  
  6.    Device Boot Start     End   #cyls    #blocks   Id  System  
  7. /dev/sdb1          1    1010    1010      31310   8e  Linux LVM  
  8. /dev/sdb2          0       -       0          0    0  Empty  
  9. /dev/sdb3          0       -       0          0    0  Empty  
  10. /dev/sdb4          0       -       0          0    0  Empty 

下一步,将/dev/sdb1制作成新的LVM物理卷,并使用pvs命令查看物理LVM卷相关信息:

  1. # pvcreate /dev/sdb1           将sdb1制作成LVM物理卷  
  2.   Physical volume "/dev/sdb1" successfully created  
  3. # pvs                          查看物理LVM分区  
  4.   PV         VG     Fmt  Attr PSize  PFree  
  5.   /dev/sdb1  vgusb  lvm2 a-   28.0020.00M  
  6.  
  7. 下面使用vgcreate创建vgusb卷组,并列出当前活跃的卷组:  
  8.  
  9. $ vgcreate vgusb /dev/sdb1        创建vgusb卷组  
  10.   Volume group "vgusb" successfully created  
  11. $ vgs                             查看当前卷组  
  12.   VG     #PV #LV #SN Attr   VSize  VFree  
  13.   vgusb    1   0   0 wz--n- 28.0028.00

使用lvcreate在vgusb卷组里新建一个10M大小的LVM分区。然后,用lvs查看逻辑卷,用vgs查看空闲空间的大小变化:

  1. $ lvcreate --size 10M --name lvm_u1 vgusb
  2. Rounding up size to full physical extent 12.00 MB
  3. Logical volume "lvm_u1" created
  4. $ lvs 查看逻辑卷信息
  5. LV VG Attr LSize Origin Snap% Move Log Copy%
  6. lvm_u1 vgusb -wi-a- 12.00M
  7. $ vgs 发现卷组仍有16M空闲空间
  8. VG #PV #LV #SN Attr VSize VFree
  9. vgusb 1 1 0 wz--n- 28.00M 16.00M

使用mkfs.ext3命令在lvm分区上创建ext3文件系统,示例如下:

  1. $ mkfs.ext3 /dev/mapper/vgusb-lvm_u1
  2. mke2fs 1.38 (30-Jun-2005)
  3. Filesystem label=
  4. OS type: Linux
  5. Block size=1024 (log=0)
  6. Fragment size=1024 (log=0)
  7. 3072 inodes, 12288 blocks
  8. 614 blocks (5.00%) reserved for the super user
  9. First data block=1
  10. Maximum filesystem blocks=12582912
  11. 2 block groups
  12. 8192 blocks per group, 8192 fragments per group
  13. 1536 inodes per group
  14. Superblock backups stored on blocks:
  15. 8193
  16. Writing inode tables: done
  17. Creating journal (1024 blocks): done
  18. Writing superblocks and filesystem accounting information: done
  19. This filesystem will be automatically checked every 35 mounts or
  20. 180 days, whichever comes first. Use tune2fs -c or -i to override.

至此,ext3文件系统创建完毕,该LVM卷已准备就绪。

« 上一篇 | 下一篇 »

Trackbacks

点击获得Trackback地址,Encode: UTF-8

发表评论

评论内容 (必填):