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

[经验分享] RedHat扩容LVM下的/根目录

[复制链接]

尚未签到

发表于 2018-5-13 08:24:40 | 显示全部楼层 |阅读模式
  转载自http://blogold.chinaunix.net/u3/93765/showart_2082034.html
  

  图形,命令方式LVM下扩展/根目录、命令方式建立VG和LV、动态扩容VG大小、删除VG  注意:此种扩容/的根目录的前提是分区必须采用LVM格式完成,此次实验系统为redhat 4
实验目的:对/根目录进行扩容,由原来的4.8G扩容到5.3G,增加500MB的空间  分区规划:boot        150MB
  /           5000MB        rootlv
  home        500MB         homelv
  swap        500MB         swaplv
一、如下是安装系统时如何按照LVM方式进行分区的关键几步,其他的安装步骤和正常系统安装一样  二、通过系统自带的逻辑卷管理器进行查看LVM的详细信息
三、通过命令方式来对/目录进行扩容500MB测试
[root@localhost ~]# df -h


  Filesystem           >  /dev/mapper/rootvg-rootlv
  4.8G  3.0G  1.6G  66% /
  /dev/sda1             145M   14M  124M  10% /boot
  none                  125M     0  125M   0% /dev/shm
  /dev/mapper/rootvg-homelv
  465M   11M  431M   3% /home
[root@localhost ~]# fdisk -l

  Disk /dev/sda: 8589 MB, 8589934592 bytes
  255 heads, 63 sectors/track, 1044 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start         End      Blocks  >  /dev/sda1   *           1          19      152586   83  Linux
  /dev/sda2              20         401     3068415   8e  Linux LVM
  /dev/sda3             402         720     2562367+  8e  Linux LVM
  /dev/sda4             721        1044     2602530    5  Extended
  /dev/sda5             721         975     2048256   8e  Linux LVM
[root@localhost /]# lvextend -L +500M /dev/mapper/rootvg-rootlv


  Rounding up>  Extending logical volume rootlv to 5.38 GB
  Logical volume rootlv successfully resized
[root@localhost /]# ext2online /dev/mapper/rootvg-rootlv

  ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b
[root@localhost /]# df -h
  Filesystem           >  /dev/mapper/rootvg-rootlv
  5.3G  3.0G  2.1G  60% /
  /dev/sda1             145M   14M  124M  10% /boot
  none                  125M     0  125M   0% /dev/shm
  /dev/mapper/rootvg-homelv
  465M   11M  431M   3% /home
[root@localhost /]# fdisk -l  Disk /dev/sda: 8589 MB, 8589934592 bytes
  255 heads, 63 sectors/track, 1044 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start         End      Blocks  >  /dev/sda1   *           1          19      152586   83  Linux
  /dev/sda2              20         401     3068415   8e  Linux LVM
  /dev/sda3             402         720     2562367+  8e  Linux LVM
  /dev/sda4             721        1044     2602530    5  Extended
  /dev/sda5             721         975     2048256   8e  Linux LVM
  四、通过图形界面来对/根目录进行扩容500MB测试
[root@localhost ~]# df -h


  Filesystem           >  /dev/mapper/rootvg-rootlv
  5.3G  3.0G  2.1G  60% /
  /dev/sda1             145M   14M  124M  10% /boot
  none                  125M     0  125M   0% /dev/shm
  /dev/mapper/rootvg-homelv
  465M   11M  431M   3% /home
[root@localhost ~]# df -h
  Filesystem           >  /dev/mapper/rootvg-rootlv
  5.8G  3.0G  2.5G  55% /
  /dev/sda1             145M   14M  124M  10% /boot
  none                  125M     0  125M   0% /dev/shm
  /dev/mapper/rootvg-homelv
  465M   11M  431M   3% /home
  五、通过命令方式建立新LVM的文件系统/jiajia和卷组jiajiavg,大小为200MB,主要步骤见下面红色字体
