24.Linux硬盘分区管理 - 详解

news/2025/9/25 19:14:36/文章来源:https://www.cnblogs.com/lxjshuju/p/19111823

文章目录

  • Linux 硬盘分区管理
    • 硬盘为什么要分区?
    • MBR 分区方案
    • fdisk 工具
      • fdisk命令语法
      • 查看分区
      • 创建分区
      • 删除分区
      • 非交互方式管理
    • GPT 分区方案
    • gdisk 工具
      • gdisk命令语法
      • 查看分区表
      • 转换分区表方案
      • 创建分区
      • 更改分区名称
      • 查看分区详细信息
      • 删除分区
    • wipefs 工具
    • parted 工具
      • 查看分区表
      • 设置单位
      • 管理 MBR 磁盘
        • 设置磁盘分区管理方案
        • 创建分区
        • 扩展分区
        • 删除分区
        • 免交互操作
      • 管理 GPT 磁盘
        • 设置磁盘分区管理方案
        • 创建分区
        • 扩展分区
        • 删除分区
        • 免交互操作
    • 文件系统持久化挂载
      • 环境准备
      • 持久化挂载
      • 取消持久化挂载
    • 综合案例:文件系统空间不足
      • 情况1:大量的大文件占用空间
      • 情况2:删除文件后,空间没有释放
      • 情况3:大量的小文件占用空间
    • 思考:如何彻底擦除硬盘上数据

Linux 硬盘分区管理

硬盘为什么要分区?

举一个通俗的例子:

想象一下,你有一栋全新的、空荡荡的大毛坯楼。这就是你的一块新硬盘

现在,这栋楼太大了,你想把它分成不同的区域来做不同的事。这个“划分区域”的过程,就是分区

光划分出空间还不够,每个公司需要把自己的区域装修和布置成适合自己工作的样子。这个“装修”的过程,就是格式化

最后,你要让大楼里的人能进去工作,就需要给每个区域一个入口和门牌号。这个就是挂载

类比Windows的硬盘分区

在这里插入图片描述

在Windows上:

  1. 插上硬盘。
  2. 打开“磁盘管理”。
  3. 找到新磁盘,初始化(选择分区表,就像决定大楼用哪种蓝图)。
  4. 新建简单卷(划分分区,比如分出D盘和E盘)。
  5. 格式化(选择NTFS或exFAT,即“装修”)。
  6. 完成!系统自动分配了 D:E: 盘符,你可以在“此电脑”里直接访问了。

在Linux上:

  1. 插上硬盘。
  2. 使用 fdiskgdisk 工具对磁盘进行分区(划分出 /dev/sdb1/dev/sdb2)。
  3. 使用 mkfs 命令格式化分区(如 sudo mkfs.ext4 /dev/sdb1)。
  4. 创建挂载点(即空目录,如 sudo mkdir /mnt/data)。
  5. 手动挂载(如 sudo mount /dev/sdb1 /mnt/data)。
  6. 现在,你可以通过访问 /mnt/data 目录来使用这个新硬盘的空间了。
  7. (可选)为了开机自动挂载,需要将挂载信息写入 /etc/fstab 配置文件。

MBR 分区方案

自 1982年以来,主启动记录(MBR)分区方案指定了在运行 BIOS 固件的系统上如何对磁盘进行分区:

在这里插入图片描述

  • 该方案支持最多4个主分区。

  • 在 Linux系统上,管理员可以使用扩展分区和逻辑分区来创建最多 15个分区

    逻辑分区是可以格式化(format),扩展分区是不可以格式化。

  • MBR 记录用4个字节(1byte=8bit)存储分区的总扇区数,最大能表示2的32次方的扇区个数,按每扇区512字节计算,每个分区最大不能超过 2 TiB

类比为:笔记本只有4个usb接口,如果不够用,则将第四个usb接口外接扩展坞,由扩展坞提供多个usb接口。

通常,我们将磁盘第一个扇区称为主引导扇区,位于硬盘的柱面0、磁头0、扇区1的位置,这一扇区包含MBR引导代码,承担系统启动职能。它不属于磁盘上任何分区,因而分区空间内的格式化命令不能清除主引导记录的任何信息。

主引导扇区由三个部分组成:

在这里插入图片描述

  • 引导程序(占446个字节),硬盘启动时将系统控制权转给分区表中的某个操作系统。
  • 磁盘分区表项(DPT,Disk Partition Table),由四个分区表项构成(每个16个字节)。
  • 结束标志(占2个字节),其值为AA55(十六进制)。

fdisk 工具

fdisk 工具可用于管理采用 MBR 分区方案的磁盘,用户可以根据实际情况进行划分分区。

fdisk命令语法

