Table of contents
1. Linux hard disk
1.1. Basic knowledge
But please remember:
- One mount point mounts one device at the same time
- A mount point mounts multiple devices at the same time, only the data of the last device can be seen, and the data on other devices will be hidden
- A device can be mounted to multiple mount points at the same time
- Usually the mount point is an existing empty directory
There are also some commonly used commands:
findmnt
The command can check whether the folder has a mount pointlsof
The command can check whether a mount point is being used by someoneblkid
Command to view UUIDmount -a
: The mount takes effect immediatelyvim /etc/fstab
Edit folder can modify permanent mount
1.1.1. Primary vs. Extended Partition
Difference | Primary partition | Extended partition |
---|---|---|
Quantity | At least 1 and a maximum of 4. | Cannot use extended partition directly. It is used as a logical partition so that the extended partition consists of several logical partitions. |
Bootable | The primary partition is bootable, and it contains the operating system/s of the computer. | The extended partition is a partition that is not bootable. |
Applicable scenarios (applicable scenarios) | We can use it to boot the operating system, establish one to four primary partitions and install multiple operating systems without interfering. | Extended partitions do not store files directly but create logical partitions to store general data, audio, pictures, and files. |
Naming example | Primary partitions are assigned the first letters in the alphabet as drive letters (such as C, D). | Logical drives in the extended partition get the other letters (such as E, F, G). |
1.2. Virtual machine hard disk expansion process
1.2.1. Problems found
Use a virtual machine to create a CentOS with a 300G hard disk, but when it comes in, it is only 35G:
# df - report file system disk space usage
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 35G 2.1G 33G 6% /
devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 8.8M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/sda1 1014M 133M 882M 14% /boot
tmpfs 396M 0 396M 0% /run/user/0
# lsblk - list block devices
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 300G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 39G 0 part
├─centos-root 253:0 0 35G 0 lvm /
└─centos-swap 253:1 0 4G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
# fdisk - manipulate disk partition table
fdisk -l
Disk /dev/sda: 322.1 GB, 322122547200 bytes, 629145600 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 label type: dos
Disk identifier: 0x000f1bd2
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
Disk /dev/mapper/centos-root: 37.6 GB, 37576769536 bytes, 73392128 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/centos-swap: 4294 MB, 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
1.2.2. Start to adjust the partition
Bring back the lost space.
# 打开 sdb 盘进行分区
fdisk /dev/sda
m # m for help
n # add a new partition
[default]... # 一直按回车就可以了
p # print the partition table
w # write table to disk and exit
reboot
# ls /lib/modules/`uname -r`/kernel/fs # 判断当前的内核支持哪些文件系统
# lsblk -f # 查看一下刚刚添加的文件系统
# mkfs.xfs /dev/sda3 # 创建 ext4 的文件系统到硬盘 b 的 1 分区
# 给刚刚新建的分区 /dev/sda3
# pvcreate - Initialize physical volume(s) for use by LVM
pvcreate /dev/sda3
# 查看 vg 组
# vgs - Display information about volume groups
vgs
# 扩展 vg
# vgextend - Add physical volumes to a volume group
vgextend centos /dev/sda3
# lvs - Display information about logical volumes
lvs
# lvextend - Add space to a logical volume
lvextend -l +100%FREE /dev/centos/root
# 使系统重新读取大小
# xfs_growfs, xfs_info - expand an XFS filesystem
xfs_growfs /dev/mapper/centos-root
reboot
reference: