Linux 硬盘

1. Linux 硬盘

1.1. 基础知识

但是请大家记住:

  • 一个挂载点同一时间挂载一个设备
  • 一个挂载点同一时间挂载了多个设备, 只能看到最后一个设备的数据, 其他设备上的数据将被隐藏
  • 一个设备可以同时挂载到多个挂载点
  • 通常挂载点一般是已存在的空目录

还有一些常用的命令哦:

  • findmnt 命令可以查看文件夹是否有挂载点
  • lsof 命令可以查看某个挂载点是否在被人使用
  • blkid 命令查看 UUID
  • mount -a: 挂载立即生效
  • vim /etc/fstab 编辑文件夹可以修改永久挂载

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 (适用场景) 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. 虚拟机硬盘扩展过程

1.2.1. 发现问题

用虚拟机创建 300G 硬盘的 CentOS, 结果一进来发现只有 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. 开始调整分区

把消失的空间找回来。

# 打开 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

参考:

猜你喜欢

转载自blog.csdn.net/wan212000/article/details/130954844