[root@server ~ 17:21:17]# fdisk -h
用法:
fdisk [选项] <磁盘> 更改分区表fdisk [选项] -l <磁盘> 列出分区表fdisk -s <分区> 给出分区大小(块数)选项:-b <大小> 扇区大小(512、1024、2048或4096)-c[=<模式>] 兼容模式:“dos”或“nondos”(默认)-h 打印此帮助文本-u[=<单位>] 显示单位:“cylinders”(柱面)或“sectors”(扇区,默认)-v 打印程序版本-C <数字> 指定柱面数-H <数字> 指定磁头数-S <数字> 指定每个磁道的扇区数

除了使用-l选项查看分区表,其他选项暂时都不用。

查看分区

fdisk工具大部分操作通过交互式完成,出了查看分区表。

DOS disklabel 指的硬盘管理方式是MBR。

我们使用上一章准备的一块硬盘/dev/sdb。

# 方法1:
[root@server ~ 17:40:51]# fdisk -l /dev/sdb
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
# 方法2:
[root@server ~ 17:41:10]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0xdfb0ed89 创建新的 DOS 磁盘标签。
# 输入m,查看帮助信息
Command (m for help): `m`
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
# 输入p,打印分区表
Command (m for help): p
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xdfb0ed89
设备 Boot Start End Blocks Id System
# 输入q,退出管理
Command (m for help): q

创建分区

# 输入n,创建一个新分区
Command (m for help): `n`
# 选择分区类型
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
# 直接回车,选择默认分区类型:primary
Select (default p): `回车`
Using default response p
# 直接回车,分区号,使用默认值1
分区号 (1-4,默认 1)`回车`
# 直接回车,设置分区起始位置为:默认值2048扇区,也就是1M位置。
起始 扇区 (2048-41943039,默认为 2048)`回车`
将使用默认值 2048
# 设置分区结束位置,输入+2G,也就是起始位置之后2
Last 扇区, +扇区 or +size{K,M,G
} (2048-41943039,默认为 41943039):+2G
分区 1 已设置为 Linux 类型,大小设为 2 GiB
Command (m for help): p
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x14871d1b
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
# 输入w,保存更改并退出
# 输入q,不保存更改并退出
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
# 再次验证分区表变化
[root@server ~ 17:44:10]# lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 2G 0 part

注意:如果此时分区表未生成,执行以下命令,通知kernel重新生成分区表。有时候重启系统才会生成最新分区表。

[root@server ~ 17:44:33]# partprobe

删除分区

[root@server ~ 17:45:06]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
# 输入p,打印分区表
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0x78ceaffe
Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 83 Linux
# 输入d,删除分区,因为只有1个分区,所以自动删除了第一个分区
命令(输入 m 获取帮助):d
已选择分区 1
分区 1 已删除
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x14871d1b
设备 Boot Start End Blocks Id System

如果硬盘空间比较大,需要的文件系统数量超过4个,那么就需要借助扩展分区创建逻辑分区了。

如下示例,创建第4个分区的时候,类型选择扩展分区;创建第5个分区的时候,类型选择逻辑分区。

[root@server ~ 17:46:05]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
# 再次创建一个容量为3G的分区
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (4196352-41943039, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G
} (4196352-41943039, default 41943039): +3G
Partition 2 of type Linux and of size 3 GiB is set
# 再次创建一个容量为4G的分区
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (10487808-41943039, default 10487808):
Using default value 10487808
Last sector, +sectors or +size{K,M,G
} (10487808-41943039, default 41943039): +4G
Partition 3 of type Linux and of size 4 GiB is set
# 创建第4个分区的时候,选择扩展分区,并且使用剩余所有容量
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e):
Using default response e
Selected partition 4
First sector (18876416-41943039, default 18876416):
Using default value 18876416
Last sector, +sectors or +size{K,M,G
} (18876416-41943039, default 41943039):
Using default value 41943039
Partition 4 of type Extended and of size 11 GiB is set
# 创建第5个分区:在扩展分区中,创建逻辑分区,分配5G容量
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (18878464-41943039, default 18878464):
Using default value 18878464
Last sector, +sectors or +size{K,M,G
} (18878464-41943039, default 41943039): +5G
Partition 5 of type Linux and of size 5 GiB is set
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0x78ceaffe
Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 10487807 3145728 83 Linux
/dev/sdb3 10487808 18876415 4194304 83 Linux
/dev/sdb4 18876416 41943039 11533312 5 Extended
/dev/sdb5 18878464 29364223 5242880 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
# 查看分区表
[root@server ~ 17:48:00]# lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 2G 0 part
├─sdb2 8:18 0 3G 0 part
├─sdb3 8:19 0 4G 0 part
└─sdb4 8:20 0 1K 0 part

创建分区演示完成,只保留1个分区,多余的删除。

[root@server ~ 17:49:46]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): d
Partition number (1-5, default 5):
Partition 5 is deleted
Command (m for help): d
Partition number (1-4, default 4):
Partition 4 is deleted
Command (m for help): d
Partition number (1-3, default 3):
Partition 3 is deleted
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 is deleted
Command (m for help): d
Selected partition 1
Partition 1 is deleted
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