[root@localhost ~]# fdisk /dev/sda

  The number of cylinders for this disk is set to 1044.
  There is nothing wrong with that, but this is larger than 1024,
  and could in certain setups cause problems with:
  1) software that runs at boot time (e.g., old versions of LILO)
  2) booting and partitioning software from other OSs
  (e.g., DOS FDISK, OS/2 FDISK)
  Command (m for help): m
  Command action
  a   toggle a bootable flag
  b   edit bsd disklabel
  c   toggle the dos compatibility flag
  d   delete a partition
  l   list known partition types
  m   print this menu
  n   add a new partition
  o   create a new empty DOS partition table
  p   print the partition table
  q   quit without saving changes
  s   create a new empty Sun disklabel

  t   change a partition's system>  u   change display/entry units
  v   verify the partition table
  w   write table to disk and exit
  x   extra functionality (experts only)
Command (m for help): n  First cylinder (976-1044, default 976):
  Using default value 976
  Last cylinder or +size or +sizeM or +sizeK (976-1044, default 1044): +200M
  Command (m for help): p
  Disk /dev/sda: 8589 MB, 8589934592 bytes
  255 heads, 63 sectors/track, 1044 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start         End      Blocks  >  /dev/sda1   *           1          19      152586   83  Linux
  /dev/sda2              20         401     3068415   8e  Linux LVM
  /dev/sda3             402         720     2562367+  8e  Linux LVM
  /dev/sda4             721        1044     2602530    5  Extended
  /dev/sda5             721         975     2048256   8e  Linux LVM
  /dev/sda6             976        1000      200781   83  Linux
Command (m for help): t  Partition number (1-6): 6
  Hex code (type L to list codes): 8e
  Changed system type of partition 6 to 8e (Linux LVM)
  Command (m for help): p
  Disk /dev/sda: 8589 MB, 8589934592 bytes
  255 heads, 63 sectors/track, 1044 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start         End      Blocks  >  /dev/sda1   *           1          19      152586   83  Linux
  /dev/sda2              20         401     3068415   8e  Linux LVM
  /dev/sda3             402         720     2562367+  8e  Linux LVM
  /dev/sda4             721        1044     2602530    5  Extended
  /dev/sda5             721         975     2048256   8e  Linux LVM
  /dev/sda6             976        1000      200781   8e  Linux LVM
Command (m for help): w
  The partition table has been>  Calling ioctl() to re-read partition table.
  WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
  The kernel still uses the old table.
  The new table will be used at the next reboot.
  Syncing disks.
[root@localhost ~]# partprobe             ---使得上面的设置生效,而无需要重启系统

[root@localhost ~]# pvcreate /dev/sda6    ---将/dev/sda6转换成PV

  Physical volume "/dev/sda6" successfully created
[root@localhost ~]# pvdisplay /dev/sda6   ---检查新PV的详细信息

  "/dev/sda6" is a new physical volume of "196.08 MB"
  --- NEW Physical volume ---
  PV Name               /dev/sda6
  VG Name

  PV>  Allocatable           NO

  PE>  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               lICdJx-KJAP-SO33-unmJ-ox4x-eR1Z-GJvn0z
[root@localhost ~]# vgcreate jiajiavg /dev/sda6     ---创建卷组,并将逻辑卷/dev/sda6加入到该卷组jiajiavg中

  Volume group "jiajiavg" successfully created
[root@localhost ~]# vgdisplay jiajiavg

  --- Volume group ---
  VG Name               jiajiavg

  System>  Format                lvm2
  Metadata Areas        1
  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                1
  Act PV                1

  VG>
  PE>  Total PE              48

  Alloc PE />
  Free  PE />  VG UUID               is2u3L-G9F1-Bnrc-9rPM-1DFm-WDSD-wLog9u
[root@localhost ~]# lvcreate -L 150M -n lvjiajia jiajiavg          ---从卷组jiajiavg中分出150M出来给LV,名为lvjiajia


  Rounding up>  Logical volume "lvjiajia" created
