[vbox虚拟机]给vbox磁盘空间扩容的操作步骤

时间:2020-12-03  来源:DB2教程  阅读:

我的vbox的根目录磁盘空间快不够用了,

[root@testdb2 ~]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_testdb2-lv_root
                      27431124  21329720   4707948  82% /
tmpfs                  3481600        88   3481512   1% /dev/shm
/dev/sda1               495844     56258    413986  12% /boot
[root@testdb2 ~]#

我原来的oracle软件和数据,都放在根目录的/u01下,现在根目录已经82%了。

我决定给vbox加一块盘,扩大根目录的空间。

首先,在vbox的图形化界面添加一块硬盘。
add-vdisk
当然,如果不用图形化界面,用命令行如下,也是可以的。


VBoxManage createhd --filename "Z:\Oralce_Virtual_Box\Test DB\TestDB2(11g 12c)\Test_db(11 12c)_AttachStorage.vdi" --size 8192 --format VDI --variant Standard
 
VBoxManage storageattach "TestDB2(11g 12c)" --storagectl "SATA" --port 2 --device 0 --type hdd --medium "Z:\Oralce_Virtual_Box\Test DB\TestDB2(11g 12c)\Test_db(11 12c)_AttachStorage.vdi"

完成后,打开linux,进行扩容。


## 初始状态
[root@testdb2 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_testdb2-lv_root
                       27G   21G  4.5G  82% /
tmpfs                 3.4G   88K  3.4G   1% /dev/shm
/dev/sda1             485M   55M  405M  12% /boot
[root@testdb2 ~]#
[root@testdb2 ~]#
[root@testdb2 ~]#
[root@testdb2 ~]# cd /dev
[root@testdb2 dev]# ls -l sd*
brw-rw----. 1 root disk 8,  0 Nov  3 09:29 sda
brw-rw----. 1 root disk 8,  1 Nov  3 09:30 sda1
brw-rw----. 1 root disk 8,  2 Nov  3 09:29 sda2
brw-rw----. 1 root disk 8, 16 Nov  3 09:29 sdb


可以看到,我新加的一块盘,叫sdb。

创建分区,注意类型选8e,即LVM管理。


[root@testdb2 dev]# fdisk /dev/sdb

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 <<<输入n
Command action
   e   extended
   p   primary partition (1-4)
p <<<输入p
Partition number (1-4): 1 <<<输入1
First cylinder (1-1044, default 1): <<<回车
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): <<<回车
Using default value 1044

Command (m for help): t <<<输入t
Selected partition 1
Hex code (type L to list codes): L <<<输入L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris       
 1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx        
 5  Extended        42  SFS             86  NTFS volume set da  Non-FS data   
 6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility  
 8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt        
 9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access    
 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O       
 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor     
 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs       
 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT           
 f  W95 Ext"d (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor     
12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor     
14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary 
16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS   
17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep       
1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT           
1e  Hidden W95 FAT1
Hex code (type L to list codes): 8e <<<输入8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help):
Command (m for help): p <<<输入p,进行查看,确认没有问题

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x039b1264

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1044     8385898+  8e  Linux LVM

Command (m for help): w <<<输入w,写出到分区表。
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@testdb2 dev]#

[root@testdb2 dev]# ls -l sd*
brw-rw----. 1 root disk 8,  0 Nov  3 09:29 sda
brw-rw----. 1 root disk 8,  1 Nov  3 09:30 sda1
brw-rw----. 1 root disk 8,  2 Nov  3 09:29 sda2
brw-rw----. 1 root disk 8, 16 Nov  3 09:29 sdb
brw-rw----. 1 root disk 8, 17 Nov  3 09:30 sdb1

可以用fdisk -l检查一下,新建的sdb1分区,是lvm管理:


[root@testdb2 dev]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x000b1d34

   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        3917    30944256   8e  Linux LVM

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x039b1264

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1044     8385898+  8e  Linux LVM   <<<<新建的分区,lvm管理

Disk /dev/mapper/vg_testdb2-lv_root: 28.5 GB, 28538044416 bytes
255 heads, 63 sectors/track, 3469 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_testdb2-lv_swap: 3145 MB, 3145728000 bytes
255 heads, 63 sectors/track, 382 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@testdb2 dev]#


然后,先创建pv:


[root@testdb2 dev]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
[root@testdb2 dev]#
[root@testdb2 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_testdb2    <<< 可以看到原来已经存在的一个pv,注意记录此名字,一会要用到。
  PV Size               29.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              7554
  Free PE               0
  Allocated PE          7554
  PV UUID               FM5QpS-QVVz-HzaR-yDky-xyp7-pnii-ZjeqsV
  
  "/dev/sdb1" is a new physical volume of "8.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name                              <<< 新创建的pv,还没加入到vg,所以显示是空。一会加入。
  PV Size               8.00 GiB
  Allocatable           NO
  PE Size               0  
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               BvodFn-begg-Fd3I-J12E-LzBE-Z9I7-PqhcFO
  
[root@testdb2 ~]#


我们再来看看,pv之上,vg的情况:


[root@testdb2 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_testdb2  <<<< 注意记录此名字,一会要用到。
  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               29.51 GiB
  PE Size               4.00 MiB
  Total PE              7554
  Alloc PE / Size       7554 / 29.51 GiB
  Free  PE / Size       0 / 0   <<<<<< 注意Free的大小,vgextend之前,Free为0
  VG UUID               VOCOIo-ldU1-riYX-tKUc-fbVz-AkYY-QovsFe
  
[root@testdb2 ~]#


我们进行vgextend:


[root@testdb2 ~]# vgextend vg_testdb2 /dev/sdb1
  Volume group "vg_testdb2" successfully extended
[root@testdb2 ~]#
[root@testdb2 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_testdb2
  System ID            
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               37.50 GiB
  PE Size               4.00 MiB
  Total PE              9601
  Alloc PE / Size       7554 / 29.51 GiB
  Free  PE / Size       2047 / 8.00 GiB  <<<<<<<<有变化了,Free有8G了。
  VG UUID               VOCOIo-ldU1-riYX-tKUc-fbVz-AkYY-QovsFe
  
[root@testdb2 ~]#


我们再来看看lv的情况:

[root@testdb2 ~]# lvdisplay


  --- Logical volume ---
  LV Path                /dev/vg_testdb2/lv_root
  LV Name                lv_root
  VG Name                vg_testdb2
  LV UUID                GvdFtq-RLee-iuXW-SZEw-XZsh-MHv3-yXf5Um
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2013-12-09 10:46:23 +0800
  LV Status              available
  # open                 1
  LV Size                26.58 GiB
  Current LE             6804
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
  
  --- Logical volume ---
  LV Path                /dev/vg_testdb2/lv_swap
  LV Name                lv_swap
  VG Name                vg_testdb2
  LV UUID                AxCkee-CZEx-pAPl-NDWN-h0VY-erfC-KISgl7
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2013-12-09 10:46:26 +0800
  LV Status              available
  # open                 2
  LV Size                2.93 GiB
  Current LE             750
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1
  
[root@testdb2 ~]#

进行lvextend,注意大小稍微比原来的8G小一些:


[root@testdb2 ~]# lvextend -L +7.9G /dev/vg_testdb2/lv_root
  Rounding size to boundary between physical extents: 7.90 GiB
  Extending logical volume lv_root to 34.48 GiB
  Logical volume lv_root successfully resized
[root@testdb2 ~]#

注意,lvextend之后,我们看文件系统,还是没有扩容的,因为还需要进行resize2fs命令:


[root@testdb2 ~]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_testdb2-lv_root
                      27431124  21329720   4707948  82% /
tmpfs                  3481600        88   3481512   1% /dev/shm
/dev/sda1               495844     56258    413986  12% /boot
[root@testdb2 ~]#
resize2fs命令:


[root@testdb2 ~]# resize2fs  /dev/vg_testdb2/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_testdb2/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_testdb2/lv_root to 9038848 (4k) blocks.
The filesystem on /dev/vg_testdb2/lv_root is now 9038848 blocks long.

 

[root@testdb2 ~]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_testdb2-lv_root
                      35587744  21333800  12448736  64% /
tmpfs                  3481600        88   3481512   1% /dev/shm
/dev/sda1               495844     56258    413986  12% /boot
[root@testdb2 ~]#

[vbox虚拟机]给vbox磁盘空间扩容的操作步骤

http://m.bbyears.com/shujuku/114177.html

推荐访问:vbox官网
相关阅读 猜你喜欢
本类排行 本类最新