非交互方式管理

示例1:创建一个分区

# 将要执行的fdisk命令行写入到一个文本文件
[root@server ~ 17:51:29]# vim fdisk-create.txt
n
p
1
2048
+2G
p
w
# 执行
[root@server ~ 17:51:59]# fdisk /dev/sdb < fdisk-create.txt
[root@server ~ 17:52:34]# lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 2G 0 part

示例2:删除一个分区

# 将要执行的fdisk命令行写入到一个文本文件
[root@server ~ 17:53:13]# vim fdisk-delete.txt
d
p
w
# 执行
[root@server ~ 17:53:29]# fdisk /dev/sdb < fdisk-delete.txt
[root@centos7 ~]# lsblk /dev/sdb
[root@server ~ 17:53:35]# lsblk /dev/sdb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 20G 0 disk

GPT 分区方案

GPT是运行统一可扩展固件接口(UEFI)固件系统上硬盘分区表的标准。

  • MBR分区方案只能管理最大2TiB分区和磁盘。全局唯一标识分区表(GPT,GUID Partition Table)使用8个字节(1byte=8bit)存储分区的总扇区数,可支持最多8 ZiB(=264*512 Byte),即80亿太字节的分区和磁盘。

  • MBR分区方案支持最多15个分区。GPT分区方案最多可提供128个分区

  • GPT提供分区表信息的冗余

GPT分区表结构如下:

在这里插入图片描述

  • LBA0(保护性MBR),分为两个部分:

    • 第一部分是与MBR中446字节相似的区块,用于存放第一阶段的启动引导程序

    • 第二部分是与MBR分区表记录区对应,该区域存储一个特殊标识符0xEE,用于表示该磁盘为GPT格式。若磁盘管理程序(比较老的软件)无法识别该磁盘,不能修改这个分区信息,进一步保护磁盘。

  • LBA1(GPT表头记录),记录了分区表自身的位置和大小,同时也记录了前面提到备份用的GPT分区所在位置(最后34个LBA),还放置了分区表的校验码(CRC32),校验码的作用是让操作系统判断GPT的正确与否,倘若发现错误则可以从备份的GPT中恢复正常运行。

  • LBA2-33,记录分区信息,每个LBA可以提供4组的分区记录,默认情况下可以有4×32=128组分区记录。因为每个LBA都有512字节,所以每组分区记录所占128字节,除去每组记录需要的标识符和相关记录信息外,GPT在每组记录中提供了64位记载分区的扇区总数。

  • 虽然GPT最大支持128个分区,但是实际使用过程中分区超过第120个会出现无法格式化使用的情况。

gdisk 工具

gdisk工具用于管理采用GPT分区方案的磁盘分区,主要用于管理磁盘容量超过2T的磁盘。

gdisk命令语法

gdisk [ -l ] device

查看分区表

[root@server ~ 17:55:16]# gdisk -l /dev/sdb
GPT fdisk (gdisk) version 0.8.10
# 这里显示识别到了MBR分区方案
Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present
***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory.
***************************************************************
Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): A774FD5A-4047-43D9-8CF9-534D87DFE799
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 41942973 sectors (20.0 GiB)
Number Start (sector) End (sector) Size Code Name

转换分区表方案

gdisk工具用于管理gpt分区,所以我们需要将磁盘的分区管理方案由MBR转换成GPT。

[root@server ~ 17:55:33]# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present
***************************************************************
Found invalid GPT and valid MBR; converting MBR to GPT format
in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by
typing 'q' if you don't want to convert your MBR partitions
to GPT format!
***************************************************************
# 输入?,查看帮助信息。gdisk管理命令跟fdisk很相似。
Command (? for help): ?
b back up GPT data to a file
c change a partition's name
d delete a partition
i show detailed information on a partition
l list known partition types
n add a new partition
o create a new empty GUID partition table (GPT)
p print the partition table
q quit without saving changes
r recovery and transformation options (experts only)
s sort partitions
t change a partition's type code
v verify disk
w write table to disk and exit
x extra functionality (experts only)
? print this menu
# 输入o,将磁盘的分区管理方案由MBR转换成GPT
Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): Y
# 输入p,查看分区表
Command (? for help): p
Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 99FE6E5F-8316-428D-BA81-D824C786CC43
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 41942973 sectors (20.0 GiB)
Number Start (sector) End (sector) Size Code Name
# 输入w,保存更改并退出
# 输入q,不保存更改并退出
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.

创建分区

