• RedHat6.5系统LVM增加新硬盘实现根文件系统扩容


    一、新增物理空间

    二、linux中创建新分区

    1、首先查看硬盘信息,用fdisk -l命令,如果有硬盘有剩余空间就可以对其进行分区。

    1. [root@master 桌面]# fdisk -l
    2.  
    3. Disk /dev/sda: 64.4 GB, 64424509440 bytes
    4. 255 heads, 63 sectors/track, 7832 cylinders
    5. Units = cylinders of 16065 * 512 = 8225280 bytes
    6. Sector size (logical/physical): 512 bytes / 512 bytes
    7. I/O size (minimum/optimal): 512 bytes / 512 bytes
    8. Disk identifier: 0x0004bbc1
    9.  
    10.    Device Boot      Start         End      Blocks   Id  System
    11. /dev/sda1   *           1          64      512000   83  Linux
    12. Partition 1 does not end on cylinder boundary.
    13. /dev/sda2              64        2611    20458496   8e  Linux LVM
    14.  
    15. Disk /dev/mapper/vg_hadoop-lv_root: 18.8 GB, 18798870528 bytes
    16. 255 heads, 63 sectors/track, 2285 cylinders
    17. Units = cylinders of 16065 * 512 = 8225280 bytes
    18. Sector size (logical/physical): 512 bytes / 512 bytes
    19. I/O size (minimum/optimal): 512 bytes / 512 bytes
    20. Disk identifier: 0x00000000
    21.  
    22.  
    23. Disk /dev/mapper/vg_hadoop-lv_swap: 2147 MB, 2147483648 bytes
    24. 255 heads, 63 sectors/track, 261 cylinders
    25. Units = cylinders of 16065 * 512 = 8225280 bytes
    26. Sector size (logical/physical): 512 bytes / 512 bytes
    27. I/O size (minimum/optimal): 512 bytes / 512 bytes
    28. Disk identifier: 0x00000000

    2、下面对/dev/sda进行分区

    fdisk /dev/sda

    Command (m for help): m   //输入m查看帮助文档

    Command (m for help): n   //输入n新建分区

    1. [root@master ~]# fdisk /dev/sda
    2.  
    3. WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
    4.          switch off the mode (command 'c') and change display units to
    5.          sectors (command 'u').
    6.  
    7. Command (m for help): m
    8. Command action
    9.    a   toggle a bootable flag
    10.    b   edit bsd disklabel
    11.    c   toggle the dos compatibility flag
    12.    d   delete a partition
    13.    l   list known partition types
    14.    m   print this menu
    15.    n   add a new partition
    16.    o   create a new empty DOS partition table
    17.    p   print the partition table
    18.    q   quit without saving changes
    19.    s   create a new empty Sun disklabel
    20.    t   change a partition's system id
    21.    u   change display/entry units
    22.    v   verify the partition table
    23.    w   write table to disk and exit
    24.    x   extra functionality (experts only)
    25.  
    26. Command (for help): n
    27. Command action
    28.    e   extended
    29.    p   primary partition (1-4)

    3、建立扩展分区

    有扩展分区和主分区,逻辑分区在扩展分区中建立。注意到括号中的1-4,最多只能建四个主分区(包括扩展分区)。这里创建扩展分区,

    输入 : e  #建立扩展分区

    Partition number (1-4)  :  3   #因为已经有sda1、sda2了

    First cylinder (2611-7832, default 2611):Last cylinder, +cylinders or +size{K,M,G} (2611-7832, default 7832): #直接Enter键,默认即可

    Command (m for help): p   #查看分区结果

    1. Command action
    2.    e   extended
    3.    p   primary partition (1-4)
    4. e
    5. Partition number (1-4): 3
    6. First cylinder (2611-7832, default 2611): 
    7. Using default value 2611
    8. Last cylinder, +cylinders or +size{K,M,G} (2611-7832, default 7832): 
    9. Using default value 7832
    10.  
    11. Command (for help): p
    12.  
    13. Disk /dev/sda: 64.4 GB, 64424509440 bytes
    14. 255 heads, 63 sectors/track, 7832 cylinders
    15. Units = cylinders of 16065 * 512 = 8225280 bytes
    16. Sector size (logical/physical): 512 bytes / 512 bytes
    17. I/O size (minimum/optimal): 512 bytes / 512 bytes
    18. Disk identifier: 0x0004bbc1
    19.  
    20.    Device Boot      Start         End      Blocks   Id  System
    21. /dev/sda1   *           1          64      512000   83  Linux
    22. Partition 1 does not end on cylinder boundary.
    23. /dev/sda2              64        2611    20458496   8e  Linux LVM
    24. /dev/sda3            2611        7832    41939020    5  Extended

    4、扩展分区建好就可以在扩展分区建立逻辑分区了

    Command (m for help): n

    输入 : l  建立逻辑分区

    Command (m for help): p   #查看分区结果

    1. Command action
    2.    l   logical (5 or over)
    3.    p   primary partition (1-4)
    4. l
    5. First cylinder (2611-7832, default 2611): 
    6. Using default value 2611
    7. Last cylinder, +cylinders or +size{K,M,G} (2611-7832, default 7832): 
    8. Using default value 7832
    9.  
    10. Command (for help): p
    11.  
    12. Disk /dev/sda: 64.4 GB, 64424509440 bytes
    13. 255 heads, 63 sectors/track, 7832 cylinders
    14. Units = cylinders of 16065 * 512 = 8225280 bytes
    15. Sector size (logical/physical): 512 bytes / 512 bytes
    16. I/O size (minimum/optimal): 512 bytes / 512 bytes
    17. Disk identifier: 0x0004bbc1
    18.  
    19.    Device Boot      Start         End      Blocks   Id  System
    20. /dev/sda1   *           1          64      512000   83  Linux
    21. Partition 1 does not end on cylinder boundary.
    22. /dev/sda2              64        2611    20458496   8e  Linux LVM
    23. /dev/sda3            2611        7832    41939020    5  Extended
    24. /dev/sda5            2611        7832    41938988+  83  Linux

    5、上面显示已经建好一个主分区,一个逻辑分区,但是这些现在还没有生效,需要保存退出。

    Command (m for help):w   #保存退出

    输入 reboot 重启系统生效。

    1. Command (for help): w
    2. The partition table has been altered!
    3.  
    4. Calling ioctl() to re-read partition table.
    5.  
    6. WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
    7. The kernel still uses the old table. The new table will be used at
    8. the next reboot or after you run partprobe(8) or kpartx(8)
    9. Syncing disks.

    三、 Linux系统LVM增加新硬盘实现根文件系统扩容

    1、创建物理卷

    fdisk -l

    1. [root@master local]# fdisk -l
    2.  
    3. Disk /dev/sda: 64.4 GB, 64424509440 bytes
    4. 255 heads, 63 sectors/track, 7832 cylinders
    5. Units = cylinders of 16065 * 512 = 8225280 bytes
    6. Sector size (logical/physical): 512 bytes / 512 bytes
    7. I/O size (minimum/optimal): 512 bytes / 512 bytes
    8. Disk identifier: 0x0004bbc1
    9.  
    10.    Device Boot      Start         End      Blocks   Id  System
    11. /dev/sda1   *           1          64      512000   83  Linux
    12. Partition 1 does not end on cylinder boundary.
    13. /dev/sda2              64        2611    20458496   8e  Linux LVM
    14. /dev/sda3            2611        7832    41939020    5  Extended
    15. /dev/sda5            2611        7832    41938988+  83  Linux
    16.  
    17. Disk /dev/mapper/vg_hadoop-lv_root: 18.8 GB, 18798870528 bytes
    18. 255 heads, 63 sectors/track, 2285 cylinders
    19. Units = cylinders of 16065 * 512 = 8225280 bytes
    20. Sector size (logical/physical): 512 bytes / 512 bytes
    21. I/O size (minimum/optimal): 512 bytes / 512 bytes
    22. Disk identifier: 0x00000000
    23.  
    24.  
    25. Disk /dev/mapper/vg_hadoop-lv_swap: 2147 MB, 2147483648 bytes
    26. 255 heads, 63 sectors/track, 261 cylinders
    27. Units = cylinders of 16065 * 512 = 8225280 bytes
    28. Sector size (logical/physical): 512 bytes / 512 bytes
    29. I/O size (minimum/optimal): 512 bytes / 512 bytes
    30. Disk identifier: 0x00000000

    pvcreate /dev/sda5

    1. [root@master local]# pvcreate /dev/sda5
    2.   Physical volume "/dev/sda5" successfully created

     
    2、查看创建好的物理卷

    pvdisplay /dev/sda5

    1. [root@master local]# pvdisplay /dev/sda5
    2.   "/dev/sda5" is a new physical volume of "40.00 GiB"
    3.   --- NEW Physical volume ---
    4.   PV Name               /dev/sda5
    5.   VG Name               
    6.   PV Size               40.00 GiB
    7.   Allocatable           NO
    8.   PE Size               0   
    9.   Total PE              0
    10.   Free PE               0
    11.   Allocated PE          0
    12.   PV UUID               qX00lY-nkpd-4txl-HFwM-6NuT-wMqu-yEFehV

    3、卷组扩容

    vgdisplay

     

    1. [root@master local]# vgdisplay
    2.   --- Volume group ---
    3.   VG Name               vg_hadoop
    4.   System ID             
    5.   Format                lvm2
    6.   Metadata Areas        1
    7.   Metadata Sequence No  3
    8.   VG Access             read/write
    9.   VG Status             resizable
    10.   MAX LV                0
    11.   Cur LV                2
    12.   Open LV               2
    13.   Max PV                0
    14.   Cur PV                1
    15.   Act PV                1
    16.   VG Size               19.51 GiB
    17.   PE Size               4.00 MiB
    18.   Total PE              4994
    19.   Alloc PE / Size       4994 / 19.51 GiB
    20.   Free  PE / Size       0 / 0   
    21.   VG UUID               iQqDwB-Ft3T-aFfh-7nwK-alS3-LSMo-Uid9nz

    vgextend vg_hadoop /dev/sda5

    1. [root@master local]# vgextend vg_hadoop /dev/sda5
    2.   Volume group "vg_hadoop" successfully extended

     

    4、查看扩容之后的卷组信息

    vgdisplay

    1. [root@master local]# vgdisplay
    2.   --- Volume group ---
    3.   VG Name               vg_hadoop
    4.   System ID             
    5.   Format                lvm2
    6.   Metadata Areas        2
    7.   Metadata Sequence No  4
    8.   VG Access             read/write
    9.   VG Status             resizable
    10.   MAX LV                0
    11.   Cur LV                2
    12.   Open LV               2
    13.   Max PV                0
    14.   Cur PV                2
    15.   Act PV                2
    16.   VG Size               59.50 GiB
    17.   PE Size               4.00 MiB
    18.   Total PE              15232
    19.   Alloc PE / Size       4994 / 19.51 GiB
    20.   Free  PE / Size       10238 / 39.99 GiB
    21.   VG UUID               iQqDwB-Ft3T-aFfh-7nwK-alS3-LSMo-Uid9nz

    5、逻辑卷扩容

    df -h

    1. [root@master local]# df -h
    2. Filesystem                     Size  Used Avail Use% Mounted on
    3. /dev/mapper/vg_hadoop-lv_root   18G   12G  5.1G  70% /
    4. tmpfs                          1.9G  224K  1.9G   1% /dev/shm
    5. /dev/sda1                      485M   40M  421M   9% /boot
    6. /dev/sr0                       3.6G  3.6G     0 100% /media/RHEL_6.5 x86_64 Disc 1

    lvextend -L +38G /dev/mapper/vg_hadoop-lv_root 

    1. [root@master local]# lvextend -+38G /dev/mapper/vg_hadoop-lv_root 
    2.   Extending logical volume lv_root to 55.51 GiB
    3.   Logical volume lv_root successfully resized

    6、查看扩容之后的逻辑卷

    lvdisplay /dev/vg_hadoop/lv_root

    1. [root@master local]# lvdisplay /dev/vg_hadoop/lv_root
    2.   --- Logical volume ---
    3.   LV Path                /dev/vg_hadoop/lv_root
    4.   LV Name                lv_root
    5.   VG Name                vg_hadoop
    6.   LV UUID                wv0vJ6-c5Dd-Su9k-7dSV-P3KE-CF88-ElqYFA
    7.   LV Write Access        read/write
    8.   LV Creation host, time hadoop, 2017-07-05 18:56:16 +0800
    9.   LV Status              available
    10.   # open                 1
    11.   LV Size                55.51 GiB
    12.   Current LE             14210
    13.   Segments               2
    14.   Allocation             inherit
    15.   Read ahead sectors     auto
    16.   - currently set to     256
    17.   Block device           253:0


    7、文件系统扩容

    resize2fs /dev/vg_hadoop/lv_root

    1. [root@master local]# resize2fs /dev/vg_hadoop/lv_root
    2. resize2fs 1.41.12 (17-May-2010)
    3. Filesystem at /dev/vg_hadoop/lv_root is mounted on /; on-line resizing required
    4. old desc_blocks = 2, new_desc_blocks = 4
    5. Performing an on-line resize of /dev/vg_hadoop/lv_root to 14551040 (4k) blocks.
    6. The filesystem on /dev/vg_hadoop/lv_root is now 14551040 blocks long.

    8、成功

    df -h

    1. [root@master local]# df -h
    2. Filesystem                     Size  Used Avail Use% Mounted on
    3. /dev/mapper/vg_hadoop-lv_root   55G   12G   41G  22% /
    4. tmpfs                          1.9G  224K  1.9G   1% /dev/shm
    5. /dev/sda1                      485M   40M  421M   9% /boot
    6. /dev/sr0                       3.6G  3.6G     0 100% /media/RHEL_6.5 x86_64 Disc 1

    参考资料:

    https://zhidao.baidu.com/question/2138735858352570708.html

    http://blog.chinaunix.net/uid-17176286-id-3129057.html

  • 相关阅读:
    <%%>,<%!%>,<%=%>,<%@%>,<jsp:include><%@ include%>区别
    struts2学习
    struts2标签
    OGNL
    Andriod XML Editor cannot process this input
    Error 错误: 找不到或无法加载主类
    Class<T> 与T区别
    poi
    POI-java读取Excel(包含合并单元格)
    SQL-字符串连接聚合函数
  • 原文地址:https://www.cnblogs.com/yangcx666/p/8723921.html
Copyright © 2020-2023  润新知