[root@localhost ~]# lvdisplay /dev/jiajiavg/lvjiajia

  --- Logical volume ---
  LV Name                /dev/jiajiavg/lvjiajia
  VG Name                jiajiavg
  LV UUID                ECAEFu-Pyr3-wkEI-27AE-lYXp-xIWk-1WVI5x
  LV Write Access        read/write
  LV Status              available
  # open                 0

  LV>  Current LE             38
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3
[root@localhost ~]# mke2fs -j /dev/jiajiavg/lvjiajia      ---将lvjiajia格式化掉

  mke2fs 1.35 (28-Feb-2004)
  Filesystem label=
  OS type: Linux

  Block>
  Fragment>  38912 inodes, 155648 blocks
  7782 blocks (5.00%) reserved for the super user
  First data block=1
  Maximum filesystem blocks=67371008
  19 block groups
  8192 blocks per group, 8192 fragments per group
  2048 inodes per group
  Superblock backups stored on blocks:
  8193, 24577, 40961, 57345, 73729
  Writing inode tables: done
  Creating journal (4096 blocks): done
  Writing superblocks and filesystem accounting information: done
  This filesystem will be automatically checked every 20 mounts or
  180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]# mkdir /jiajia
[root@localhost ~]# mount /dev/jiajiavg/lvjiajia /jiajia/

[root@localhost ~]# df -h


  Filesystem           >  /dev/mapper/rootvg-rootlv
  5.8G  3.1G  2.4G  57% /
  /dev/sda1             145M   14M  124M  10% /boot
  none                  125M     0  125M   0% /dev/shm
  /dev/mapper/rootvg-homelv
  465M   11M  431M   3% /home
  /dev/mapper/jiajiavg-lvjiajia
  148M  5.6M  135M   4% /jiajia
  六、动态加大VG的大小200M,主要步骤见下面红色字体
[root@localhost ~]# fdisk -l

  Disk /dev/sda: 8589 MB, 8589934592 bytes
  255 heads, 63 sectors/track, 1044 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start         End      Blocks  >  /dev/sda1   *           1          19      152586   83  Linux
  /dev/sda2              20         401     3068415   8e  Linux LVM
  /dev/sda3             402         720     2562367+  8e  Linux LVM
  /dev/sda4             721        1044     2602530    5  Extended
  /dev/sda5             721         975     2048256   8e  Linux LVM
  /dev/sda6             976        1000      200781   8e  Linux LVM
[root@localhost ~]# fdisk /dev/sda

  The number of cylinders for this disk is set to 1044.
  There is nothing wrong with that, but this is larger than 1024,
  and could in certain setups cause problems with:
  1) software that runs at boot time (e.g., old versions of LILO)
  2) booting and partitioning software from other OSs
  (e.g., DOS FDISK, OS/2 FDISK)
  Command (m for help): m
  Command action
  a   toggle a bootable flag
  b   edit bsd disklabel
  c   toggle the dos compatibility flag
  d   delete a partition
  l   list known partition types
  m   print this menu
  n   add a new partition
  o   create a new empty DOS partition table
  p   print the partition table
  q   quit without saving changes
  s   create a new empty Sun disklabel

  t   change a partition's system>  u   change display/entry units
  v   verify the partition table
  w   write table to disk and exit
  x   extra functionality (experts only)
  Command (m for help): n
  First cylinder (1001-1044, default 1001):
  Using default value 1001
  Last cylinder or +size or +sizeM or +sizeK (1001-1044, default 1044): +200M
  Command (m for help): p
  Disk /dev/sda: 8589 MB, 8589934592 bytes
  255 heads, 63 sectors/track, 1044 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start         End      Blocks  >  /dev/sda1   *           1          19      152586   83  Linux
  /dev/sda2              20         401     3068415   8e  Linux LVM
  /dev/sda3             402         720     2562367+  8e  Linux LVM
  /dev/sda4             721        1044     2602530    5  Extended
  /dev/sda5             721         975     2048256   8e  Linux LVM
  /dev/sda6             976        1000      200781   8e  Linux LVM
  /dev/sda7            1001        1025      200781   83  Linux
  Command (m for help): t
  Partition number (1-7): 7
  Hex code (type L to list codes): 8e
  Changed system type of partition 7 to 8e (Linux LVM)
  Command (m for help): p
  Disk /dev/sda: 8589 MB, 8589934592 bytes
  255 heads, 63 sectors/track, 1044 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start         End      Blocks  >  /dev/sda1   *           1          19      152586   83  Linux
  /dev/sda2              20         401     3068415   8e  Linux LVM
  /dev/sda3             402         720     2562367+  8e  Linux LVM
  /dev/sda4             721        1044     2602530    5  Extended
  /dev/sda5             721         975     2048256   8e  Linux LVM
  /dev/sda6             976        1000      200781   8e  Linux LVM
  /dev/sda7            1001        1025      200781   8e  Linux LVM
  Command (m for help): w

  The partition table has been>  Calling ioctl() to re-read partition table.
  WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
  The kernel still uses the old table.
  The new table will be used at the next reboot.
  Syncing disks.