[root@server ~ 17:57:08]# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.10
# 这里识别到了GPT分区方案
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
# 输入n,创建新分区
Command (? for help): `n`
# 设置分区ID
Partition number (1-128, default 1): `回车`
# 设置分区起始位置
First sector (34-41943006, default = 2048) or {+-
}size{KMGTP
}: `回车`
# 设置分区结束位置
Last sector (2048-41943006, default = 41943006) or {+-
}size{KMGTP
}: `+2G`
Current type is 'Linux filesystem'
# 设置分区类型,输入L查看所有分区类型
Hex code or GUID (L to show codes, Enter = 8300): `L`
0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE
3000 ONIE boot 3001 ONIE config 4100 PowerPC PReP boot
4200 Windows LDM data 4201 Windows LDM metadata 7501 IBM GPFS
7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved
8200 Linux swap 8300 Linux filesystem 8301 Linux reserved
8302 Linux /home 8400 Intel Rapid Start 8e00 Linux LVM
a500 FreeBSD disklabel a501 FreeBSD boot a502 FreeBSD swap
a503 FreeBSD UFS a504 FreeBSD ZFS a505 FreeBSD Vinum/RAID
a580 Midnight BSD data a581 Midnight BSD boot a582 Midnight BSD swap
a583 Midnight BSD UFS a584 Midnight BSD ZFS a585 Midnight BSD Vinum
a800 Apple UFS a901 NetBSD swap a902 NetBSD FFS
a903 NetBSD LFS a904 NetBSD concatenated a905 NetBSD encrypted
a906 NetBSD RAID ab00 Apple boot af00 Apple HFS/HFS+
af01 Apple RAID af02 Apple RAID offline af03 Apple label
af04 AppleTV recovery af05 Apple Core Storage be00 Solaris boot
bf00 Solaris root bf01 Solaris /usr & Mac Z bf02 Solaris swap
bf03 Solaris backup bf04 Solaris /var bf05 Solaris /home
bf06 Solaris alternate se bf07 Solaris Reserved 1 bf08 Solaris Reserved 2
bf09 Solaris Reserved 3 bf0a Solaris Reserved 4 bf0b Solaris Reserved 5
c001 HP-UX data c002 HP-UX service ea00 Freedesktop $BOOT
eb00 Haiku BFS ed00 Sony system partitio ed01 Lenovo system partit
# 输入回车继续查看
Press the <Enter> key to see more codes:`回车`ef00 EFI System ef01 MBR partition scheme ef02 BIOS boot partitionfb00 VMWare VMFS fb01 VMWare reserved fc00 VMWare kcore crash pfd00 Linux RAID# 输入回车,选择默认分区类型Hex code or GUID (L to show codes, Enter = 8300):Changed type of partition to 'Linux filesystem'# 输入p,查看分区表Command (? for help): pDisk /dev/sdb: 41943040 sectors, 20.0 GiBLogical sector size: 512 bytesDisk identifier (GUID): 715BA9C0-A82A-4617-A5DD-475C126F34CBPartition table holds up to 128 entriesFirst usable sector is 34, last usable sector is 41943006Partitions will be aligned on 2048-sector boundariesTotal free space is 37748669 sectors (18.0 GiB)Number Start (sector) End (sector) Size Code Name1 2048 4196351 2.0 GiB 8300 Linux filesystem

更改分区名称

# 输入c,修改分区ID为1的分区名
Command (? for help): c
Using 1
# 输入新名称
Enter name: data01
# 查看分区表
Command (? for help): p
Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 715BA9C0-A82A-4617-A5DD-475C126F34CB
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 37748669 sectors (18.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 4196351 2.0 GiB 8300 data01

查看分区详细信息

Command (? for help): i
Using 1
Partition GUID code: 0FC63DAF-8483-4772-8E79-3D69D8477DE4 (Linux filesystem)
Partition unique GUID: 172EDA13-1535-4D24-9CF0-117202B93CE6
First sector: 2048 (at 1024.0 KiB)
Last sector: 4196351 (at 2.0 GiB)
Partition size: 4194304 sectors (2.0 GiB)
Attribute flags: 0000000000000000
Partition name: 'data01'

删除分区

# 输入d,删除分区ID为1的分区
Command (? for help): d
Using 1
Command (? for help): p
Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 715BA9C0-A82A-4617-A5DD-475C126F34CB
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 41942973 sectors (20.0 GiB)
Number Start (sector) End (sector) Size Code Name
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.

wipefs 工具

作用:清除磁盘分区表信息。

注意:数据无价,操作需谨慎,最好提前备份。

# 清除未挂载磁盘的分区表
[root@server ~ 17:59:30]# wipefs -a /dev/sdb
# 禁止使用 -f 强制清除分区表
[root@centos7 ~]# wipefs -fa /dev/sdb

parted 工具

parted 工具既可以管理采用MBR分区方案的磁盘,又可以管理采用GPT分区方案的磁盘。

parted 命令同时支持交互式操作和非交互式操作(编写脚本)。

我们先来看看交互式操作。

操作流程:

  1. 查看分区表。如果是未初始化硬盘,创建分区。
  2. 设置单位(MiB)
  3. 创建分区
  4. 调整分区大小
  5. 调整分区类型
  6. 删除分区

查看分区表

[root@server ~ 17:59:39]# parted /dev/sdb
GNU Parted 3.1
使用 /dev/sdb
# 查看帮助,输入help
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) `help`
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices,
free space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
resizepart NUMBER END resize partition NUMBER
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright
information of GNU Parted
# 查看分区表,输入 print
(parted) print
错误: /dev/sdb: unrecognised disk label
Model: ATA VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:

