【9.5】磁盘格式化、挂载、手动增加swap空间
4.5/4.6 磁盘格式化
- linux支持的文件系统格式:
[root@arslinux-01 ~]# cat /etc/filesystems
xfs
ext4
ext3
ext2
nodev proc
nodev devpts
iso9660
vfat
hfs
hfsplus
*
-
CentOS7 默认系统:xfs
CentOS7 是 xfs,CentOS6 是 ext4,CentOS5 是 ext3 …
但 CentOS7 也可以格式化成 ext4,ext3 -
mount 查看分区文件系统
[root@arslinux-01 ~]# mount
-
在结果中,只需要关注/dev/开头的行,例如:
/dev/sda3 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota) -
格式化分区:
-
mke2fs
-
mke2fs -t 指定格式化成的格式(ext4或者其他,不支持 xfs)
-b 指定块大小 -
mkfs.xfs 格式化成xfs文件系统(支持xfs、ext4和其他)
mkfs.ext4 == mke2fs -t ext4
– mke2fs 格式化
[root@arslinux-01 ~]# mke2fs -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
– mkfs 格式化
[root@arslinux-01 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
- 格式化成 xfs 格式,如果之前被格式化过,那么需要加 -f 强制格式化
[root@arslinux-01 ~]# mkfs.xfs /dev/sdb1
mkfs.xfs: /dev/sdb1 appears to contain an existing filesystem (ext4).
mkfs.xfs: Use the -f option to force overwrite.
[root@arslinux-01 ~]# mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1310720, 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
目前 mount 查看不到,因为还未挂载,这时用 blkid 查看
- blkid 分区 查看未为挂载的分区
[root@arslinux-01 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="94bc27fe-36c8-4b4a-be32-924ae1bac4b1" TYPE="xfs"
-
格式化磁盘可以不分区直接格式化,如果格式化的磁盘上有分区,那么如果直接格式化整个磁盘,保存的分区会消失,需要一个分区一个分区格式化
-
mke2fs -b 指定块大小
[root@arslinux-01 ~]# mke2fs -b 8192 /dev/sdb1
Warning: blocksize 8192 not usable on most systems.
mke2fs 1.42.9 (28-Dec-2013)
mke2fs: 8192-byte blocks too big for system (max 4096)
无论如何也要继续? (y,n) y
Warning: 8192-byte blocks too big for system (max 4096), forced to continue
warning: 80 blocks unused.
文件系统标签=
OS type: Linux
块大小=8192 (log=3)
分块大小=8192 (log=3)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 655280 blocks
32764 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=671006720
10 block groups
65528 blocks per group, 65528 fragments per group
32768 inodes per group
Superblock backups stored on blocks:
65528, 196584, 327640, 458696, 589752
Allocating group tables: 完成
正在写入inode表: 完成
Writing superblocks and filesystem accounting information: 完成
分区存储视频、音乐、高清图片等大文件,可以把块分的大一点,读写更快一些,8KB一个块;
小文件的话,那么块更小一点比较好,比如2048,一般保持默认即可
- mke2fs -m 百分比 分区 指定分区预留空间大小
- mkfs.格式 -m 百分比 分区(必须指定格式)
[root@arslinux-01 ~]# mke2fs -m 1 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
13107 blocks (1.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: 完成
正在写入inode表: 完成
Writing superblocks and filesystem accounting information: 完成
[root@arslinux-01 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="fdb5c852-b979-4801-bedc-2fb5f3482347" TYPE="ext2"
如果不指定文件系统格式,那么默认格式为:ext2,最好还是要ext4 或者 xfs
[root@arslinux-01 ~]# mke2fs -t ext4 -m 0.1 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
1310 blocks (0.10%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@arslinux-01 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="b07c7d2b-1db4-401c-afd1-361b4db8c5c4" TYPE="ext4"
[root@arslinux-01 ~]# mkfs.xfs -m 0.1 /dev/sdb1
unknown option -m 0.1
Usage: mkfs.xfs
/* blocksize */ [-b log=n|size=num]
/* metadata */ [-m crc=0|1,finobt=0|1,uuid=xxx]
/* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num,
(sunit=value,swidth=value|su=num,sw=num|noalign),
sectlog=n|sectsize=num
/* force overwrite */ [-f]
/* inode size */ [-i log=n|perblock=n|size=num,maxpct=n,attr=0|1|2,
projid32bit=0|1]
/* no discard */ [-K]
/* log subvol */ [-l agnum=n,internal,size=num,logdev=xxx,version=n
sunit=value|su=num,sectlog=n|sectsize=num,
lazy-count=0|1]
/* label */ [-L label (maximum 12 characters)]
/* naming */ [-n log=n|size=num,version=2|ci,ftype=0|1]
/* no-op info only */ [-N]
/* prototype file */ [-p fname]
/* quiet */ [-q]
/* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx]
/* sectorsize */ [-s log=n|size=num]
/* version */ [-V]
devicename
<devicename> is required unless -d name=xxx is given.
<num> is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxx KiB),
xxxm (xxx MiB), xxxg (xxx GiB), xxxt (xxx TiB) or xxxp (xxx PiB).
<value> is xxx (512 byte blocks).
- xfs 格式不支持 -m 指定指定预留空间大小
[root@arslinux-01 ~]# mkfs.ext4 -m 0.1 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
1310 blocks (0.10%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
- mkfs.ext4 和 mke2fs -t ext4 都可以用 -m 预留空间
从上看到 327680 inodes, 1310720 blocks ,差不多4个块对应1个inode
- mke2fs -i 字节数 指定多少字节对应一个inode
4个块对应1个inode,1个块4K,那么1个inode16K,改为2个块对应1个inode,那么1个inode 8K
[root@arslinux-01 ~]# mke2fs -i 8192 -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
655360 inodes, 1310720 blocks,2个块对应1个inode,inode变多
最低1个快对应1个inode
mkfs.xfs基本上没有特殊用法,后面一般跟分区,如:mkfs.xfs /dev/sdb1
4.7/4.8 磁盘挂载
- 磁盘不分区,直接格式化
[root@arslinux-01 ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xef3809d5
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
命令(输入 m 获取帮助):d
已选择分区 1
分区 1 已删除
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@arslinux-01 ~]# mkfs.xfs /dev/sdb
mkfs.xfs: /dev/sdb appears to contain a partition table (dos).
mkfs.xfs: Use the -f option to force overwrite.
[root@arslinux-01 ~]# mkfs.xfs -f /dev/sdb
meta-data=/dev/sdb isize=512 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2621440, 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
[root@arslinux-01 ~]# blkid /dev/sdb
/dev/sdb: UUID="aa2459b4-013d-41a0-9dca-ded6dd521bc1" TYPE="xfs"
无论有没有分区,都可以直接格式化,只有格式化,才能够挂载文件系统
-
linux磁盘要想访问,必须挂载到一个挂载点,挂载点实际上就是一个目录
-
mount 分区 挂载点 挂载磁盘命令
[root@arslinux-01 ~]# mount /dev/sdb /mnt/
[root@arslinux-01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 28G 1.2G 27G 5% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 105M 93M 54% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb 10G 33M 10G 1% /mnt
- umount 分区 卸载磁盘(只有分区未在使用时才可卸载,退出到其他目录)
- umount 挂载点 也可以卸载磁盘
[root@arslinux-01 ~]# cd /mnt/
[root@arslinux-01 mnt]# touch 1.txt 2.txt
[root@arslinux-01 mnt]# mkdir 123
[root@arslinux-01 mnt]# ls
123 1.txt 2.txt
[root@arslinux-01 mnt]# umount /dev/sdb
umount: /mnt:目标忙。
(有些情况下通过 lsof(8) 或 fuser(1) 可以
找到有关使用该设备的进程的有用信息)
[root@arslinux-01 mnt]# cd
[root@arslinux-01 ~]# umount /dev/sdb
[root@arslinux-01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 28G 1.2G 27G 5% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 105M 93M 54% /boot
tmpfs 98M 0 98M 0% /run/user/0
已成功卸载
- umount -l 分区/挂载点 不退出分区,磁盘卸载(l = lazy)
[root@arslinux-01 ~]# mount /dev/sdb /mnt/
[root@arslinux-01 ~]# mount |grep sdb
/dev/sdb on /mnt type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
[root@arslinux-01 ~]# cd /mnt/
[root@arslinux-01 mnt]# mount /mnt
mount: /dev/sdb 已经挂载或 /mnt 忙
/dev/sdb 已经挂载到 /mnt 上
[root@arslinux-01 mnt]# umount -l /mnt/
[root@arslinux-01 mnt]# cd
[root@arslinux-01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 28G 1.2G 27G 5% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 105M 93M 54% /boot
tmpfs 98M 0 98M 0% /run/user/0
-
mount 常用选项
不加任何选项默认:rw,suid,dev,exec,auto,nouser,async
rw 可读可写
suid 允许分区里的文件设置suid权限
dev
exec 是否可执行(noexec 挂载分区下的文件不可执行)
auto 自动挂载
nouser 是否允许普通用户挂载(默认不允许)
async 内存里的数据不会随时写入磁盘 (sync实时同步) -
mount -o
-o (-o options)
remount 重新挂载
ro 只读
rw 读写
exec 是否可执行
auto 自动挂载
async 不实时同步
[root@arslinux-01 ~]# mount /dev/sdb /mnt
[root@arslinux-01 ~]# mount -o remount,rw /dev/sdb
- 系统启动默认挂载哪些磁盘,哪些分区,在fstab中配置
[root@arslinux-01 ~]# vi /etc/fstab
1#设备号(分区号或者UUID)
2#挂载点
3#分区格式
4#挂载选项
5#是否备份(早期有用,现在没用)
6#设置优先级(0,1,2 级别1高,根文件系统1,其他2,不检测为0)
- blkid 分区 查看UUID
[root@arslinux-01 ~]# blkid /dev/sdb
/dev/sdb: UUID=“aa2459b4-013d-41a0-9dca-ded6dd521bc1” TYPE=“xfs”
4.9 手动增加swap空间
- swap 一般不用太大空间,8G 就够用了,如果遇到需要大 swap 空间时,可增加 swap 空间
dd 读写磁盘
if 哪里去读
/dev/zero linux内核造0器
of 将0写到哪里去
bs 指定块大小
count 多少倍 (大小=count × bs)
[root@arslinux-01 ~]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=100
记录了100+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,1.64137 秒,63.9 MB/秒
[root@arslinux-01 ~]# du -sh /tmp/newdisk
100M /tmp/newdisk
[root@arslinux-01 ~]# mkswap -f /tmp/newdisk
正在设置交换空间版本 1,大小 = 102396 KiB
无标签,UUID=9d921919-5509-4ab0-9600-68a979ac802e
[root@arslinux-01 ~]# free
total used free shared buff/cache available
Mem: 995896 127012 616196 7784 252688 687192
Swap: 1999868 0 1999868
- swapon 新空间 挂载swap空间
[root@arslinux-01 ~]# swapon /tmp/newdisk
swapon: /tmp/newdisk:不安全的权限 0644,建议使用 0600。
[root@arslinux-01 ~]# free
total used free shared buff/cache available
Mem: 995896 126908 616280 7784 252708 687296
Swap: 2102264 0 2102264
[root@arslinux-01 ~]# chmod 600 /tmp/newdisk
- swapoff 新空间 卸载swap空间
[root@arslinux-01 ~]# swapoff /tmp/newdisk
[root@arslinux-01 ~]# free -m
total used free shared buff/cache available
Mem: 972 123 601 7 246 671
Swap: 1952 0 1952
另一种思路:
在磁盘上创建一个新的分区
然后将该分区的类型改为Linux Swap / Solaris
再将该分区 swapon
[root@arslinux-01 ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0x00fbe955 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x00fbe955
设备 Boot Start End Blocks Id System
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认 1):1
起始 扇区 (2048-20971519,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-20971519,默认为 20971519):+1G
分区 1 已设置为 Linux 类型,大小设为 1 GiB
命令(输入 m 获取帮助):n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
分区号 (2-4,默认 2):
起始 扇区 (2099200-20971519,默认为 2099200):
将使用默认值 2099200
Last 扇区, +扇区 or +size{K,M,G} (2099200-20971519,默认为 20971519):+1G
分区 2 已设置为 Linux 类型,大小设为 1 GiB
命令(输入 m 获取帮助):N
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
分区号 (3,4,默认 3):
起始 扇区 (4196352-20971519,默认为 4196352):
将使用默认值 4196352
Last 扇区, +扇区 or +size{K,M,G} (4196352-20971519,默认为 20971519):+1G
分区 3 已设置为 Linux 类型,大小设为 1 GiB
命令(输入 m 获取帮助):t
分区号 (1-3,默认 3):3
Hex 代码(输入 L 列出所有代码):L
0 空 24 NEC DOS 81 Minix / 旧 Linu bf Solaris
1 FAT12 27 隐藏的 NTFS Win 82 Linux 交换 / 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 隐藏的 C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux 扩展 c7 Syrinx
5 扩展 41 PPC PReP Boot 86 NTFS 卷集 da 非文件系统数据
6 FAT16 42 SFS 87 NTFS 卷集 db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux 纯文本 de Dell 工具
8 AIX 4e QNX4.x 第2部分 8e Linux LVM df BootIt
9 AIX 可启动 4f QNX4.x 第3部分 93 Amoeba e1 DOS 访问
a OS/2 启动管理器 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 休 eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 扩展 (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC
11 隐藏的 FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq 诊断 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 隐藏的 FAT16 <3 61 SpeedStor ab Darwin 启动 f2 DOS 次要
16 隐藏的 FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 隐藏的 HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST 智能睡眠 65 Novell Netware b8 BSDI swap fd Linux raid 自动
1b 隐藏的 W95 FAT3 70 DiskSecure 多启 bb Boot Wizard 隐 fe LANstep
1c 隐藏的 W95 FAT3 75 PC/IX be Solaris 启动 ff BBT
1e 隐藏的 W95 FAT1 80 旧 Minix
Hex 代码(输入 L 列出所有代码):82
已将分区“Linux”的类型更改为“Linux swap / Solaris”
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x00fbe955
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 4196351 1048576 83 Linux
/dev/sdb3 4196352 6293503 1048576 82 Linux swap / Solaris
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@arslinux-01 ~]# mkswap /dev/sdb3
正在设置交换空间版本 1,大小 = 1048572 KiB
无标签,UUID=8bd0dc23-2037-49aa-8995-6bb5fcb52182
[root@arslinux-01 ~]# swapon !$
swapon /dev/sdb3
[root@arslinux-01 ~]# free
total used free shared buff/cache available
Mem: 995896 127384 616732 7796 251780 686808
Swap: 3048440 0 3048440
[root@arslinux-01 ~]# swapoff /dev/sdb3
[root@arslinux-01 ~]# free
total used free shared buff/cache available
Mem: 995896 128248 615872 7796 251776 685944
Swap: 1999868 0 1999868