1、fdisk -l 查看磁盘情况,可以看到总共4块磁盘,sda是系统盘及根目录,剩余sdb、sdc、sdd三块磁盘可用
[root@openEuler dev]# fdisk -l
Disk /dev/sdd: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VBOX HARDDISK
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: 0xa7c7a1e0
Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VBOX HARDDISK
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: 0x08450d55
Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VBOX HARDDISK
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: EAA79339-30ED-4ABF-8801-C9516611767C
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VBOX HARDDISK
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: 0xeae28f32
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 411647 409600 200M 83 Linux
/dev/sda2 * 411648 821247 409600 200M 6 FAT16
/dev/sda3 821248 30197759 29376512 14G 8e Linux LVM
Disk /dev/mapper/openeuler-root: 10 GiB, 10737418240 bytes, 20971520 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/openeuler-swap: 4 GiB, 4294967296 bytes, 8388608 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
2、磁盘分区,
方式一:fdisk分区(将/dev/sdb分成两个5G的区)
[root@openEuler dev]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.37.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 #要进行的操作,n表示新建分区
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): # p表示新建主分区,默认p直接回车
Using default response p.
Partition number (2-4, default 2): # 设置分区号,我之前创建过1了,所有现在默认2,直接回车
First sector (10487808-20971519, default 10487808): #设置起始位置,默认就行
Last sector, +/-sectors or +/-size{K,M,G,T,P} (10487808-20971519, default 20971519): #设置结束位置,我这里是第二个分区了,默认到最后,第一个分区起始是0,结束位置写+5G,表示分配5G的大小
Created a new partition 2 of type 'Linux' and of size 5 GiB.
Command (m for help): w # w保存并退出,q退出不保存
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
方式二:(推荐)parted分区(将/dev/sdc分成一个3G,一个7G的)
[root@openEuler dev]# parted /dev/sdc mkpart gpt 0% 30% #创建分区,起始位置0%,结束位置30%
Information: You may need to update /etc/fstab.
[root@openEuler dev]# parted /dev/sdc mkpart gpt 30% 100%
Information: You may need to update /etc/fstab.
3、fdisk -l 查看分区结果符合预期,sdb1、sdb2各5G,sdc1 3G,sdc2 7G
[root@openEuler dev]# fdisk -l
Disk /dev/sdd: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VBOX HARDDISK
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: 0xa7c7a1e0
Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VBOX HARDDISK
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: 0x08450d55
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 10487807 10485760 5G 83 Linux
/dev/sdb2 10487808 20971519 10483712 5G 83 Linux
Disk /dev/sdc: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: VBOX HARDDISK
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: EAA79339-30ED-4ABF-8801-C9516611767C
Device Start End Sectors Size Type
/dev/sdc1 2048 6291455 6289408 3G Linux filesystem
/dev/sdc2 6291456 20969471 14678016 7G Linux filesystem
4、挂载:
方式一:直接挂载分区(不推荐,后期无法动态扩容)mount /dev/sdb1 /home
方式二:挂载逻辑卷
(1)创建物理卷
[root@openEuler dev]# pvcreate /dev/sdb{1,2}
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
[root@openEuler dev]# pvcreate /dev/sdc{1,2}
Physical volume "/dev/sdc1" successfully created.
Physical volume "/dev/sdc2" successfully created.
[root@openEuler dev]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 openeuler lvm2 a-- 14.00g 4.00m
/dev/sdb1 lvm2 --- 5.00g 5.00g
/dev/sdb2 lvm2 --- <5.00g <5.00g
/dev/sdc1 lvm2 --- <3.00g <3.00g
/dev/sdc2 lvm2 --- <7.00g <7.00g
(2)创建卷组(不知道为啥出0.02G误差,问题不大)
[root@openEuler dev]# vgcreate testvg /dev/sdb1 /dev/sdb2 /dev/sdc1 /dev/sdc2 #testvg是卷组名称,后面是多个物理卷
Volume group "testvg" successfully created
[root@openEuler dev]# vgs
VG #PV #LV #SN Attr VSize VFree
openeuler 1 2 0 wz--n- 14.00g 4.00m # 系统的
testvg 4 0 0 wz--n- 19.98g 19.98g # 刚创建的
(3)创建逻辑卷(一个8G,一个12G(上面开始出了20M误差))
[root@openEuler dev]# lvcreate -L 8G testvg #直接指定大小8G,testvg是卷组名
Logical volume "lvol0" created.
[root@openEuler dev]# lvcreate -l 100%FREE testvg #按剩余容量的百分比分配
Logical volume "lvol1" created.
[root@openEuler dev]# lvs #查看,有lvol0和lvol1两个逻辑卷
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root openeuler -wi-ao---- 10.00g
swap openeuler -wi-ao---- 4.00g
lvol0 testvg -wi-a----- 8.00g
lvol1 testvg -wi-a----- 11.98g
(4)格式化逻辑卷(只有第一次新建需要格式化)
[root@openEuler ~]# mkfs.ext4 /dev/testvg/lvol0
mke2fs 1.46.4 (18-Aug-2021)
Creating filesystem with 2097152 4k blocks and 524288 inodes
Filesystem UUID: 394e80e2-1096-4158-8953-232ea07cbef2
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@openEuler ~]# mkfs.ext4 /dev/testvg/lvol1
mke2fs 1.46.4 (18-Aug-2021)
Creating filesystem with 3141632 4k blocks and 786432 inodes
Filesystem UUID: 6e569e9d-cb54-4592-a77e-e6e0d0c3d491
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
(5)挂载
[root@openEuler ~]# df -h #挂载前
Filesystem Size Used Avail Use% Mounted on
devtmpfs 716M 0 716M 0% /dev
tmpfs 733M 12K 733M 1% /dev/shm
tmpfs 293M 4.4M 289M 2% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/mapper/openeuler-root 9.8G 2.5G 6.9G 27% /
tmpfs 733M 0 733M 0% /tmp
/dev/sda1 182M 87M 82M 52% /boot
/dev/sda2 200M 8.0K 200M 1% /boot/efi
/dev/mapper/openeuler-swap 3.9G 24K 3.7G 1% /swap
[root@openEuler ~]# mount /dev/testvg/lvol0 /home #挂载
[root@openEuler ~]# mount /dev/testvg/lvol1 /data
[root@openEuler ~]# df -h #挂载后,多出/home和/data两个挂载点
Filesystem Size Used Avail Use% Mounted on
devtmpfs 716M 0 716M 0% /dev
tmpfs 733M 12K 733M 1% /dev/shm
tmpfs 293M 4.4M 289M 2% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/mapper/openeuler-root 9.8G 2.5G 6.9G 27% /
tmpfs 733M 0 733M 0% /tmp
/dev/sda1 182M 87M 82M 52% /boot
/dev/sda2 200M 8.0K 200M 1% /boot/efi
/dev/mapper/openeuler-swap 3.9G 24K 3.7G 1% /swap
/dev/mapper/testvg-lvol1 12G 24K 12G 1% /data
/dev/mapper/testvg-lvol0 7.8G 24K 7.4G 1% /home
(6)扩容,现在还有一块sdd磁盘未使用,步骤是分区、创建物理卷、加入到已有的卷组(上面创建好的testvg)、给逻辑卷分配容量、刷新逻辑卷
[root@openEuler ~]# parted /dev/sdd mkpart 0% 100% # 分区
Information: You may need to update /etc/fstab.
[root@openEuler ~]# pvcreate /dev/sdd1 # 创建物理卷
Physical volume "/dev/sdd1" successfully created.
[root@openEuler ~]# vgextend testvg /dev/sdd1 # 把物理卷加到卷组
Volume group "testvg" successfully extended
[root@openEuler ~]#lvextend -l +50%FREE /dev/testvg/lvol0 # 把50%空闲容量分配给lvol0逻辑卷
WARNING: Reducing active and open logical volume to 5.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testvg/lvol0? [y/n]: y
Size of logical volume testvg/lvol0 changed from 8.00 GiB (2048 extents) to 5.00 GiB (1280 extents).
Logical volume testvg/lvol0 successfully resized.
[root@openEuler ~]# resize2fs /dev/testvg/lvol2 # 刷新逻辑卷
resize2fs 1.46.4 (18-Aug-2021)
Filesystem at /dev/testvg/lvol2 is mounted on /home; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/testvg/lvol2 is now 3407872 (4k) blocks long.
[root@openEuler ~]# df -h # 扩容成功,/home挂载点从8G变成了13G
Filesystem Size Used Avail Use% Mounted on
devtmpfs 716M 0 716M 0% /dev
tmpfs 733M 12K 733M 1% /dev/shm
tmpfs 293M 4.4M 289M 2% /run
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
/dev/mapper/openeuler-root 9.8G 2.5G 6.9G 27% /
tmpfs 733M 0 733M 0% /tmp
/dev/sda1 182M 87M 82M 52% /boot
/dev/sda2 200M 8.0K 200M 1% /boot/efi
/dev/mapper/openeuler-swap 3.9G 24K 3.7G 1% /swap
/dev/mapper/testvg-lvol1 12G 24K 12G 1% /data
/dev/mapper/testvg-lvol0 13G 40M 13G 1% /home