设置单位

parted工具默认单位是MB(103K),设置为MiB(210KiB)

(parted) unit MiB

管理 MBR 磁盘

设置磁盘分区管理方案
# 输入mklabel或mktable设置磁盘分区管理方案
# 设置分区方案为msdos,也就是MBR,输入mklabel msdos
(parted) `mklabel msdos`
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will
be lost. Do you want to continue?
# 确认更改,输入y
Yes/No? `y`
(parted) print
Model: ATA VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
# 分区表已改成msdos

**注意:**parted命令所做更改立刻生效。

创建分区
# 创建分区,输入 mkpart
(parted) `mkpart`
# 设置分区类型,输入 primary
分区类型? primary/主分区/extended/扩展分区? primary
# 设置分区文件系统类型,输入 xfs,实际不生效,格式化文件系统仍需手动操作
文件系统类型? [ext2]? xfs
# 设置分区起始位置,输入 1
起始点? 1
# 设置分区结束位置,输入 2049
结束点? 2049
(parted) print
Model: ATA VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
1 1.00MiB 2049MiB 2048MiB primary xfs
扩展分区
# 1 代表分区号,4097代表分区结束位置
(parted) resizepart 1 4097
(parted) print
Model: ATA VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
1 1.00MiB 4097MiB 4096MiB primary xfs
删除分区
# 1 代表分区号
(parted) rm 1
(parted) print
Model: ATA VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
免交互操作
# 设置磁盘分区管理方案
[root@server ~ 18:07:21]# parted /dev/sdb mklabel msdos
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this
disk will be lost. Do you want to continue?
Yes/No? y
Information: You may need to update /etc/fstab.
# 查看分区
[root@server ~ 18:07:36]# parted /dev/sdb unit MiB print
Model: ATA VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
# 创建分区
[root@server ~ 18:07:43]# parted /dev/sdb unit MiB mkpart primary 1 2049
信息: You may need to update /etc/fstab.
[root@server ~ 18:07:59]# parted /dev/sdb unit MiB print
Model: ATA VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
1 1.00MiB 2049MiB 2048MiB primary xfs
# 扩展分区
[root@server ~ 18:08:14]# parted /dev/sdb unit MiB resizepart 1 5121
信息: You may need to update /etc/fstab.
[root@server ~ 18:08:29]# parted /dev/sdb unit MiB print
Model: ATA VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
1 1.00MiB 5121MiB 5120MiB primary xfs
# 删除分区
[root@server ~ 18:08:41]# parted /dev/sdb rm 1
信息: You may need to update /etc/fstab.
[root@server ~ 18:09:01]# parted /dev/sdb unit MiB print 
Model: ATA VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志

管理 GPT 磁盘

管理GPT磁盘基本与管理MBR磁盘一致,除了创建分区。

设置磁盘分区管理方案
# 设置分区方案为gpt,输入mklabel gpt
(parted) `mklabel gpt`
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will
be lost. Do you want to continue?
Yes/No? y
(parted) print
Model: ATA VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
创建分区
(parted) unit mib
(parted) mkpart
分区名称? []? data01
文件系统类型? [ext2]? xfs
起始点? 1
结束点? 2049
(parted) print
Model: ATA VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
1 1.00MiB 2049MiB 2048MiB xfs data01
扩展分区
(parted) resizepart 1 5121
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1.00MiB 5121MiB 5120MiB xfs data01
删除分区
(parted) rm 1
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
免交互操作
# 设置磁盘分区管理方案
[root@server ~ 18:14:31]# parted /dev/sdb mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this
disk will be lost. Do you want to continue?
Yes/No? y
Information: You may need to update /etc/fstab.
# 查看分区
[root@server ~ 18:14:43]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
# 创建分区
[root@server ~ 18:15:04]# parted /dev/sdb unit MiB mkpart data01 xfs 1 2049
信息: You may need to update /etc/fstab.
[root@server ~ 18:15:19]# parted /dev/sdb unit MiB print 
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1.00MiB 2049MiB 2048MiB xfs data01
# 扩展分区
[root@server ~ 18:15:35]# parted /dev/sdb unit MiB resizepart 1 5121
Information: You may need to update /etc/fstab.
[root@server ~ 18:15:57]# parted /dev/sdb unit MiB print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1.00MiB 5121MiB 5120MiB xfs data01
# 删除分区
[root@server ~ 18:16:08]# parted /dev/sdb rm 1
Information: You may need to update /etc/fstab.
[root@server ~ 18:16:18]# parted /dev/sdb unit MiB print 
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 20480MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags

