关闭

ESXI扩展linux虚拟机根目录空间

504人阅读 评论(0) 收藏 举报
分类:

1. 在ESXI服务器上增加虚拟机磁盘空间。

2. 进入虚拟机查看硬盘空间(/dev/sda已变为171GB)

[root@CIT ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cit-lv_root
                       43G   39G  1.8G  96% /
tmpfs                  12G  176K   12G   1% /dev/shm
/dev/sda1             485M   37M  423M   9% /boot
/dev/mapper/vg_cit-lv_home
                      4.2G  137M  3.9G   4% /home

[root@CIT ~]# fdisk -l

Disk /dev/sda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 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: 0x0001e603

   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        7833    62401536   8e  Linux LVM

Disk /dev/mapper/vg_cit-lv_root: 46.7 GB, 46665826304 bytes
255 heads, 63 sectors/track, 5673 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_cit-lv_swap: 12.7 GB, 12675186688 bytes
255 heads, 63 sectors/track, 1541 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_cit-lv_home: 4555 MB, 4555014144 bytes
255 heads, 63 sectors/track, 553 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


3. 增加磁盘分区

[root@CIT ~]# 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): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (7833-20886, default 7833):
Using default value 7833
Last cylinder, +cylinders or +size{K,M,G} (7833-20886, default 20886):
Using default value 20886

Command (m for help): p

Disk /dev/sda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 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: 0x0001e603

   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        7833    62401536   8e  Linux LVM
/dev/sda3            7833       20886   104852235   83  Linux

Command (m for help): t (修改分区ID为Linux LVM,否则无法格式化)

Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

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.
[root@CIT ~]# fdisk -l               

Disk /dev/sda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 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: 0x0001e603

   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        7833    62401536   8e  Linux LVM
/dev/sda3            7833       20886   104852235   8e  Linux LVM

Disk /dev/mapper/vg_cit-lv_root: 46.7 GB, 46665826304 bytes
255 heads, 63 sectors/track, 5673 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_cit-lv_swap: 12.7 GB, 12675186688 bytes
255 heads, 63 sectors/track, 1541 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_cit-lv_home: 4555 MB, 4555014144 bytes
255 heads, 63 sectors/track, 553 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


4. 重启服务器,然后格式化分区

[root@CIT ~]# mkfs -t ext3 /dev/sda3 (注意/etc/fstab里的分区格式)
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
6553600 inodes, 26213058 blocks
1310652 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 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,
        4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:

done

This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


5. 使用vgextend命令加到lvm组里面去

[root@CIT ~]# lvs
  LV      VG     Attr     LSize  Pool Origin Data%  Move Log Copy%  Convert
  lv_home vg_cit -wi-ao--  4.24g                                           
  lv_root vg_cit -wi-ao-- 43.46g                                           
  lv_swap vg_cit -wi-ao-- 11.80g                                           
[root@CIT ~]# pvcreate /dev/sda3
  Writing physical volume data to disk "/dev/sda3"
  Physical volume "/dev/sda3" successfully created

[root@CIT ~]# vgextend vg_cit /dev/sda3
  Volume group "vg_cit" successfully extended
[root@CIT ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_cit
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               159.50 GiB
  PE Size               4.00 MiB
  Total PE              40832
  Alloc PE / Size       15234 / 59.51 GiB
  Free  PE / Size       25598 / 99.99 GiB
  VG UUID               xeQlGW-NlDY-y44E-YKeg-dvmk-xyG3-PgpGF8
   
[root@CIT ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cit-lv_root
                       43G   39G  1.8G  96% /
tmpfs                  12G   88K   12G   1% /dev/shm
/dev/sda1             485M   37M  423M   9% /boot
/dev/mapper/vg_cit-lv_home
                      4.2G  137M  3.9G   4% /home
[root@CIT ~]# lvextend -L +99.99G /dev/vg_cit/lv_root /dev/sda3
  Rounding size to boundary between physical extents: 99.99 GiB
  Extending logical volume lv_root to 143.45 GiB
  Logical volume lv_root successfully resized

6. 检查文件系统

[root@CIT ~]# e2fsck -f /dev/vg_cit/lv_root
e2fsck 1.41.12 (17-May-2010)
/dev/vg_cit/lv_root is mounted.  

WARNING!!!  The filesystem is mounted.   If you continue you ***WILL***
cause ***SEVERE*** filesystem damage.

Do you really want to continue (y/n)? yes

/dev/vg_cit/lv_root: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/vg_cit/lv_root: ***** FILE SYSTEM WAS MODIFIED *****
/dev/vg_cit/lv_root: ***** REBOOT LINUX *****
/dev/vg_cit/lv_root: 483114/2850816 files (0.2% non-contiguous), 10363101/11393024 blocks

7. 调整分割区大小

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

[root@CIT ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_cit-lv_root
                      142G   39G   96G  29% /
tmpfs                  12G   88K   12G   1% /dev/shm
/dev/mapper/vg_cit-lv_home
                      4.2G  137M  3.9G   4% /home

完成!

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:10259次
    • 积分:156
    • 等级:
    • 排名:千里之外
    • 原创:4篇
    • 转载:11篇
    • 译文:0篇
    • 评论:0条
    文章分类