[root@localhost ~]# vgdisplay rootvg       ---先检查未扩容VG钱的大小为7.28G

  --- Volume group ---
  VG Name               rootvg

  System>  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                3
  Act PV                3

  VG>
  PE>  Total PE              233

  Alloc PE />
  Free  PE />  VG UUID               C50uYl-cDF5-03Ie-0Bwh-ucbi-oOpo-Odlmq9
[root@localhost ~]# partprobe                            ---使得上面的分区生效

[root@localhost ~]# pvcreate /dev/sda7                   ---将/dev/sda7转换成PV

  Physical volume "/dev/sda7" successfully created
[root@localhost ~]# vgextend rootvg /dev/sda7            ---将PV /dev/sda7加入到VG rootvg中

  Volume group "rootvg" successfully extended
[root@localhost ~]# vgdisplay rootvg                     ---检查扩容后的VG大小为7.47G

  --- Volume group ---
  VG Name               rootvg

  System>  Format                lvm2
  Metadata Areas        4
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                4
  Act PV                4

  VG>
  PE>  Total PE              239

  Alloc PE />
  Free  PE />  VG UUID               C50uYl-cDF5-03Ie-0Bwh-ucbi-oOpo-Odlmq9
七、删除VG jiajiavg,主要步骤见红色字体
[root@localhost ~]# df -h


  Filesystem           >  /dev/mapper/rootvg-rootlv
  5.8G  3.1G  2.4G  57% /
  /dev/sda1             145M   14M  124M  10% /boot
  none                  125M     0  125M   0% /dev/shm
  /dev/mapper/rootvg-homelv
  465M   11M  431M   3% /home
  /dev/mapper/jiajiavg-lvjiajia
  148M  5.6M  135M   4% /jiajia
[root@localhost ~]# vgdisplay jiajiavg

  --- Volume group ---
  VG Name               jiajiavg

  System>  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1

  VG>
  PE>  Total PE              48

  Alloc PE />
  Free  PE />  VG UUID               is2u3L-G9F1-Bnrc-9rPM-1DFm-WDSD-wLog9u
[root@localhost ~]# lvdisplay /dev/mapper/jiajiavg-lvjiajia

  --- Logical volume ---
  LV Name                /dev/jiajiavg/lvjiajia
  VG Name                jiajiavg
  LV UUID                ECAEFu-Pyr3-wkEI-27AE-lYXp-xIWk-1WVI5x
  LV Write Access        read/write
  LV Status              available
  # open                 1

  LV>  Current LE             38
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3
[root@localhost ~]# umount /jiajia/                         ---先卸载LV所对应的挂在目录

[root@localhost ~]# lvremove /dev/mapper/jiajiavg-lvjiajia  ---删除LV

  Do you really want to remove active logical volume "lvjiajia"? [y/n]: y
  Logical volume "lvjiajia" successfully removed