文件系统持久化挂载

说白了就是开机自动启动挂载,持久化挂载

环境准备

利用 parted 创建一个分区,并格式化为xfs文件系统。

[root@server ~ 18:17:00]# parted /dev/sdb mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this
disk will be lost. Do you want to continue?
Yes/No? y
Information: You may need to update /etc/fstab.
[root@server ~ 18:17:10]# parted /dev/sdb unit MiB mkpart data01 xfs 1 2049 
Information: You may need to update /etc/fstab.
[root@server ~ 18:20:17]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=131072 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=524288, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
# 如果格式化时候,提示存在文件系统,则需要-f选项强制格式化

持久化挂载

当服务器重启时,系统不会再次将文件系统自动挂载到目录树上,用户无法访问。为了确保系统在启动时自动挂载文件系统, 需要在 /etc/fstab文件中添加一个条目。

/etc/fstab 是以空格分隔的文件,每行具有六个字段。

  • **第一个字段指定设备。**可以使用UUID或device来指定设备。
  • **第二个字段是目录挂载点。**通过它可以访问目录结构中的块设备。挂载点必须存在;如果不存在,请使用mkdir命令进行创建。
  • 第三个字段包含文件系统类型,如xfs或ext4 。
  • 第四个字段是挂载选项,以逗号分隔的。 defaults是一组常用选项。详细信息参考mount(8) 。
  • 第五个字段指定dump命令是否备份设备。
  • 第六个字段指定fsck顺序字段,决定了在系统启动吋是否应运行fsck命令,以验证文件系统是否干净。 该字段中的值指示了 fsck的运行顺序。 对于XFS文件系统, 请将该字段设为0 ,因为XFS并不使用fsck来检查自己的文件系统状态。 对于ext4 文件系统,如果是根文件系统, 请将该字段设 为 1 ; 如果是其他ext4 文件系统, 则将该字段设为2。 这样, fsck就会先处理根文件系统,然后同步检查不同磁盘上的文件系统,并按顺序检查同一磁盘上的文件系统。

示例:

[root@server ~ 18:20:23]# blkid /dev/sdb1
/dev/sdb1: UUID="78ca3302-4133-4c48-a305-db1175c632e4" TYPE="xfs" PARTLABEL="data01" PARTUUID="e2427a55-743d-4bed-94a6-6e97ba7e9200"
[root@server ~ 18:20:37]# mkdir /data01
[root@server ~ 18:20:50]# vim /etc/fstab
# 最后一行增加一个条目
UUID="78ca3302-4133-4c48-a305-db1175c632e4" /data01 xfs defaults 0 0
# 使用如下命令立刻挂载
[root@server ~ 18:21:59]# mount /data01
# 或者
[root@server ~ 18:21:59]# mount /dev/sdb1
# 验证
[root@server ~ 18:22:12]# df -h /data01
文件系统 容量 已用 可用 已用% 挂载点
/dev/sdb1 2.0G 33M 2.0G 2% /data01
# 重启系统验证
[root@server ~ 18:22:53]# reboot
[root@server ~ 18:23:18]# df -h /data01
文件系统 容量 已用 可用 已用% 挂载点
/dev/sdb1 2.0G 33M 2.0G 2% /data01

取消持久化挂载

删除/etc/fstab中对应条目即可。

综合案例:文件系统空间不足

情况1:大量的大文件占用空间

准备环境

[root@server ~ 18:24:06]# parted /dev/sdb mklabel gpt
[root@server ~ 18:24:18]# parted /dev/sdb unit MiB mkpart data01 xfs 1 2049
[root@server ~ 18:24:30]# mkfs.xfs /dev/sdb1
[root@server ~ 18:24:38]# mkdir /myapp-1
[root@server ~ 18:24:45]# mount /dev/sdb1 /myapp-1
[root@server ~ 18:24:50]# cp -r /etc/ /myapp-1/
# 创建一个大文件
[root@server ~ 18:25:01]# dd if=/dev/zero of=/myapp-1/etc/bigfile bs=1M count=2000

原因:大文件占用大量空间。

解决方法:找到文件后删除。

[root@server ~ 18:25:12]# df -h /myapp-1/
文件系统 容量 已用 可用 已用% 挂载点
/dev/sdb1 2.0G 2.0G 436K 100% /myapp-1
# 方法1:find 查找
[root@server ~ 18:25:24]# find /myapp-1/ -size +100M
/myapp-1/etc/bigfile
# 方法2:du 查找
[root@server ~ 18:25:24]# du -s /myapp-1/* |sort -n |tail -2
2051628 /myapp-1/etc
[root@server ~ 18:25:35]# du -s /myapp-1/etc/* |sort -n |tail -2
23220 /myapp-1/etc/selinux
2008512 /myapp-1/etc/bigfile
[root@server ~ 18:25:41]# du -s /myapp-1/etc/bigfile/* |sort -n |tail -2
du: 无法访问"/myapp-1/etc/bigfile/*": 不是目录
# 删除大文件
[root@server ~ 18:26:05]# rm -f /myapp-1/etc/bigfile

