Máy chủ có 500GB ổ cứng, theo nhu cầu cần mở rộng lên 1TB
Máy chủ chạy centos 7 trên VMware
1, Lên VMWare, edit disk của máy chủ lên TB
2, Truy cập máy chủ centos:
– Scan lại disk
[root@mm-adap1 ~]# ls /sys/class/scsi_device/ 0:0:0:0 3:0:0:0 [root@mm-adap1 ~]# echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan [root@mm-adap1 ~]# echo 1 > /sys/class/scsi_device/3\:0\:0\:0/device/rescan
[root@mm-adap1 ~]# fdisk -l Disk /dev/sda: 500 GB, 1099511627776 bytes, 2147483648 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000add72 Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 629145599 313523200 8e Linux LVM /dev/sda3 629145600 1048575999 209715200 8e Linux LVM Disk /dev/mapper/centos_mm--adap1-root: 500 GB, 1098425303040 bytes, 2145361920 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
Đã thấy dung lượng tăng lên, ổ đĩa tác động ở đây là /dev/sda, tiến hành fdisk
[root@mm-adap1 ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 4): 4 First sector (2048-20971519, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): Using default value 20971519 Partition 1 of type Linux and of size 10 GiB is set Command (m for help): t Selected partition 4 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
Khởi tạo physical volume
partprobe [root@mm-adap1 ~]# pvcreate /dev/sda4 Physical volume "/dev/sda4" successfully created.
Lấy thông tin volume group hiện tại
[root@mm-adap1 ~]# vgdisplay --- Volume group --- VG Name centos_mm-adap1 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 498.99 GiB PE Size 4.00 MiB Total PE 127742 Alloc PE / Size 127742 / 498.99 GiB Free PE / Size 0 / 0 VG UUID eyBefC-npQ3-Kl7Q-lHeC-j08s-OLCG-zl33QK
Ta được name VG Name = centos_mm-adap1, tiến hành nhét sda4 vừa tạo vào volume group
[root@mm-adap1 ~]# vgextend centos_mm-adap1 /dev/sda4 Volume group "centos_mm-adap1" successfully extended
Làm tương tự, mở rộng tiếp logical volume
[root@mm-adap1 ~]# lvdisplay --- Logical volume --- LV Path /dev/centos_mm-adap1/root LV Name root VG Name centos_mm-adap1 LV UUID dzkVGt-aTiT-bWyI-kYDm-cUES-7WEm-tAtFva LV Write Access read/write LV Creation host, time mm-adap1, 2020-10-18 16:46:50 +0700 LV Status available # open 1 LV Size 498.99 GiB Current LE 127742 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 [root@mm-adap1 ~]# lvextend /dev/centos_mm-adap1/root /dev/sda4 Size of logical volume centos_mm-adap1/root changed from 498.99 GiB (127742 extents) to <1022.99 GiB (261885 extents). Logical volume centos_mm-adap1/root successfully resized.
Kiểm tra mount
[root@mm-adap1 ~]# mount | grep -i mapper /dev/mapper/centos_mm--adap1-root on / type ext4 (rw,relatime,data=ordered)
Thấy LVM /dev/mapper/centos_mm–adap1-root
tiến hành resize, ở đây phân vùng xài ext4 nên sử dụng resize2fs
[root@mm-adap1 ~]# resize2fs /dev/mapper/centos_mm--adap1-root resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/mapper/centos_mm--adap1-root is mounted on /; on-line resizing required old_desc_blocks = 63, new_desc_blocks = 128 The filesystem on /dev/mapper/centos_mm--adap1-root is now 268170240 blocks long.
Kiểm tra lại thấy / đã có 1TB
[root@mm-adap1 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos_mm--adap1-root 1007G 107G 857G 12% / devtmpfs 16G 0 16G 0% /dev tmpfs 16G 0 16G 0% /dev/shm tmpfs 16G 169M 16G 2% /run tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/sda1 976M 100M 810M 11% /boot tmpfs 3.2G 0 3.2G 0% /run/user/0