zoukankan      html  css  js  c++  java
  • [CentOS7] [VMWARE] 增加磁盘空间后扩大逻辑分区

    0. Check current disk size

    fdisk -l

    1. Increase VM disk size from VMWare

    2. Rescan disk

    echo 1>/sys/class/block/sda/device/rescan

    3. Alter partition table (sudo)

    fdisk /dev/sda

    Use to list partitions. Use d to delete partition to be extended (e.g. 2)

    Create a new partition with n and choose primary type p. Use default for all parameters

    Use to change partition (e.g. 2) to change partition type from 80(Linux) to type 8e (Linux LVM)

    Use p to list partitions again. Then use w to write changes to disk

    4. Reboot

    If partprobe -s works then reboot can be avoided. Otherwise reboot is needed.

    5. Resize Physical Volumne so that LVM identify this new space

    pvresize /dev/sda2

    Verify the new size by pvs (Check PSize and PFree)

    6. Check and extend the file system

    df -T

    Mark down Type (e.g. xfs or ext4) 

    For xfs (default on CentOS): xfs_growfs /dev/centos/root

    For ext4: resize2fs /dev/centos/root

    7. Check result

    df -h

    THE END

    Learn to rescan disk in Linux VM when its backed vdisk in vmware is extended. This method does not require downtime and no data loss.

    Rescan disk when vdisk in extendedRe-scan vdisk in Linux


    Sometimes we get a disk utilization situations and needs to increase disk space. In vmware environment, this can be done on the fly at vmware level. VM assigned disk can be increased in size without any downtime. But, you need to take care of increasing space at OS level within VM. In such scenario we often think, how to increase disk size in Linux when vmware disk size is increased? or how to increase mount point size when vdisk size is increased? or steps for expanding LVM partitions in vmware Linux guest? or how to rescan disk when vdisk expanded? We are going to see steps to achieve this without any downtime.

     

    In our example here, we have one disk /dev/sdd assigned to VM of 1GB. It is part of volume group vg01 and mount point /mydrive is carved out of it. Now, we will increase size of disk to 2GB at vmware level and then will add up this space in mount point /mydrive.

    Step 1:

    See below fdisk -l output snippet showing disk /dev/sdd of 1GB size. We have created single primary partition on it /dev/sdd1 which in turns forms vg01 as stated earlier. Always make sure you have data backup in place of the disk you are working on.


    Step 2:

    Now, change disk size at vmware level. We are increasing it by 1 more GB so final size is 2GB now. At this stage disk need to be re-scanned in Linux so that kernel identifies this size change. Re-scan disk using below command :

    Make sure you use correct disk name in command (before rescan). You can match your SCSI number (X:X:X:X) with vmare disk using this method.

    Note : Sending “– – -” to /sys/class/scsi_host/hostX/scan is scanning SCSI host adapters for new disks on every channel (first -), every target (second -), and every device i.e. disk/lun (third -) i.e. CTD format. This will only helps to scan when new devices are attached to system. It will not help us to re-scan already identified devices.

    Thats why we have to send “1” to /sys/class/block/XYZ/device/rescan to respective SCSI block device to refresh device information like size. So this will be helpful here since our device is already identified by kernel but we want kernel to re-read its new size and update itself accordingly.

    Now kernel re-scan disk and fetch its new size. You can see new size is being shown in your fdisk -l output.


    Step 3:

    At this stage our kernel know new size of disk but out partition (/dev/sdd1) is still of old 1GB size. This left us no choice but delete this partition and re-create it again with full size. Make a note here your data is safe and make sure your (old & new) partition are marked as Linux LVM using hex code  8e or else your will mess up whole configuration.

    Delete and re-create partition using fdisk console as below:

    All fdisk prompt commands are highlighted in above output. Now you can see new partition /dev/sdd1 is of 2GB size. But this partition table is not yet written to disk. Use w command at fdisk prompt to write table.

    You may see warning and error like above. If yes, you can use partprobe -s and you should be good. If you still below error with partprobe then you need to reboot your system (which is sad ).


    Step 4:

    Now rest of the part should be tackeled by LVM. You need to resize PV so that LVM identify this new space. This can be done with pvresize command.

    As new PV size is learned by LVM you should see free/extra space available in VG.

    You can see our VG now have 2GB space i.e. what we have resized our disk to! Now you can use this space to create new lvol in this VG or extend existing lvol using LVM commands. Further you can extend filesystem online which is sittign on logical volumes.

    You can observe all lvol in this VG will be un-affected by this activity and data is still there as it was previously.

  • 相关阅读:
    Linux 进程终止后自动重启
    (转) Android中ViewStub组件使用
    (转)android UI进阶之用ViewPager实现欢迎引导页面
    (转)android UI进阶之实现listview的分页加载
    (转)android UI进阶之实现listview的下拉加载
    (转)android UI进阶之弹窗的使用(2)实现通讯录的弹窗效果
    学习网址
    (转)android UI进阶之实现listview中checkbox的多选与记录
    (转)android UI进阶之自定义组合控件
    (转)Android里merge和include标签的使用
  • 原文地址:https://www.cnblogs.com/lionetchen/p/8954062.html
Copyright © 2011-2022 走看看