找到文件后,删除即可。

情况2:删除文件后,空间没有释放

准备环境

[root@server ~ 18:26:41]# dd if=/dev/zero of=/myapp-1/etc/bigfile bs=1M count=2000
[root@server ~ 18:26:52]# tail -f /myapp-1/etc/bigfile &
[1] 5426
# 删除文件后,空间没有释放
[root@server ~ 18:26:57]# rm -f /myapp-1/etc/bigfile
[root@centos7 ~]# df -h /myapp-1/
文件系统 容量 已用 可用 已用% 挂载点
/dev/sdb1 2.0G 2.0G 772K 100% /myapp-1
[root@server ~ 18:27:30]# tail: 无法监视"/myapp-1/etc/bigfile": 没有那个文件或目录

原因:被删除的文件,仍然有程序在使用。

解决方法:找到像一个的程序并,终止程序。

[root@server ~ 18:27:41]# lsof |grep delete |grep /myapp-1
tail 5426 root 3r REG 8,17 2061565952 444 /myapp-1/etc/bigfile (deleted)
[root@server ~ 18:28:57]# kill 5426
[root@server ~ 18:29:11]# df -h /myapp-1/
文件系统 容量 已用 可用 已用% 挂载点
/dev/sdb1 2.0G 72M 2.0G 4% /myapp-1

建议:清理大文件,先使用重定向清空文件内容,再删除文件。

情况3:大量的小文件占用空间

准备环境

[root@server ~ 18:29:11]# parted /dev/sdb unit MiB mkpart data02 ext4 2049 3073
[root@server ~ 18:29:32]# mkfs.ext4 /dev/sdb2
[root@server ~ 18:29:40]# mkdir /myapp-2
[root@server ~ 18:29:52]# mount /dev/sdb2 /myapp-2
[root@server ~ 18:29:57]# touch /myapp-2/file-{00001..70000}
touch: 无法创建"/myapp-2/file-65526": 设备上没有空间
touch: 无法创建"/myapp-2/file-65527": 设备上没有空间
touch: 无法创建"/myapp-2/file-65528": 设备上没有空间
[root@server ~ 18:30:29]# df -h /myapp-2/
文件系统 容量 已用 可用 已用% 挂载点
/dev/sdb2 976M 4.5M 905M 1% /myapp-2

原因:文件系统中inode使用完了。

解决方法:删除大量的小文件或者将这些小文件备份到其他地方。

[root@server ~ 18:30:33]# df -hi /myapp-2
文件系统 Inode 已用(I) 可用(I) 已用(I)% 挂载点
/dev/sdb2 64K 64K 0 100% /myapp-2
# 思路1:直接将这些小文件移走或删除
[root@server ~ 18:30:43]# rm -f /myapp-2/file-0*
# 思路2:合并大量小文件为单个文件
[root@server ~ 18:31:01]# cat /myapp-2/file-{00001..10000} > file-00001

思考:如何彻底擦除硬盘上数据

解答:

  1. 逻辑破坏:用0填充所有数据,例如 dd if=/dev/zero of=/dev/sdb
  2. 物理破坏,例如消磁。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/917407.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

CCF CSP-J 2025_from_黄老师_km

下面把 2025 CCF CSP-J 第一轮(入门级)C++ 试题 中 所有可辨认的选择 / 判断 / 填空 按题号逐一给出:正确答案 极简解析(why) 易错点 / 知识彩蛋【单选题】(每题 2 分,共 30 分)题号 答案 秒懂解析1 D 科学计数…

个人cms网站凡科做的网站打不开

面向对象和面向过程的区别&#xff1f; 面向对象编程&#xff08;OOP&#xff09;和面向过程编程&#xff08;POP&#xff09;是两种不同的编程范式&#xff0c;它们之间有一些重要的区别&#xff1a; 思想方式&#xff1a; 面向对象编程&#xff1a;将问题看作是一组对象之间…

网站flash代码成立公司一年需要多少费用

目录简介数据手册接口简单 I/OXBus简单 I/O 对比 XBus语言参考程序结构注释标签寄存器accdatp0、p1、x0、x1、x2、x3null 伪寄存器指令操作数确保进行足够的睡眠 (slp)&#xff01;基本指令算法指令条件指令隐藏指令游戏界面DIY版本&#xff1a; 简介 以下介绍摘自未来软件园 …

AI一周资讯 250918-250925

