zoukankan      html  css  js  c++  java
  • Oracle VM VirtualBox虚拟机内Linux系统硬盘扩容步骤(CentOS6.5)

    1.首先获取要扩容的虚拟机的 UUID
    VBoxManage 改命令在C:Program FilesOracleVirtualBox目录内,可先添加该目录到环境变量。
    C:Usersyzkj-1008VirtualBox VMsCentOS65197>VBoxManage list hdds

    UUID:           297f254e-ada0-4ddd-be61-552226c3df58
    Parent UUID:    base
    State:          created
    Type:           normal (base)
    Location:       C:Usersyzkj-1008VirtualBox VMsCentOS65197centos.vdi
    Storage format: VDI
    Capacity:       8192 MBytes
    Encryption:     disabled
    
    UUID:           840332aa-7efb-4167-b108-cea25b1bded6
    Parent UUID:    base
    State:          created
    Type:           normal (base)
    Location:       C:Usersyzkj-1008VirtualBox VMsCentOS65198CentOS65198-disk1.vdi
    Storage format: VDI
    Capacity:       8192 MBytes
    Encryption:     disabled
    
    UUID:           0e4317e3-2dd1-45f5-82e0-83a4469bf4ab
    Parent UUID:    base
    State:          created
    Type:           normal (base)
    Location:       C:Usersyzkj-1008VirtualBox VMsCentOS65199CentOS65199-disk1.vdi
    Storage format: VDI
    Capacity:       8192 MBytes
    Encryption:     disabled
    
    UUID:           536f5698-b4e0-4d03-bdcc-2450fb802707
    Parent UUID:    base
    State:          created
    Type:           normal (base)
    Location:       C:Usersyzkj-1008VirtualBox VMsCentOS65197
    ewdisk.vdi
    Storage format: VDI
    Capacity:       8192 MBytes
    Encryption:     disabled

    2.虚拟机磁盘扩容
    C:Usersyzkj-1008VirtualBox VMsCentOS65197>VBoxManage modifyhd 297f254e-ada0-4ddd-be61-552226c3df58 --resize 16384


    3.调整当前硬盘大小

    [root@zendlinux ~]# df -h
    Filesystem                        Size  Used Avail Use% Mounted on
    /dev/mapper/vg_zendlinux-lv_root  6.5G  4.8G  1.5G  77% /
    tmpfs                             499M     0  499M   0% /dev/shm
    /dev/sda1                         477M   51M  401M  12% /boot
    workspace                          22G  6.4G   16G  30% /mnt/www
    
    [root@zendlinux ~]# fdisk -l
    
    Disk /dev/sda: 17.2 GB, 17179869184 bytes
    255 heads, 63 sectors/track, 2088 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: 0x000dc501
    
       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        1045     7875584   8e  Linux LVM
    
    Disk /dev/mapper/vg_zendlinux-lv_root: 7205 MB, 7205814272 bytes
    255 heads, 63 sectors/track, 876 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

    把容量从6.5扩容到17.2G 单还不能使用
    将空余磁盘创建为 sda4

    [root@zendlinux ~]# 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): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 4
    First cylinder (1045-2088, default 1045): 
    Using default value 1045
    Last cylinder, +cylinders or +size{K,M,G} (1045-2088, default 2088): 
    Using default value 2088
    
    Command (m for help): t
    Partition number (1-4): 3
    Partition 3 does not exist yet!
    
    Command (m for help): t
    Partition number (1-4): 4
    Hex code (type L to list codes): 8e
    Changed system type of partition 4 to 8e (Linux LVM)
    
    Command (m for help): w  
    The partition table has been altered!
    
    Disk /dev/mapper/vg_zendlinux-lv_swap: 855 MB, 855638016 bytes
    255 heads, 63 sectors/track, 104 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
    
    [root@zendlinux ~]# fdisk -l /dev/sda
    
    Disk /dev/sda: 17.2 GB, 17179869184 bytes
    255 heads, 63 sectors/track, 2088 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: 0x000dc501
    
       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        1045     7875584   8e  Linux LVM
    /dev/sda4            1045        2088     8383252   8e  Linux LVM

     调整 LVM 大小先看看当前 Volume Group:

    [root@zendlinux ~]# vgdisplay
      --- Volume group ---
      VG Name               vg_zendlinux
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  3
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                2
      Open LV               2
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               7.51 GiB
      PE Size               4.00 MiB
      Total PE              1922
      Alloc PE / Size       1922 / 7.51 GiB
      Free  PE / Size       0 / 0   
      VG UUID               Ou41cE-HyIM-IrsE-Ga3W-Tmmn-l5RX-sw58Zz

    名称为 vg_zendlinux,可调整大小(resizable),当前大小为7.51 GB。
    活动的 LVM 卷有

    [root@zendlinux ~]# lvscan
      ACTIVE            '/dev/vg_zendlinux/lv_root' [6.71 GiB] inherit
      ACTIVE            '/dev/vg_zendlinux/lv_swap' [816.00 MiB] inherit

    先将分配过来的新磁盘空间创建为一个新的物理卷

    [root@zendlinux ~]# pvcreate /dev/sda4
      dev_is_mpath: failed to get device for 8:4
      Physical volume "/dev/sda4" successfully created

    然后使用新的物理卷来扩展 LVM 的vg_zendlinux

    [root@zendlinux ~]# vgextend vg_zendlinux /dev/sda4
      Volume group "vg_zendlinux" successfully extended

    然后扩展 LVM 的逻辑卷 vg_zendlinux/lv_root

    [root@zendlinux ~]# lvextend /dev/vg_zendlinux/lv_root /dev/sda4
      Extending logical volume lv_root to 14.70 GiB
      Logical volume lv_root successfully resized

    最后,调整逻辑卷文件系统的大小

    [root@zendlinux ~]# resize2fs /dev/vg_zendlinux/lv_root
    resize2fs 1.41.12 (17-May-2010)
    Filesystem at /dev/vg_zendlinux/lv_root is mounted on /; on-line resizing required
    old desc_blocks = 1, new_desc_blocks = 1
    Performing an on-line resize of /dev/vg_zendlinux/lv_root to 3854336 (4k) blocks.
    The filesystem on /dev/vg_zendlinux/lv_root is now 3854336 blocks long.

    完成。看看效果:

    [root@zendlinux ~]# lvscan
      ACTIVE            '/dev/vg_zendlinux/lv_root' [14.70 GiB] inherit
      ACTIVE            '/dev/vg_zendlinux/lv_swap' [816.00 MiB] inherit
    [root@zendlinux ~]# df -h
    Filesystem                        Size  Used Avail Use% Mounted on
    /dev/mapper/vg_zendlinux-lv_root   15G  4.8G  8.9G  35% /
    tmpfs                             499M     0  499M   0% /dev/shm
    /dev/sda1                         477M   51M  401M  12% /boot
    workspace                          22G  6.4G   16G  30% /mnt/www
  • 相关阅读:
    poj 1286
    poj 1815
    poj 3368
    十个利用矩阵乘法解决的经典题目
    poj 1026
    hdu 1394
    poj 3270
    poj 2154
    《重构 改善既有代码的设计》读书笔记2
    Android OpenGL ES: 渐变颜色的三角形
  • 原文地址:https://www.cnblogs.com/zendwang/p/6560737.html
Copyright © 2011-2022 走看看