设为首页 收藏本站
查看: 1218|回复: 0

[经验分享] Linux 逻辑卷LVM创建扩展删除实例

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-12-30 10:47:19 | 显示全部楼层 |阅读模式
我这里用sdb这个20G的硬盘创建四个5G分区,并使用这四个分区创建test_lvm卷组,最后从卷组中创建两个8G的逻辑卷test_web和test_data.
详细步骤:需要操作和注意的内容均已用深色标注
1,首先对sdb创建分区
[iyunv@localhost ~]# fdisk -l    #查看磁盘分区
Disk /dev/sdb: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000a25c6
   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          13      102400   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              13         274     2097152   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             274        2611    18770944   83  Linux
[iyunv@localhost ~]# fdisk /dev/sdb    #对sdb进行分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7c32b0fe.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): n

Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5G

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (655-2610, default 655):
Last cylinder, +cylinders or +size{K,M,G} (655-2610, default 2610): +5G

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1309-2610, default 1309):
Using default value 1309
Last cylinder, +cylinders or +size{K,M,G} (1309-2610, default 2610): +5G

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Selected partition 4
First cylinder (1963-2610, default 1963):
Using default value 1963
Last cylinder, +cylinders or +size{K,M,G} (1963-2610, default 2610):
Using default value 2610

Command (m for help): n
First cylinder (1963-2610, default 1963):
Using default value 1963
Last cylinder, +cylinders or +size{K,M,G} (1963-2610, default 2610): +5G
Using default value 2610

Command (m for help): t        
Partition number (1-5): 1        #指定分区编号
Hex code (type L to list codes): 8e    #修改分区标签为LVM
Changed system type of partition 1 to 8e (Linux LVM)
(四个分区都要修改标签为LVM,8e代表是lvm)
Command (m for help): t
Partition number (1-5): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): t
Partition number (1-5): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)

Command (m for help): p    #查看分区情况

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x7c32b0fe
   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         654     5253223+  8e  Linux LVM
/dev/sdb2             655        1308     5253255   8e  Linux LVM
/dev/sdb3            1309        1962     5253255   8e  Linux LVM
/dev/sdb4            1963        2610     5205060    5  Extended
/dev/sdb5            1963        2610     5205028+  8e  Linux LVM

Command (m for help): w    #保存分区
The partition table has been altered!
Calling ioctl() to re-read partition table.

Syncing disks.

[iyunv@localhost ~]# yum -y install parted (安装part命令)
[iyunv@localhost ~]# partprobe /dev/sdb     #让内核读取新的分区表
[iyunv@localhost ~]# yum install lvm-common lvm2 evms     #安装lvm命令包

[iyunv@localhost ~]# pvcreate /dev/sdb{1,2,3,5}     #初始化分区
  Physical volume "/dev/sdb1" successfully created
  Physical volume "/dev/sdb2" successfully created
  Physical volume "/dev/sdb3" successfully created
  Physical volume "/dev/sdb5" successfully created
[iyunv@localhost ~]# pvdisplay            #查看初始化状态
  "/dev/sdb1" is a new physical volume of "5.01 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               5.01 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               TEc8TG-gvFL-6HRW-Pzds-pgz4-yUat-JVKh9l
    .......

[iyunv@localhost ~]# vgcreate test_lvm /dev/sdb{1,2,3,5}    #创建test_lvm卷组
  Volume group "test_lvm" successfully created
[iyunv@localhost ~]# vgdisplay        #查看创建的卷组
  --- Volume group ---
  VG Name               test_lvm
  System ID            
  Format                lvm2
  Metadata Areas        4
  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                4
  Act PV                4
  VG Size               19.98 GiB
  PE Size               4.00 MiB
  Total PE              5116
  Alloc PE / Size       0 / 0   
  Free  PE / Size       5116 / 19.98 GiB
  VG UUID               Ds6v3E-0tfi-p5Pm-0s8H-BMoU-LhDu-WmwW2V
[iyunv@localhost ~]# lvcreate -L 8G -n test_web test_lvm    #创建test_web逻辑卷,8G

  Logical volume "test_web" created.
[iyunv@localhost ~]# lvcreate -L 8G -n test_data test_lvm   #创建test_data逻辑卷,8G
  Logical volume "test_data" created.
