root@ubuntu:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 468M 0 468M 0% /dev
tmpfs 98M 4.6M 93M 5% /run
/dev/mapper/ubuntu--vg-root 38G 2.0G 34G 6% /
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 472M 58M 391M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
本次的目标主要是扩展/dev/mapper/ubuntu--vg-root
的容量,我们将其从38G扩展到60G。
这个地方有两种操作方式:
root@ubuntu:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 468M 0 468M 0% /dev
tmpfs 98M 4.6M 93M 5% /run
/dev/mapper/ubuntu--vg-root 38G 2.0G 34G 6% /
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 472M 58M 391M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
发现跟最初查看时并没有什么变化。这是因为我们上面加入的磁盘只是扩展了空间,并没有挂载上去。
但是我们可以通过以下命令查看,虚拟机实际拥有的磁盘空间:
root@ubuntu:~# fdisk -l
Disk /dev/ram0: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram1: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram2: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram3: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram4: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram5: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram6: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram7: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram8: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram9: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram10: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram11: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram12: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram13: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram14: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram15: 64 MiB, 67108864 bytes, 131072 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/sda: 60 GiB, 64424509440 bytes, 125829120 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: dos
Disk identifier: 0x183be081
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 83884031 82882562 39.5G 5 Extended
/dev/sda5 1001472 83884031 82882560 39.5G 8e Linux LVM
Disk /dev/mapper/ubuntu--vg-root: 38.5 GiB, 41326477312 bytes, 80715776 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/mapper/ubuntu--vg-swap_1: 1020 MiB, 1069547520 bytes, 2088960 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
说明:
为了扩展/dev/mapper/ubuntu--vg-root
的空间,我们需要对LVM进行操作。
等待添加完成重启,然后使用fdisk -l
命令查看,既可看到一个新的硬盘,可能名称为:/dev/sdb
。
root@ubuntu:~# fdisk -l
...
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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@ubuntu:~# fdisk /dev/sda
Welcome to fdisk (util-linux 2.27.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 type
p primary (2 primary, 1 extended, 1 free)
l logical (numbered from 5)
Select (default p): p
Selected partition 4
First sector (83884032-125829119, default 83884032): 83884032
Last sector, +sectors or +size{K,M,G,T,P} (83884032-125829119, default 125829119): 125829119
Created a new partition 4 of type 'Linux' and of size 20 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 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).
说明:
fdisk /dev/sda
中的/dev/sda
是物理磁盘名称,如果是新增的一块磁盘,那么就需要使用新的名称,比如:/dev/sdb
3
。fdisk -l
查看新创建的分区root@ubuntu:~# fdisk -l
...
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 83884031 82882562 39.5G 5 Extended
/dev/sda3 999424 1001469 2046 1023K 83 Linux
/dev/sda4 83884032 125829119 41945088 20G 83 Linux
/dev/sda5 1001472 83884031 82882560 39.5G 8e Linux LVM
...
其中/dev/sda3
和/dev/sda4
为新建的分区。
重启服务。
root@ubuntu:~# pvcreate /dev/sda4
Physical volume "/dev/sda4" successfully created
root@ubuntu:~# vgdisplay
--- Volume group ---
VG Name ubuntu-vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 39.52 GiB
PE Size 4.00 MiB
Total PE 10117
Alloc PE / Size 10108 / 39.48 GiB
Free PE / Size 9 / 36.00 MiB
VG UUID EnOwTF-LaTQ-6JlW-efYJ-HtXv-dUEt-sKsKi9
root@ubuntu:~# vgextend ubuntu-vg /dev/sda4
Volume group "ubuntu-vg" successfully extended
这里面的ubuntu-vg
就是在vgdisplay
命令中展示的VG Name
。
此时再查看VG Size
会发现已经增加了。
上面我们已经说过,我们需要扩展的是/dev/mapper/ubuntu--vg-root
。所以,命令如下:
root@ubuntu:~# lvextend -L +20G /dev/mapper/ubuntu--vg-root
Size of logical volume ubuntu-vg/root changed from 38.49 GiB (9853 extents) to 58.49 GiB (14973 extents).
Logical volume root successfully resized.
root@ubuntu:~# resize2fs /dev/mapper/ubuntu--vg-root
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mapper/ubuntu--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 4
The filesystem on /dev/mapper/ubuntu--vg-root is now 15332352 (4k) blocks long.
root@ubuntu:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 468M 0 468M 0% /dev
tmpfs 98M 4.6M 93M 5% /run
/dev/mapper/ubuntu--vg-root 58G 2.0G 53G 4% /
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 472M 58M 391M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
到此我们已经顺利的将/dev/mapper/ubuntu--vg-root
扩展了20G。
全部评论