zoukankan      html  css  js  c++  java
  • 虚拟机中CentOS 6.5 添加扩展分区

    此扩展方法要求支持LVM

    1、更改虚拟机配置

    虚拟机->设置->硬盘->扩展磁盘容量

     fdisk -l 查看,发现硬盘空间变大了

    [root@thj Desktop]# fdisk -l
    
    Disk /dev/sda: 42.9 GB, 42949672960 bytes
    255 heads, 63 sectors/track, 5221 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: 0x000812b5
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          64      512000   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              64        2611    20458496   8e  Linux LVM
    
    Disk /dev/mapper/vg_thj-lv_root: 18.9 GB, 18865979392 bytes
    255 heads, 63 sectors/track, 2293 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/mapper/vg_thj-lv_swap: 2080 MB, 2080374784 bytes
    255 heads, 63 sectors/track, 252 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

    2、创建分区

    [root@thj Desktop]# fdisk /dev/sda
    
    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): p    #查看分区表信息
    
    Disk /dev/sda: 42.9 GB, 42949672960 bytes
    255 heads, 63 sectors/track, 5221 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: 0x000812b5
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          64      512000   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              64        2611    20458496   8e  Linux LVM
    
    Command (m for help): n   #创建新的分区
    Command action
       e   extended
       p   primary partition (1-4)
    p        #创建为主分区
    Partition number (1-4): 3                           
    First cylinder (2611-5221, default 2611):       
    Using default value 2611                         #默认就好
    Last cylinder, +cylinders or +size{K,M,G} (2611-5221, default 5221): 
    Using default value 5221            #默认就好
    
    Command (m for help): p   #查看分区表
    
    Disk /dev/sda: 42.9 GB, 42949672960 bytes
    255 heads, 63 sectors/track, 5221 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: 0x000812b5
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1          64      512000   83  Linux
    Partition 1 does not end on cylinder boundary.
    /dev/sda2              64        2611    20458496   8e  Linux LVM
    /dev/sda3            2611        5221    20966162+  83  Linux
    
    Command (m for help): w  #保存
    The partition table has been altered!
    
    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 or after you run partprobe(8) or kpartx(8)
    Syncing disks.

    设置完后,reboot重启系统

    3、格式化分区

    [root@thj Desktop]# mkfs.ext3 /dev/sda3
    mke2fs 1.41.12 (17-May-2010)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    1310720 inodes, 5241540 blocks
    262077 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=4294967296
    160 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, 2654208, 
        4096000
    
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 21 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.

    4、加入LVM,并挂载到根目录下

    • vgs 查看卷组情况
    [root@thj Desktop]# vgs              
      VG     #PV #LV #SN Attr   VSize  VFree
      vg_thj   1   2   0 wz--n- 19.51g    0            //有一个vg_thj卷组(此处系统不同会有所不同)
    • 创建物理卷(LVM分区),并将物理卷加入vg_thj组里
    [root@thj Desktop]# lvm
    lvm> pvcreate /dev/sda3      //创建一个LVM硬分区
      Physical volume "/dev/sda3" successfully created
    lvm> vgextend vg_thj /dev/sda3    //加入与根目录同一个LVM组
      Volume group "vg_thj" successfully extended
    • 查看 lv path
    [root@thj Desktop]# lvdisplay
      --- Logical volume ---
      LV Path                /dev/vg_thj/lv_root      //root对应的lv path
      LV Name                lv_root
      VG Name                vg_thj
      LV UUID                FMlzw9-r8dt-2Oa1-mS0W-brnn-YsDm-g3ld5S
      LV Write Access        read/write
      LV Creation host, time thj.localthj, 2018-09-10 10:47:47 +0800
      LV Status              available
      # open                 1
      LV Size                17.57 GiB
      Current LE             4498
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           253:0
       
      --- Logical volume ---
      LV Path                /dev/vg_thj/lv_swap
      LV Name                lv_swap
      VG Name                vg_thj
      LV UUID                lLgahm-QUMF-XHiN-jZJc-F5ve-YycI-FmEVdr
      LV Write Access        read/write
      LV Creation host, time thj.localthj, 2018-09-10 10:47:50 +0800
      LV Status              available
      # open                 1
      LV Size                1.94 GiB
      Current LE             496
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           253:1
    • 扩展 lv path
    [root@thj Desktop]# lvextend -L +19.99G /dev/vg_thj/lv_root
      Rounding size to boundary between physical extents: 19.99 GiB.
      Size of logical volume vg_thj/lv_root changed from 17.57 GiB (4498 extents) to 37.56 GiB (9616 extents).
      Logical volume lv_root successfully resized.
    • 重置主分区大小
    [root@thj Desktop]# resize2fs /dev/vg_thj/lv_root
    resize2fs 1.41.12 (17-May-2010)
    Filesystem at /dev/vg_thj/lv_root is mounted on /; on-line resizing required
    old desc_blocks = 2, new_desc_blocks = 3
    Performing an on-line resize of /dev/vg_thj/lv_root to 9846784 (4k) blocks.
    The filesystem on /dev/vg_thj/lv_root is now 9846784 blocks long.

    有时报错:

    [root@thj Desktop]# lvextend -L +19G /dev/vg_thj/lv_root
      Couldn't find device with uuid N0xspW-ZOct-v7pH-GHRN-G1Ck-0CnJ-ghqEKZ.
      Cannot change VG vg_thj while PVs are missing.
      Consider vgreduce --removemissing.
      Cannot process volume group vg_thj

    参考  https://blog.51cto.com/yl497103815/1180426

    • 查看扩展后的文件系统
    [root@thj Desktop]# df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/vg_thj-lv_root
                           37G   12G   24G  33% /                   
    tmpfs                 491M  228K  491M   1% /dev/shm
    /dev/sda1             477M   36M  417M   8% /boot
  • 相关阅读:
    C++11模板类使用心得
    Linux下MakeFile初探
    Leetcode 35 Search Insert Position 二分查找(二分下标)
    Leetcode 4 Median of Two Sorted Arrays 二分查找(二分答案+二分下标)
    数据库分库分表的应用场景及方法分析
    DB主从一致性的几种解决方法
    Redis主从复制和集群配置
    RPC vs RESTful
    Mysql锁详解
    BIO与NIO、AIO的区别
  • 原文地址:https://www.cnblogs.com/xdjun/p/11460946.html
Copyright © 2011-2022 走看看