Linux虚拟机扩展文件系统

来源:互联网 发布:看直播的软件 编辑:程序博客网 时间:2024/05/16 07:12

我的安装TimesTen和12c的虚拟机文件系统满了,需要扩展文件系统。
然后下面的过程大致是:
1. 扩展物理磁盘
2. 创建磁盘分区
2. 重启
3. 使用磁盘分区创建PV
4. 使用新PV扩展VG
5. 使用新PV扩展文件系统所在的LV
6. 扩展文件系统

以下是文件系统满的信息,可以看到文件系统所在的VG为VolGroup,LV为lv_root

[root@tt12c ~]# df -kFilesystem           1K-blocks      Used Available Use% Mounted on/dev/mapper/VolGroup-lv_root                      22063664  21106848         0 100% /tmpfs                  2020948        76   2020872   1% /dev/shm/dev/sda1               487652     65340    392616  15% /boot.host:/              341867516 322829796  19037720  95% /mnt/hgfs

关机,由于是虚拟机,因此通过VMware Workstation中磁盘的实用工具中的扩展,将24G的硬盘扩展到30G,然后启动。

发现物理磁盘已变为30G

[root@tt12c ~]# fdisk -lDisk /dev/sda: 32.2 GB, 32212254720 bytes <- 已经是30G了255 heads, 63 sectors/track, 3916 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00061f5d   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          64      512000   83  LinuxPartition 1 does not end on cylinder boundary./dev/sda2              64        2611    20458496   8e  Linux LVM/dev/sda3            2611        3133     4194302+  83  LinuxDisk /dev/mapper/VolGroup-lv_root: 23.1 GB, 23089643520 bytes255 heads, 63 sectors/track, 2807 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/VolGroup-lv_swap: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000

然后建立新的磁盘分区

[root@tt12c ~]# fdisk /dev/sdaWARNING: 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): nCommand action   e   extended   p   primary partition (1-4)pSelected partition 4First cylinder (3134-3916, default 3134): Using default value 3134Last cylinder, +cylinders or +size{K,M,G} (3134-3916, default 3916): Using default value 3916Command (m for help): wThe 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 atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.

新的磁盘分区/dev/sda4建立好了

[root@tt12c ~]# fdisk -lDisk /dev/sda: 32.2 GB, 32212254720 bytes255 heads, 63 sectors/track, 3916 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00061f5d   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          64      512000   83  LinuxPartition 1 does not end on cylinder boundary./dev/sda2              64        2611    20458496   8e  Linux LVM/dev/sda3            2611        3133     4194302+  83  Linux/dev/sda4            3134        3916     6289447+  83  LinuxDisk /dev/mapper/VolGroup-lv_root: 23.1 GB, 23089643520 bytes255 heads, 63 sectors/track, 2807 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/mapper/VolGroup-lv_swap: 2147 MB, 2147483648 bytes255 heads, 63 sectors/track, 261 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000

这时VG还没有多余的PE

[root@tt12c ~]# vgdisplay  --- Volume group ---  VG Name               VolGroup  System ID               Format                lvm2  Metadata Areas        2  Metadata Sequence No  5  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               23.50 GiB  PE Size               4.00 MiB  Total PE              6017  Alloc PE / Size       6017 / 23.50 GiB  Free  PE / Size       0 / 0     VG UUID               sjpb7M-lq3U-h15f-Rzoi-351J-icTS-6mQARK

重启机器, 使用shutdown -r now 。如果不用重启就好了,不过现在还不知道如何做。

使用/dev/sda4创建PV

[root@tt12c ~]# pvcreate /dev/sda4  Physical volume "/dev/sda4" successfully created

扩展VG后,发现有了多余的PE,后续lvextend可以用到此数字。然后扩展LV,在线扩展文件系统,成功!

[root@tt12c ~]# vgextend /dev/VolGroup /dev/sda4  Volume group "VolGroup" successfully extended[root@tt12c ~]# vgdisplay  --- Volume group ---  VG Name               VolGroup  System ID               Format                lvm2  Metadata Areas        3  Metadata Sequence No  6  VG Access             read/write  VG Status             resizable  MAX LV                0  Cur LV                2  Open LV               2  Max PV                0  Cur PV                3  Act PV                3  VG Size               29.50 GiB  PE Size               4.00 MiB  Total PE              7552  Alloc PE / Size       6017 / 23.50 GiB  Free  PE / Size       1535 / 6.00 GiB  VG UUID               sjpb7M-lq3U-h15f-Rzoi-351J-icTS-6mQARK[root@tt12c ~]# lvdisplay  --- Logical volume ---  LV Path                /dev/VolGroup/lv_root  LV Name                lv_root  VG Name                VolGroup  LV UUID                PY5XNv-pu3C-l8DH-bLbn-obly-uYZH-PaoMZW  LV Write Access        read/write  LV Creation host, time localhost.localdomain, 2015-06-19 22:28:46 +0800  LV Status              available  # open                 1  LV Size                21.50 GiB  Current LE             5505  Segments               2  Allocation             inherit  Read ahead sectors     auto  - currently set to     256  Block device           252:0  --- Logical volume ---  LV Path                /dev/VolGroup/lv_swap  LV Name                lv_swap  VG Name                VolGroup  LV UUID                4BmUJs-9AGc-PGd9-dFTM-OD7m-KeUv-CTsRv0  LV Write Access        read/write  LV Creation host, time localhost.localdomain, 2015-06-19 22:28:48 +0800  LV Status              available  # open                 2  LV Size                2.00 GiB  Current LE             512  Segments               1  Allocation             inherit  Read ahead sectors     auto  - currently set to     256  Block device           252:1[root@tt12c ~]# [root@tt12c ~]# lvextend /dev/VolGroup/lv_root /dev/sda4  Size of logical volume VolGroup/lv_root changed from 21.50 GiB (5505 extents) to 27.50 GiB (7040 extents).  Logical volume lv_root successfully resized[root@tt12c ~]# resize2fs /dev/VolGroup/lv_rootresize2fs 1.43-WIP (20-Jun-2013)Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing requiredold_desc_blocks = 2, new_desc_blocks = 2The filesystem on /dev/VolGroup/lv_root is now 7208960 blocks long.[root@tt12c ~]# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root                       27G   21G  5.6G  79% /tmpfs                 2.0G   80K  2.0G   1% /dev/shm/dev/sda1             477M   64M  384M  15% /boot.host:/               327G  308G   19G  95% /mnt/hgfs

这里有一点注意,由于是将新建的分区的所有空间都用以扩展文件系统,因此使用了lvextend /dev/VolGroup/lv_root /dev/sda4.
如果只是给一部分空间用于文件系统,则使用lvextend -l+1535 /dev/VolGroup/lv_root (1535=7040-5505)

参考:
* Logical Volume Manager: How can I extend a Volume Group?
* VMware KB: Extending a logical volume in a virtual machine running Red Hat or Cent OS

1 0
原创粉丝点击