zoukankan      html  css  js  c++  java
  • VIrtualBox扩容-Linux根分区扩容

    参考网页:https://blog.csdn.net/wzy0623/article/details/50667442

    一、CMD下扩容

    1.进入VIrtualBox安装位置:cd E:SoftWareVirtualBox

    2.若格式不是VDI则将VDH虚拟硬盘转化成VDI:

    VBoxManage clonehd E:SoftWareVirtualBoxDisklinux01.vhd E:SoftWareVirtualBoxDisklinux02.vdi --format VDI
    

    3.VDI扩容

    VBoxManage modifyhd E:SoftWareVirtualBoxDisklinux02.vdi --resize 20480
    

    中间存在空格时可使用“”修饰

    VBoxManage modifyhd "E:SoftWareVirtualBox VMscentos6.5linux01.vdi" --resize 20480
    

    二.centos6.5 linux下生效

    1.查看挂载情况fdisk -l

    [root@localhost home]# fdisk -l
    
    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: 0x0005137c
    
       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/VolGroup-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
    
    
    Disk /dev/mapper/VolGroup-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
    
    
    可以看到:
    (1)Linux就一块虚拟的物理盘/dev/sda,扩容后该盘的空间20G。
    (2)该盘已有两个物理分区/dev/sda1和/dev/sda2。
    (3)/dev/sda1 485M,用作boot分区。
    (4)/dev/sda2 7.5G,分成两个逻辑卷,一个用作根6G,一个用作交换1.5G。

    下面要做的就是将/dev/sda上未分配的磁盘空间分区,并添加到根分区所属的逻辑卷上。

    2.将/dev/sda上未分配的磁盘空间分区

    
    [root@localhost home]# 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): 3
    First cylinder (1045-2610, default 1045): w
    First cylinder (1045-2610, default 1045): 
    Using default value 1045
    Last cylinder, +cylinders or +size{K,M,G} (1045-2610, default 2610): 
    Using default value 2610
    
    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.
    
    
    

    3.重启虚拟机

    4.将新建的分区格式化,建立文件系统mkfs.ext4 /dev/sda3

    [root@localhost ~]# mkfs.ext4 /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
    786432 inodes, 3144054 blocks
    157202 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=3221225472
    96 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
    
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 29 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    

    5.创建物理卷 pvcreate /dev/sda3

    [root@localhost ~]# pvcreate /dev/sda3
      Physical volume "/dev/sda3" successfully created
    

    6.执行完后查看物理卷 pvdisplay

    [root@localhost ~]# pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               VolGroup
      PV Size               7.51 GiB / not usable 3.00 MiB
      Allocatable           yes (but full)
      PE Size               4.00 MiB
      Total PE              1922
      Free PE               0
      Allocated PE          1922
      PV UUID               5UbDaB-Lvxi-i0MV-tjZ4-fRZ1-hxsp-6SLBz5
       
      "/dev/sda3" is a new physical volume of "11.99 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sda3
      VG Name               
      PV Size               11.99 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               ldePe6-5NF1-6Nsn-QdEW-Evdj-Qjl1-PuGe9a
     
    

    可以看到新增了一个12G的物理卷

    7.查看卷组 vgdisplay

    [root@localhost ~]# vgdisplay
      --- Volume group ---
      VG Name               VolGroup
      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               0JYZxD-Yg23-ytaP-O66f-DOlF-Rm3O-7X0KhH
    
    

    可以看到只有一个名为VolGroup的卷组,当前大小为7.51G

    8.扩展卷组vgextend vg_fab1 /dev/sda3

    [root@localhost ~]# vgextend VolGroup /dev/sda3
      Volume group "VolGroup" successfully extended
    

    9.查看逻辑卷lvdisplay

    [root@localhost ~]# lvdisplay
      --- Logical volume ---
      LV Path                /dev/VolGroup/lv_root
      LV Name                lv_root
      VG Name                VolGroup
      LV UUID                feWkC3-4OpZ-fmQg-kEbq-697P-S7P0-Mp9jKG
      LV Write Access        read/write
      LV Creation host, time localhost.localdomain, 2018-11-21 11:31:09 +0800
      LV Status              available
      # open                 1
      LV Size                6.71 GiB
      Current LE             1718
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           253:0
       
      --- Logical volume ---
      LV Path                /dev/VolGroup/lv_swap
      LV Name                lv_swap
      VG Name                VolGroup
      LV UUID                G1WHul-iCRS-PnA1-YOZh-AbdK-cyEm-JqUNEr
      LV Write Access        read/write
      LV Creation host, time localhost.localdomain, 2018-11-21 11:31:15 +0800
      LV Status              available
      # open                 1
      LV Size                816.00 MiB
      Current LE             204
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           253:1
    
    

    可以看到用作根的逻辑卷路径为/dev/VolGroup/lv_root

    10.扩展逻辑卷 lvextend

    
    [root@localhost ~]# lvextend -L 18G -n /dev/VolGroup/lv_root
      Extending logical volume lv_root to 18.00 GiB
      Logical volume lv_root successfully resized
    

    11.调整根逻辑卷大小 resize2fs

    当系统为centos7时,调整使用xfs_growfs 替换 resize2fs

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

    12.再次查看当前操作系统的空间情况df-h

    [root@localhost ~]# 
    [root@localhost ~]# df -h
    Filesystem                    Size  Used Avail Use% Mounted on
    /dev/mapper/VolGroup-lv_root   18G  4.8G   13G  29% /
    tmpfs                         1.9G   72K  1.9G   1% /dev/shm
    /dev/sda1                     485M   35M  426M   8% /boot
    [root@localhost ~]# 
    
    
  • 相关阅读:
    SQL Server 2005 Beta 2 快照隔离 zt
    WP7基础学习第九讲
    WP7基础学习第七讲
    WP7基础学习第二讲
    如何对HttpWebRequest异步调用?
    WP7基础学习第五讲
    如何对HttpWebRequest和HttpWebRsponse异步调用?
    WP7基础学习第六讲
    WP7基础学习第一讲
    [收藏学习]gcc和g++
  • 原文地址:https://www.cnblogs.com/code-red-memory/p/13570279.html
Copyright © 2011-2022 走看看