为 vmware 虚拟机磁盘扩容
磁盘空间不足,需要进行扩容 20G
df -h查看磁盘使用情况
Filesystem Size Used Avail Use% Mounted onudev 966M 0 966M 0% /devtmpfs 200M 2.6M 197M 2% /run/dev/mapper/ubuntu--vg-ubuntu--lv 19G 5.9G 12G 33% /tmpfs 997M 0 997M 0% /dev/shmtmpfs 5.0M 0 5.0M 0% /run/locktmpfs 997M 0 997M 0% /sys/fs/cgroup/dev/loop0 89M 89M 0 100% /snap/core/7270/dev/loop1 92M 92M 0 100% /snap/core/8689/dev/sda2 976M 145M 765M 16% /boottmpfs 200M 0 200M 0% /run/user/0
- 执行
parted
root@radius:/home/casa# parted /dev/vda
GNU Parted 3.2
Using /dev/vda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Warning: Not all of the space available to /dev/vda appears to be used, you can fix the GPT to use all of the space (an extra 62914560 blocks) or continue with the current setting?
Fix/Ignore? Fix
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 42.9GB
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 1076MB 1074MB ext4
3 1076MB 10.7GB 9661MB
- 对新加的硬盘进行分区,格式化
fdisk /dev/sda
root@SERVER-214:~# fdisk /dev/sda
Welcome to fdisk (util-linux 2.31.1).
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 number (5-128, default 5):
First sector (41943007-83886046, default 41943040):
Last sector, +sectors or +size{K,M,G,T,P} (41943040-83886046, default 83886046):
Created a new partition 5 of type 'Linux filesystem' and of size 20 GiB.
Command (m for help): t
Partition number (1-5, default 5):
Partition type (type L to list all types): 8e
Type of partition 5 is unchanged: Linux filesystem.
Command (m for help): w
The partition table has been altered.
Syncing disks.
其中空的选项为默认值,回车即可
同步磁盘
partprobe查看分区
root@SERVER-214:~# fdisk -l
Disk /dev/loop0: 88.5 MiB, 92778496 bytes, 181208 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 /dev/loop1: 91.4 MiB, 95805440 bytes, 187120 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 /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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: 35336CBB-AA0E-4985-9627-47299607B0AF
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 2101247 2097152 1G Linux filesystem
/dev/sda3 2101248 20969471 18868224 9G Linux filesystem
/dev/sda4 20969472 41943006 20973535 10G Linux filesystem
/dev/sda5 41943040 83886046 41943007 20G Linux filesystem
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 19 GiB, 20388511744 bytes, 39821312 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
root@SERVER-214:~# mkfs.ext4 /dev/sda5
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 5242875 4k blocks and 1310720 inodes
Filesystem UUID: afbfa28c-a567-4521-b211-7ca4fd396284
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
- 加新创建的 /dev/sda5 加入 pv 卷中
pvcreate /dev/sda5
root@SERVER-214:~# pvcreate /dev/sda5
WARNING: ext4 signature detected on /dev/sda5 at offset 1080. Wipe it? [y/n]: y
Wiping ext4 signature on /dev/sda5.
Physical volume "/dev/sda5" successfully created.
- 查看新的卷组
root@SERVER-214:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 ubuntu-vg lvm2 a-- <9.00g 0
/dev/sda4 ubuntu-vg lvm2 a-- <10.00g 4.00m
/dev/sda5 lvm2 --- <20.00g <20.00g
- 如果需要加到 lvs 中,查看另一篇教程
