OpenEuler 操作系统磁盘根目录扩容
1.查看分区和磁盘情况(如下,vdb是没有被使用的)
[root@localhost ~]# ls /dev/
autofs dm-0 input ppp snd tty13 tty25 tty37 tty49 tty60 urandom vcsa vcsu6
block dm-1 kmsg ptmx sr0 tty14 tty26 tty38 tty5 tty61 usbmon0 vcsa1 vda
bsg dm-2 log pts sr1 tty15 tty27 tty39 tty50 tty62 usbmon1 vcsa2 vda1
btrfs-control dri loop-control random sr2 tty16 tty28 tty4 tty51 tty63 usbmon2 vcsa3 vda2
bus fb0 mapper raw stderr tty17 tty29 tty40 tty52 tty7 usbmon3 vcsa4 vdb
cdrom fd mcelog rfkill stdin tty18 tty3 tty41 tty53 tty8 usbmon4 vcsa5 vfio
char full mem rtc stdout tty19 tty30 tty42 tty54 tty9 vcs vcsa6 vga_arbiter
console fuse mqueue rtc0 tty tty2 tty31 tty43 tty55 ttyS0 vcs1 vcsu vhci
core hidraw0 net sg0 tty0 tty20 tty32 tty44 tty56 ttyS1 vcs2 vcsu1 vhost-net
cpu hpet null sg1 tty1 tty21 tty33 tty45 tty57 ttyS2 vcs3 vcsu2 vhost-vsock
cpu_dma_latency hugepages nvram sg2 tty10 tty22 tty34 tty46 tty58 ttyS3 vcs4 vcsu3 virtio-ports
cuse hwrng openeuler shm tty11 tty23 tty35 tty47 tty59 uhid vcs5 vcsu4 vport2p1
disk initctl port snapshot tty12 tty24 tty36 tty48 tty6 uinput vcs6 vcsu5 zero
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.6G 0 7.6G 0% /dev
tmpfs 7.6G 0 7.6G 0% /dev/shm
tmpfs 3.1G 8.6M 3.1G 1% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/mapper/openeuler-root 47G 1.8G 43G 4% /
tmpfs 7.6G 0 7.6G 0% /tmp
/dev/vda1 974M 87M 820M 10% /boot
/dev/mapper/openeuler-home 23G 24K 22G 1% /home
[root@localhost ~]# lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sr0 iso9660 Joliet Extension openEuler-22.03-LTS-x86_64 2022-03-30-08-44-34-00
sr1 iso9660 Joliet Extension castools 2023-06-26-23-34-18-00
sr2
vda
├─vda1 ext4 1.0 71fb67c4-a22f-4fdb-b6b4-f0962fb1cb04 819.6M 9% /boot
└─vda2 LVM2_member LVM2 001 AH2hhK-nj4P-RKh3-lPmd-eZ20-Q9z0-G8CU4p
├─openeuler-root
│ ext4 1.0 3cc1b574-5122-470f-b260-2bd675678ad0 42.6G 4% /
├─openeuler-swap
│ swap 1 43e4cbfe-6ae7-4115-9580-e978b6aa0568 [SWAP]
└─openeuler-home
ext4 1.0 6a755264-867c-4ffc-9f36-ab337696be4c 21.6G 0% /home
vdb
2.查看文件系统格式
[root@localhost ~]# blkid
/dev/mapper/openeuler-root: UUID="3cc1b574-5122-470f-b260-2bd675678ad0" BLOCK_SIZE="4096" TYPE="ext4"
/dev/vda2: UUID="AH2hhK-nj4P-RKh3-lPmd-eZ20-Q9z0-G8CU4p" TYPE="LVM2_member" PARTUUID="6f91a654-02"
/dev/mapper/openeuler-swap: UUID="43e4cbfe-6ae7-4115-9580-e978b6aa0568" TYPE="swap"
/dev/sr0: BLOCK_SIZE="2048" UUID="2022-03-30-08-44-34-00" LABEL="openEuler-22.03-LTS-x86_64" TYPE="iso9660" PTUUID="22bdc5ef" PTTYPE="dos"
/dev/mapper/openeuler-home: UUID="6a755264-867c-4ffc-9f36-ab337696be4c" BLOCK_SIZE="4096" TYPE="ext4"
/dev/vda1: UUID="71fb67c4-a22f-4fdb-b6b4-f0962fb1cb04" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="6f91a654-01"
/dev/sr1: BLOCK_SIZE="2048" UUID="2023-06-26-23-34-18-00" LABEL="castools" TYPE="iso9660"
[root@localhost ~]# blkid /dev/vda
/dev/vda: PTUUID="6f91a654" PTTYPE="dos"
3.创建新分区
[root@localhost ~]# cfdisk /dev/vdb
# 如果出现如下情况:
┌ Select label type ───┐
│ gpt │
│ dos │
│ sgi │
│ sun │
└──────────────────────┘
# 选择 dos类型并继续:
new -> write
4.将物理硬盘分区初始化为物理卷,以便被LVM使用
[root@localhost ~]# lvs
[root@localhost ~]# pvcreate /dev/vdb1
将 `/dev/vdb1` 设备(假设这是一个硬盘分区或独立的磁盘设备)转换为LVM物理卷。执行此命令后,/dev/vdb1 就可以作为LVM存储池的一部分,用于创建卷组(Volume Group)和逻辑卷(Logical Volume)
5.增加卷组容量
[root@localhost ~]# vgextend openeuler /dev/vdb1
6.查看可扩展的空间大小(Free PE / Size 表示可分配空间的最大值)
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name openeuler
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size 178.99 GiB
PE Size 4.00 MiB
Total PE 45822
Alloc PE / Size 20223 / <79.00 GiB
Free PE / Size 25599 / <100.00 GiB
VG UUID JwXroX-LdJj-YC2X-28fJ-Vhve-FZln-hDrpNa
7.自定义大小并扩容root目录
[root@localhost ~]# lvextend -L+99.99G /dev/mapper/openeuler-root
Rounding size to boundary between physical extents: 99.90 GiB.
Size of logical volume openeuler/root changed from <47.81 GiB (12239 extents) to 147.71 GiB (37814 extents).
Logical volume openeuler/root successfully resized.
[root@localhost ~]# resize2fs /dev/mapper/openeuler-root
resize2fs 1.46.4 (18-Aug-2021)
Filesystem at /dev/mapper/openeuler-root is mounted on /; on-line resizing required
old_desc_blocks = 6, new_desc_blocks = 19
The filesystem on /dev/mapper/openeuler-root is now 38743040 (4k) blocks long.
8.查看扩容后分区容量
[root@localhost ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.6G 0 3.6G 0% /dev
tmpfs 3.7G 0 3.7G 0% /dev/shm
tmpfs 1.5G 8.6M 1.5G 1% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/mapper/openeuler-root 146G 1.8G 137G 2% /
tmpfs 3.7G 0 3.7G 0% /tmp
/dev/vda1 974M 87M 820M 10% /boot
/dev/mapper/openeuler-home 23G 24K 22G 1% /home
[root@localhost ~]# lsblk -f
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sr0 iso9660 Joliet Extension openEuler-22.03-LTS-x86_64 2022-03-30-08-44-34-00
sr1 iso9660 Joliet Extension castools 2023-06-26-23-34-18-00
sr2
vda
├─vda1 ext4 1.0 5a32fa8a-8efd-41f2-b4a8-d7f80d8bb6d8 819.6M 9% /boot
└─vda2 LVM2_member LVM2 001 rYFqjG-pRNC-24tG-AEmg-Cq15-YMeH-A1fnrj
├─openeuler-root
│ ext4 1.0 52eed6d4-ab9c-4265-9f85-ad8f131c1e7e 136.9G 1% /
├─openeuler-swap
│ swap 1 e48c1076-4686-4708-856a-8fada3de45a9 [SWAP]
└─openeuler-home
ext4 1.0 39e5efc0-d0e0-4379-a199-022bb6f7912d 21.6G 0% /home
vdb
└─vdb1 LVM2_member LVM2 001 0fBbzO-0QGC-wBb4-eFng-xdIC-vVjj-3PBQOz
└─openeuler-root
ext4 1.0 52eed6d4-ab9c-4265-9f85-ad8f131c1e7e 136.9G 1% /
命令
- 列出所有磁盘设备及其分区信息:
fdisk -l
- 所有块设备的信息,并且包括其文件系统信息:
lsblk -f
- 查看文件系统的磁盘空间使用情况:
df -lh
- 显示所有可用块设备及其UUID和文件系统类型等信息:
blkid
或blkid /dev/[设备如vda]
- 列出所有的逻辑卷信息:
lvs
pvcreate
命令用于初始化一个新的物理卷:pvcreate /dev/vdb1
- 向已存在的卷组中添加新的物理卷(Physical Volume,此处为
/dev/vdb1
):vgextend openeuler /dev/vdb1
...