1. 管理分区
[09:37:23 root@centos8 ~]
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 xfs 06d75d27-4daa-4729-ac9f-55718e94d870 /boot
├─sda2 xfs fef228f1-0a8a-4ac8-8bab-0cb590ff7ff6 /
├─sda3 xfs be6ecf7a-851e-420c-bb65-9979bf830ea2 /data
├─sda4
└─sda5 swap 874f4e74-ab3e-4f5e-93f0-cc28483c64da [SWAP]
sdb
sdc
sr0 iso9660 CentOS-8-3-2011-x86_64-dvd 2020-11-18-21-39-52-00
p
t
n
u
w
q
[10:04:00 root@centos8 ~]
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x335c1b74.
Command (m for help):
[10:09:34 root@centos8 ~]
GPT fdisk (gdisk) version 1.0.3
Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present
Creating new GPT entries.
Command (? for help):
du
[21:58:11 root@centos8 ~]
19G /data/isos
16K /data/mnt/sdb1/lost+found
20K /data/mnt/sdb1
0 /data/mnt/sdb2
20K /data/mnt
21G /data
[21:58:21 root@centos8 ~]
21G /data
du -sh -x /data
dd工具
dd if=f1.txt of=f2.txt bs=1 count=2 skip=3 seek=4 conv=notrunc
2.一个硬盘要用分为三部
fdisk /dev/sdb
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xbe39d95a.
Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xbe39d95a
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): +1G
Created a new partition 1 of type 'Linux' and of size 1 GiB.
Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xbe39d95a
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 2099199 2097152 1G 83 Linux
Command (m for help): n
Partition type
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p): e
Partition number (3,4, default 3):
First sector (6293504-41943039, default 6293504):
Last sector, +sectors or +size{K,M,G,T,P} (6293504-41943039, default 41943039): +10G
Created a new partition 3 of type 'Extended' and of size 10 GiB.
Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xbe39d95a
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 2099199 2097152 1G 83 Linux
/dev/sdb2 2099200 6293503 4194304 2G 83 Linux
/dev/sdb3 6293504 27265023 20971520 10G 5 Extended
Command (m for help): n
Partition type
p primary (2 primary, 1 extended, 1 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (6295552-27265023, default 6295552):
Last sector, +sectors or +size{K,M,G,T,P} (6295552-27265023, default 27265023): +1G
Created a new partition 5 of type 'Linux' and of size 1 GiB.
Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xbe39d95a
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 2099199 2097152 1G 83 Linux
/dev/sdb2 2099200 6293503 4194304 2G 83 Linux
/dev/sdb3 6293504 27265023 20971520 10G 5 Extended
/dev/sdb5 6295552 8392703 2097152 1G 83 Linux
Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xbe39d95a
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 2099199 2097152 1G 83 Linux
/dev/sdb2 2099200 6293503 4194304 2G 83 Linux
/dev/sdb3 6293504 27265023 20971520 10G 5 Extended
/dev/sdb5 6295552 8392703 2097152 1G 83 Linux
/dev/sdb6 8394752 12589055 4194304 2G 83 Linux
Command (m for help): t
Partition number (1-3,5,6, default 6): 6
Hex code (type L to list all codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi ea Rufus alignment
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs
f W95 Extd (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT
10 OPUS 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fb VMware VMFS
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fc VMware VMKCORE
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fd Linux raid auto
1c Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fe LANstep
1e Hidden W95 FAT1 80 Old Minix be Solaris boot ff BBT
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'.
Command (m for help): p
Disk /dev/sdb: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0xbe39d95a
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 2099199 2097152 1G 83 Linux
/dev/sdb2 2099200 6293503 4194304 2G 83 Linux
/dev/sdb3 6293504 27265023 20971520 10G 5 Extended
/dev/sdb5 6295552 8392703 2097152 1G 83 Linux
/dev/sdb6 8394752 12589055 4194304 2G 82 Linux swap / Solaris
fdisk -l
lsblk
ls /dev/sda*
partprobe
partx -a /dev/sda
partx -d --nr 6-8 /dev/sda
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
lsblk -f
mkfs.ext4 /dev/sdb1
mkfs.xfs /dev/sdb1
blkid
[15:57:31 root@centos8 ~]
/dev/sda1: UUID="06d75d27-4daa-4729-ac9f-55718e94d870" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="1486a0f6-01"
/dev/sda2: UUID="fef228f1-0a8a-4ac8-8bab-0cb590ff7ff6" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="1486a0f6-02"
/dev/sda3: UUID="be6ecf7a-851e-420c-bb65-9979bf830ea2" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="1486a0f6-03"
/dev/sda5: UUID="874f4e74-ab3e-4f5e-93f0-cc28483c64da" TYPE="swap" PARTUUID="1486a0f6-05"
/dev/sdb1: UUID="85dee10b-ddf5-44b3-81ab-a3b0deb6689d" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="be39d95a-01"
/dev/sdb2: PARTUUID="be39d95a-02"
/dev/sdb5: PARTUUID="be39d95a-05"
/dev/sdb6: PARTUUID="be39d95a-06"
/dev/sr0: BLOCK_SIZE="2048" UUID="2020-11-18-21-39-52-00" LABEL="CentOS-8-3-2011-x86_64-dvd" TYPE="iso9660" PTUUID="6b8b4567" PTTYPE="dos"
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
mkdir /data/sdb{1,2}
mount /dev/sdb1 /data/sdb1
mount
findmnt /dev/sdb1
vim /etc/fstab
UUID=fef228f1-0a8a-4ac8-8bab-0cb590ff7ff6 / xfs defaults 0 0
UUID=06d75d27-4daa-4729-ac9f-55718e94d870 /boot xfs defaults 0 0
UUID=be6ecf7a-851e-420c-bb65-9979bf830ea2 /data xfs defaults 0 0
UUID=874f4e74-ab3e-4f5e-93f0-cc28483c64da none swap defaults 0 0
:r!blkid /dev/sdb1
r!执行命令行 拿到sdb1的UUID和文件系统类型,模仿上面格式编写。
mount -a
补充:
df -Th
lsblk -f
ext:
dumpe2fs /dev/sdb1
dumpe2fs -h /dev/sdb1
xfs:
xfs_info /dev/sdb2
有挂载先取消挂载
mkfs.ext4 /dev/sdb1
标签命名:一般是挂载的路径
方法:1.在创建文件系统的时候可以直接指定标签
mkfs.ext4 -L '/data/挂载路径' /dev/sdb1
2.文件系统创建完成了,e2label创建标签
e2label /dev/sdb1 /data/挂载路径
注意:
节点编号只有在创建文件系统的时候才能指定。生产中节点编号满了,实在是没有可删除的文件,需要扩展节点编号。
第一步:把分区数据拷贝到其他盘
第二步:取消挂载
第三步:mkfs.ext4 -N 节点编号数量 /dev/sdb1
3.swap空间管理
sed -i.bak '/swap/s/^/#/' /etc/fstab
swapoff -a
vim /etc/fstab
swapon -a
swapon -s
fdisk -l
fdisk /dev/sdb
p
t
数字
L
82
p
w
----------------------------------------------------------
mkswap /dev/sdb6
----------------------------------------------------------
vim /etc/fstab
:r!blkid /dev/sdb6
swapon -a
----------------------------------------------------------
dd if=/dev/zero of=/data/swapfile bs=1M count=2048
mkswap /data/swapfile
vim /etc/fstab
/data/swapfile none swap defaults 0 0
swapon -a
chmod 0 /data/swapfile
-----------------------------------------------------------------
swapoff /data/swapfile
mv /data/swapfile /
vim /etc/fstab
/swapfile none swap defaults 0 0
swapon -a