vbox虚拟机扩容(CentOS 7.2)

 

Preface
 
My virtual machine was simply created by vagrant in default mode without anything about the extra disk volume configuration.The default size is about 10.5G.In order to use the web browse to configure the MySQL Enterprise Monitor,I have to install the gnome desktop environment first,but I found out it was out of free space like below:
 
 1 ... //Omitted.
 2 Error Summary
 3 -------------
 4 Disk Requirements:
 5   At least 1988MB more space needed on the / filesystem.
 6   
 7   [root@zlm2 04:55:29 ~]
 8 #df -h
 9 Filesystem Size Used Avail Use% Mounted on
10 /dev/mapper/centos-root 8.3G 7.1G 1.2G 87% / //Only 1.2G free space left.
11 devtmpfs 911M 0 911M 0% /dev
12 tmpfs 921M 0 921M 0% /dev/shm
13 tmpfs 921M 8.3M 912M 1% /run
14 tmpfs 921M 0 921M 0% /sys/fs/cgroup
15 /dev/sda1 497M 164M 334M 33% /boot
16 none 80G 27G 53G 34% /vagrant
17 tmpfs 185M 0 185M 0% /run/user/0

 

Therefore,I need to enlarge the disk for that.It's a little bit different from that adding a disk then mount it as a directory outside the "/" position.It's the way to increase the space of "/"(the root directroy).
 
Procedure
 
  • Halt the virtual machine first,and then add a vdi disk from the original disk(vmdk) in windows cmd cli.
 1 C:\Users\Administrator>cd F:\Program Files\Oracle\VirtualBox
 2 
 3 C:\Users\Administrator>F:
 4 
 5 F:\Program Files\Oracle\VirtualBox>VBoxManage clonehd "G:\VirtualBox VMs\zlm2\centos-vm-disk1.vmdk" "G:\VirtualBox VMs\zlm2\centos-vm-disk1.vdi" --format vdi
 6 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
 7 Clone medium created in format 'vdi'. UUID: 63be4ac1-48a1-4b52-848f-71933c6c4adc
 8 
 9 F:\Program Files\Oracle\VirtualBox>VBoxManage modifyhd "G:\VirtualBox VMs\zlm2\centos-vm-disk1.vdi" --resize 30000(default "M")
10 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
11 
12 F:\Program Files\Oracle\VirtualBox>exit

 

  • Restart the virtual machine and then add a new partition.
  1 [root@zlm2 13:56:52 ~]
  2 #fdisk -l
  3 
  4 Disk /dev/sda: 31.5 GB, 31457280000 bytes, 61440000 sectors
  5 Units = sectors of 1 * 512 = 512 bytes
  6 Sector size (logical/physical): 512 bytes / 512 bytes
  7 I/O size (minimum/optimal): 512 bytes / 512 bytes
  8 Disk label type: dos
  9 Disk identifier: 0x0000ca5e
 10 
 11    Device Boot      Start         End      Blocks   Id  System
 12 /dev/sda1   *        2048     1026047      512000   83  Linux
 13 /dev/sda2         1026048    20479999     9726976   8e  Linux LVM
 14 
 15 Disk /dev/mapper/centos-root: 8866 MB, 8866758656 bytes, 17317888 sectors
 16 Units = sectors of 1 * 512 = 512 bytes
 17 Sector size (logical/physical): 512 bytes / 512 bytes
 18 I/O size (minimum/optimal): 512 bytes / 512 bytes
 19 
 20 
 21 Disk /dev/mapper/centos-swap: 1048 MB, 1048576000 bytes, 2048000 sectors
 22 Units = sectors of 1 * 512 = 512 bytes
 23 Sector size (logical/physical): 512 bytes / 512 bytes
 24 I/O size (minimum/optimal): 512 bytes / 512 bytes
 25 
 26 [root@zlm2 13:59:13 ~]
 27 #fdisk /dev/sda
 28 Welcome to fdisk (util-linux 2.23.2).
 29 
 30 Changes will remain in memory only, until you decide to write them.
 31 Be careful before using the write command.
 32 
 33 
 34 Command (m for help): p
 35 
 36 Disk /dev/sda: 31.5 GB, 31457280000 bytes, 61440000 sectors
 37 Units = sectors of 1 * 512 = 512 bytes
 38 Sector size (logical/physical): 512 bytes / 512 bytes
 39 I/O size (minimum/optimal): 512 bytes / 512 bytes
 40 Disk label type: dos
 41 Disk identifier: 0x0000ca5e
 42 
 43    Device Boot      Start         End      Blocks   Id  System
 44 /dev/sda1   *        2048     1026047      512000   83  Linux
 45 /dev/sda2         1026048    20479999     9726976   8e  Linux LVM
 46 
 47 Command (m for help): n
 48 Partition type:
 49    p   primary (2 primary, 0 extended, 2 free)
 50    e   extended
 51 Select (default p): p
 52 Partition number (3,4, default 3): 
 53 First sector (20480000-61439999, default 20480000): 
 54 Using default value 20480000
 55 Last sector, +sectors or +size{K,M,G} (20480000-61439999, default 61439999): 
 56 Using default value 61439999
 57 Partition 3 of type Linux and of size 19.5 GiB is set
 58 
 59 Command (m for help): t
 60 Partition number (1-3, default 3): 
 61 Hex code (type L to list all codes): L
 62 
 63  0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 64  1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 65  2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 66  3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 67  4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 68  5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 69  6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 70  7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 71  8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 72  9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 73  a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 74  b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 75  c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 76  e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 77  f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
 78 10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
 79 11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
 80 12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
 81 14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
 82 16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
 83 17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
 84 18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
 85 1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
 86 1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
 87 1e  Hidden W95 FAT1 80  Old Minix      
 88 Hex code (type L to list all codes): 8e
 89 Changed type of partition 'Linux' to 'Linux LVM'
 90 
 91 Command (m for help): w
 92 The partition table has been altered!
 93 
 94 Calling ioctl() to re-read partition table.
 95 
 96 WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
 97 The kernel still uses the old table. The new table will be used at
 98 the next reboot or after you run partprobe(8) or kpartx(8)
 99 Syncing disks.