[root@localhost ~]# vgchange -a n jiajiavg                  ---将VG停止作用

  0 logical volume(s) in volume group "jiajiavg" now active
[root@localhost ~]# df -h


  Filesystem           >  /dev/mapper/rootvg-rootlv
  5.8G  3.1G  2.4G  57% /
  /dev/sda1             145M   14M  124M  10% /boot
  none                  125M     0  125M   0% /dev/shm
  /dev/mapper/rootvg-homelv
  465M   11M  431M   3% /home
[root@localhost ~]# vgremove jiajiavg

  Volume group "jiajiavg" successfully removed
[root@localhost ~]# vgdisplay jiajiavg                        ---检查该VG是否还存在

  Volume group "jiajiavg" not found
八、通过图形界面来动态扩展VG  选择在第七步骤删除VG jiajiavg后遗留下的物理卷sda6
选择右下边的“添加到已存在的卷组中”  检查卷组rootvg明显增大了,还剩下896MB
[root@localhost ~]# vgdisplay rootvg

  --- Volume group ---
  VG Name               rootvg

  System>  Format                lvm2
  Metadata Areas        5
  Metadata Sequence No  8
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                5
  Act PV                5

  VG>
  PE>  Total PE              245

  Alloc PE />  Free  PE />  VG UUID               C50uYl-cDF5-03Ie-0Bwh-ucbi-oOpo-Odlmq9
注意:1、动态扩容/根目录(LV)的步骤完全可以用到扩其他分区(LV),这里不在讲述  2、若系统是REDHAT 3,则扩容的时候需要先卸载挂在目录,举例如下
  umount /jiajia
  e2fsadm -L +200M /dev/jiajiavg/jiajiavg-lvjiajia
  mount /dev/jiajiavg/jiajiavg-lvjiajia /jiajia
  3、若系统是REDHAT 3,则在完成fdisk /dev/sda物理分区后需要reboot系统
删除VG
[root@localhost ~]# umount /jiajia/

[root@localhost ~]# lvremove /dev/mapper/jiajiavg-lvjiajia

[root@localhost ~]# vgchange -a n jiajiavg

[root@localhost ~]# vgdisplay jiajiavg

动态加大VG的大小200M
[root@localhost ~]# fdisk /dev/sda

  。。。
  Last cylinder or +size or +sizeM or +sizeK (1001-1044, default 1044): +200M
  。。。
  Hex code (type L to list codes): 8e
[root@localhost ~]# vgdisplay rootvg

[root@localhost ~]# partprobe

[root@localhost ~]# pvcreate /dev/sda7

[root@localhost ~]# vgextend rootvg /dev/sda7

[root@localhost ~]# vgdisplay rootvg

命令方式建立新LVM的文件系统/jiajia和卷组jiajiavg,大小为150MB
[root@localhost ~]# fdisk /dev/sda

  。。。
  Last cylinder or +size or +sizeM or +sizeK (976-1044, default 1044): +200M
  。。。
  Hex code (type L to list codes): 8e
[root@localhost ~]# partprobe

[root@localhost ~]# pvcreate /dev/sda6

[root@localhost ~]# vgcreate jiajiavg /dev/sda6

[root@localhost ~]# lvcreate -L 150M -n lvjiajia jiajiavg   从卷组的200M中挖出150M给LV

[root@localhost ~]# mke2fs -j /dev/jiajiavg/lvjiajia

[root@localhost ~]# mkdir /jiajia

[root@localhost ~]# mount /dev/jiajiavg/lvjiajia /jiajia/

命令方式来对/目录进行扩容500MB
[root@localhost ~]# df -h

[root@localhost /]# lvextend -L +500M /dev/mapper/rootvg-rootlv

[root@localhost /]# ext2online /dev/mapper/rootvg-rootlv


运维网声明 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-459343-1-1.html 上篇帖子: redhat5.4 yum源制做方法 下篇帖子: Redhat Lighttpd安装配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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