[iyunv@localhost ~]# lvdisplay        #查看创建的逻辑卷
  --- Logical volume ---
  LV Path                /dev/test_lvm/test_web
  LV Name                test_web
  VG Name                test_lvm
  LV UUID                ZwkBV8-LOWR-GGk7-643t-Ne15-557M-vwxc08
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-12-29 05:27:48 +0800
  LV Status              available
  # open                 0
  LV Size                8.00 GiB
  Current LE             2048
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
    --- Logical volume ---
  LV Path                /dev/test_lvm/test_data
  LV Name                test_data
  VG Name                test_lvm
  LV UUID                mxI9hQ-79uP-R0fw-McA7-483X-TPXf-0ELTdo
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-12-29 05:28:12 +0800
  LV Status              available
  # open                 0
  LV Size                8.00 GiB
  Current LE             2048
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
[iyunv@localhost ~]# mkfs.ext4 /dev/test_lvm/test_web     #格式化逻辑卷

mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2097152 blocks
104857 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
正在写入inode表: 完成                           

Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 38 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.
[iyunv@localhost ~]# mkfs.ext4 /dev/test_lvm/test_data     #格式化逻辑卷
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2097152 blocks
104857 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
正在写入inode表: 完成                           

Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 37 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.
[iyunv@localhost ~]# mkdir -p /web        #创建挂载点
[iyunv@localhost ~]# mkdir -p /data         #创建挂载点
[iyunv@localhost ~]# mount /dev/test_lvm/test_web /web    #挂载逻辑卷
[iyunv@localhost ~]# mount /dev/test_lvm/test_data /data/    #挂载逻辑卷
[iyunv@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  992M   16G   6% /
tmpfs                 491M     0  491M   0% /dev/shm
/dev/sda1              93M   27M   62M  31% /boot
/dev/mapper/test_lvm-test_web
                      7.8G   18M  7.4G   1% /web
/dev/mapper/test_lvm-test_data
7.8G   18M  7.4G   1% /data
增大逻辑卷
[iyunv@localhost ~]# lvextend -L +2G /dev/test_lvm/test_web    #扩大逻辑卷,加2G
  Size of logical volume test_lvm/test_web changed from 8.00 GiB (2048 extents) to 10.00 GiB (2560 extents).
  Logical volume test_web successfully resized.
[iyunv@localhost ~]# resize2fs /dev/test_lvm/test_web     #格式化增大的逻辑卷
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/test_lvm/test_web is mounted on /web; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/test_lvm/test_web to 2621440 (4k) blocks.
The filesystem on /dev/test_lvm/test_web is now 2621440 blocks long.

[iyunv@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  992M   16G   6% /
tmpfs                 491M     0  491M   0% /dev/shm
/dev/sda1              93M   27M   62M  31% /boot
/dev/mapper/test_lvm-test_web
                      9.8G   18M  9.3G   1% /web
/dev/mapper/test_lvm-test_data
                      7.8G   18M  7.4G   1% /data

删除LVM分区
[iyunv@localhost ~]# umount /dev/test_lvm/test_web     #卸载逻辑卷
[iyunv@localhost ~]# umount /dev/test_lvm/test_data
[iyunv@localhost ~]# lvremove /dev/test_lvm/test_web     #删除逻辑卷
Do you really want to remove active logical volume test_web? [y/n]: y
  Logical volume "test_web" successfully removed
[iyunv@localhost ~]# lvremove /dev/test_lvm/test_data
Do you really want to remove active logical volume test_data? [y/n]: y
  Logical volume "test_data" successfully removed
[iyunv@localhost ~]# vgremove test_lvm            #删除卷组
  Volume group "test_lvm" successfully removed
[iyunv@localhost ~]# pvremove /dev/sdb{1,2,3,5}        #去除PV还原磁盘
  Labels on physical volume "/dev/sdb1" successfully wiped
  Labels on physical volume "/dev/sdb2" successfully wiped
  Labels on physical volume "/dev/sdb3" successfully wiped
  Labels on physical volume "/dev/sdb5" successfully wiped



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-321570-1-1.html 上篇帖子: EP-DB1608无线网卡安装linux驱动 下篇帖子: 关于paramiko使用的问题 Linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表