這個筆記只適用於同一塊硬盤擴容
為了不讓服務器遭遇到毀滅級的打擊,我還是開了台測試用的服務器先試試水,不然的話,萬一狗帶了,那什么都沒了。
過程:
可以看到,根目錄只有 50GB
root@localhost:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 798M 1.1M 797M 1% /run
/dev/vda2 49G 39G 8.0G 83% /
還有 70GB 目前沒用
root@localhost:~# fdisk -l
Disk /dev/vda: 120 GiB, 128849018880 bytes, 251658240 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
Disklabel type: gpt
Disk identifier: 0A82F7CF-FB16-4A55-ACF6-5D4339FA7608
Device Start End Sectors Size Type
/dev/vda1 2048 4095 2048 1M BIOS boot
/dev/vda2 4096 104855551 104851456 50G Linux filesystem
/dev/vda3 104855552 251658206 146802655 70G Linux filesystem
選擇 /dev/vda,並且輸入p(print)
root@localhost:~# parted /dev/vda
GNU Parted 3.2
Using /dev/vda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p # 輸入p
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 129GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2097kB 1049kB bios_grub
2 2097kB 53.7GB 53.7GB ext4
輸入 resizepart 2,輸入 yes,End 這就填寫上一步看到的磁盤空間(Disk /dev/vda: 129GB) 129GB,這個應該是換算出了問題,最后再輸入 q (quit) 退出
由於我是系統盤,這個 /dev/vda2 是活動中的分區,會有警告是否要繼續,我這里是繼續。
(parted) resizepart 2
Warning: Partition /dev/vda2 is being used. Are you sure you want to continue?
Yes/No? yes
End? [53.7GB]? 129GB
(parted) q
Information: You may need to update /etc/fstab.
退出之后,用 df -h 命令看發現沒有任何改變,但是使用 lsblk 命令會發現已經擴容成功了,因為這只是 block device 容量變大了,還沒有反映到 file system 中
需要使用 resize2fs 命令更新
root@localhost:~# resize2fs /dev/vda2
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/vda2 is mounted on /; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 15
The filesystem on /dev/vda2 is now 31456763 (4k) blocks long.
這個時候用 df -h 查看
root@localhost:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 798M 1.1M 797M 1% /run
/dev/vda2 118G 39G 75G 35% /
lsblk 查看
root@localhost:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop1 7:1 0 6.6M 1 loop /snap/libxslt/44
loop2 7:2 0 91.3M 1 loop /snap/core/8592
loop3 7:3 0 9.6M 1 loop /snap/libxslt/67
loop4 7:4 0 91.4M 1 loop /snap/core/8689
vda 252:0 0 120G 0 disk
├─vda1 252:1 0 1M 0 part
└─vda2 252:2 0 120G 0 part /
全部都沒有問題,成功。
進行磁盤操作時請務必備份數據!!!