100 
101 [root@zlm2 14:02:20 ~]
102 #partprobe
103 
104 [root@zlm2 14:03:42 ~]
105 #fdisk -l
106 
107 Disk /dev/sda: 31.5 GB, 31457280000 bytes, 61440000 sectors
108 Units = sectors of 1 * 512 = 512 bytes
109 Sector size (logical/physical): 512 bytes / 512 bytes
110 I/O size (minimum/optimal): 512 bytes / 512 bytes
111 Disk label type: dos
112 Disk identifier: 0x0000ca5e
113 
114    Device Boot      Start         End      Blocks   Id  System
115 /dev/sda1   *        2048     1026047      512000   83  Linux
116 /dev/sda2         1026048    20479999     9726976   8e  Linux LVM
117 /dev/sda3        20480000    61439999    20480000   8e  Linux LVM
118 
119 Disk /dev/mapper/centos-root: 8866 MB, 8866758656 bytes, 17317888 sectors
120 Units = sectors of 1 * 512 = 512 bytes
121 Sector size (logical/physical): 512 bytes / 512 bytes
122 I/O size (minimum/optimal): 512 bytes / 512 bytes
123 
124 
125 Disk /dev/mapper/centos-swap: 1048 MB, 1048576000 bytes, 2048000 sectors
126 Units = sectors of 1 * 512 = 512 bytes
127 Sector size (logical/physical): 512 bytes / 512 bytes
128 I/O size (minimum/optimal): 512 bytes / 512 bytes

 

  • Create a new PV,add to the original VG and then extend the VG.
 1 [root@zlm2 14:04:09 ~]
 2 #pvdisplay | grep "VG Name"
 3   VG Name               centos
 4 
 5 [root@zlm2 14:05:05 ~]
 6 #pvcreate /dev/sda3
 7   Physical volume "/dev/sda3" successfully created
 8 
 9 [root@zlm2 14:05:23 ~]
10 #pvdisplay | grep "VG Name"
11   VG Name               centos
12   VG Name               
13 
14 [root@zlm2 14:05:41 ~]
15 #vgextend centos /dev/sda3
16   Volume group "centos" successfully extended

 

  • Check the information logical partition.
 1 [root@zlm2 14:07:19 ~]
 2 #cat /etc/fstab
 3 
 4 #
 5 # /etc/fstab
 6 # Created by anaconda on Wed Jan 27 12:42:03 2016
 7 #
 8 # Accessible filesystems, by reference, are maintained under '/dev/disk'
 9 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
10 #
11 /dev/mapper/centos-root /                       xfs     defaults        0 0
12 UUID=461cd9c0-513e-48db-bb08-d07a8f6ef260 /boot                   xfs     defaults        0 0
13 /dev/mapper/centos-swap swap                    swap    defaults        0 0

 

  • Extend the new PV into the original logical partition and expand it.
 1 [root@zlm2 14:06:15 ~]
 2 #lvextend /dev/mapper/centos-root /dev/sda3
 3   Size of logical volume centos/root changed from 8.26 GiB (2114 extents) to 27.79 GiB (7113 extents).
 4   Logical volume root successfully resized.
 5   
 6 [root@zlm2 14:13:28 ~]
 7 #resize2fs /dev/mapper/centos-root //Resizes only for ext2/ext3/ext4 filesystem.
 8 resize2fs 1.42.9 (28-Dec-2013)
 9 resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
10 Couldn't find valid filesystem superblock.
11 
12 [root@zlm2 14:15:19 ~]
13 #xfs_growfs /dev/mapper/centos-root //Expands an existing XFS filesystem.
14 meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=541184 blks
15          =                       sectsz=512   attr=2, projid32bit=1
16          =                       crc=0        finobt=0
17 data     =                       bsize=4096   blocks=2164736, imaxpct=25
18          =                       sunit=0      swidth=0 blks
19 naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
20 log      =internal               bsize=4096   blocks=2560, version=2
21          =                       sectsz=512   sunit=0 blks, lazy-count=1
22 realtime =none                   extsz=4096   blocks=0, rtextents=0
23 data blocks changed from 2164736 to 7283712

 

  • Check the diskspace again with "df -h" again.
 1 [root@zlm2 14:15:45 ~]
 2 #df -h
 3 Filesystem               Size  Used Avail Use% Mounted on
 4 /dev/mapper/centos-root   28G  7.5G   21G  27% /
 5 devtmpfs                 911M     0  911M   0% /dev
 6 tmpfs                    921M     0  921M   0% /dev/shm
 7 tmpfs                    921M  8.4M  912M   1% /run
 8 tmpfs                    921M     0  921M   0% /sys/fs/cgroup
 9 /dev/sda1                497M  164M  334M  33% /boot
10 none                      80G   29G   51G  36% /vagrant
11 tmpfs                    185M     0  185M   0% /run/user/0

 

Okay,now I've got the enough disk space to install the gnome desktop environment.That's awesome!

 

posted @ 2018-09-29 15:14  aaron8219  阅读(717)  评论(1编辑  收藏  举报