原文: https://mp.weixin.qq.com/s/6_sSbUDYOujOjeF-n1rnGA 行业首个“高刷”视频理解多模态模型!MiniCPM-V 4.5凭三大技术成30B以下最优开源 本周,由清华大学自然语言处理实验室和面壁智能联合开发的MiniCPM-V 4.5亮…

深入解析:SpringBoot与反射

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

云栖小镇现场追踪!触摸AI 未来

原文: https://mp.weixin.qq.com/s/-jkeIywNb1alCajgZveSSw 9 月 24 日的杭州云栖小镇,人山人海 ——2025 云栖大会。作为每年必蹲的科技盛会,今年大会的主题 “云智一体・碳硅共生” 可不是空口号。走在 4 万平方米…

刚入手一手房怎么网上做网站Wordpress如何创建菜单

edge浏览器扩展插件中心10月发布 可直接安装Chrome扩展 Windows 10的全新浏览器Edge收获了不少好评&#xff0c;我们也知道它将在今年秋天迎来扩展程序的支持。 Mashable已经指出&#xff0c;微软将保证Edge上的扩展严控权限、卸载干净&#xff0c;保证不拖累整体性能&#x…

济南网站建设seo优化wordpress页面内

文章目录 python常用库之数据库orm框架之SQLAlchemy一、什么是SQLAlchemySQLAlchemy 使用场景 二、SQLAlchemy使用SQLAlchemy根据模型查询SQLAlchemy SQL 格式化的方式db_session.query和 db_session.execute区别实测demo 总结&#xff1a;让我们留意一下SQLAlchemy 的 lazy lo…

AT_arc154_d [ARC154D] A + B C ?

直接被这个题闪到了。 首先发现 \(1\) 是最小的,其有很多性质,因此可以花费 \(n - 1\) 次操作比较出来 \(1\) 的位置。 同理,\(2, 3, ..., n\) 都是可以这样比较出来的,但操作次数是 \(O(n^2)\) 级别的,题目只给了…

SQL注入-联合注入

一、SQL语句基础知识 首先打开PHP的数据库,如下图所示,再在终端中输入后连接到数据库点击查看代码 mysql -u root -p1.1 MySQL的基础语句 1.1.1 创造数据库 用来创建一个数据库的语句如下:点击查看代码 create data…

实用指南:【JavaEE】多线程案例(一)

实用指南:【JavaEE】多线程案例(一)pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Mon…

网站开发和c语言反网站搭建一条龙

MySQL 5.5以上版本 与之前的版本安装出入有些区别&#xff1a; 下面是安装过程mysql5.6 下载地址&#xff1a;ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.6/一&#xff1a;卸载旧版本使用下面的命令检查是否安装有MySQL Serverrpm -qa | grep mysql有的话通过下面…

架构架构设计师备考第32天——数据库交互NoSQL

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

交互:在终端中输入用户信息

交互:在终端中输入用户信息Python可以允许用户在终端中输入一些信息。 Input功能 接受输入字符串 # -*- coding: utf-8 -*- name = input("Please input your name:") print("Hello " + name + &…

传奇三端互通新开服网站百度非企推广开户

这个算法来自LINUX的源码&#xff0c;下面带有大神的解析&#xff0c;自己在RTC实验中也使用了&#xff0c;不用月份表&#xff0c;润平年的处理&#xff0c;几行就可得出结果&#xff0c;以下是程序和大神的解析Linux源码中的mktime算法解析我们知道&#xff0c;从CMOS中读出来…

php网站开发系统wordpress 引用网页

近日&#xff0c;紫光云技术有限公司在天津举行主题为“产业城市 擎领未来”的IMPACT2019紫光云峰会&#xff0c;深度阐释打造产业数字引擎的理念和实践&#xff0c;并为unI X云创中心揭牌&#xff0c;发布紫光云芯片产业数字引擎。 天津市人民政府副秘书长杨明远为大会致辞会上…

爱站网关键字挖掘wordpress 小组

Java中new一个对象时&#xff0c;JVM到底做了什么&#xff1f; 在Java编程中&#xff0c;new关键字是我们创建对象的最常用方式。但你是否想过&#xff0c;当你写下new MyClass()时&#xff0c;Java虚拟机&#xff08;JVM&#xff09;到底在背后做了哪些工作&#xff1f;今天&…

电脑迁移技巧:适用于 Windows 10/11 的免费磁盘克隆优秀的工具

电脑迁移技巧:适用于 Windows 10/11 的免费磁盘克隆优秀的工具pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Co…

详细介绍:Windows安装PostgreSQL入门操作手册

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

主播网站建立商务网站管理的主要内容数据管理

最近在微调 ChatGLM3-6b 时&#xff0c;训练好模型之后&#xff0c;调用inference_hf.py函数验证模型的时候报了如下错误&#xff0c;下面是解决方案。 我在训练时使用的是ptuning_v2.yaml配置文件&#xff0c;训练运行代码如下&#xff1a; CUDA_VISIBLE_DEVICES1 python fi…