目录
一、新增磁盘
1. 磁盘分区
#查看新磁盘
lsblk -f
fdisk -l
#查看 UUID(格式化后生成uuid)
blkid
ls -l /dev/disk/by-uuid
lsblk -f
#分区
gdisk /dev/sdb
#参数:
-a 切换分区启动标记 -b 编辑bsd磁盘标签
-c 切换dos兼容模式 -d 删除分区
-l 显示分区类型 -m 显示帮助菜单
-o 创建新的空分区表 -n 新建分区
-p 显示分区表信息 -q 不保存退出
-s 创建新的Sun磁盘标签 -v 检验分区表
-w 保存并退出 -x 扩展功能
#将磁盘分区变化信息通知内核,请求操作系统重新加载分区表。
partprobe -s /dev/sdb1
2. 格式化
#格式化
mkfs.ext4 /dev/sdb1
3. 挂载
#临时挂载
mount -t ext4 /deva/sdb1 /data
#永久挂载
vim /etc/fstab
/dev/sdb1 /data ext4 defaults 0 0
mount -a
二、磁盘打标签
#磁盘打标签(需要在格式化之后操作)
#ext2/ext3/ext4 文件系统
e2label /dev/sdb1 new-label
#XFS 文件系统
xfs_admin -L new-label /dev/sdb1
#FAT32 文件系统
mlabel -i /dev/sdb1 ::new-label
#NTFS 文件系统
ntfslabel /dev/sdb1 new-label
#Btrfs 文件系统
btrfs filesystem label /dev/sdb1 new-label
三、创建 SWAP 分区
1. 分区
gdisk /dev/sdc
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: not present
BSD: not present
APM: not present
GPT: not present
Creating new GPT entries.
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-41943006, default = 2048) or {+-}size{KMGTP}:
Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}: +4G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 8200
Changed type of partition to 'Linux swap'
Command (? for help): p
Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 6852EAC1-7D98-4E8B-BEF0-EA30C4FFD1CD
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 33554365 sectors (16.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 8390655 4.0 GiB 8200 Linux swap
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.
2. 格式化
mkswap /dev/sdc2
3. 挂载
#挂载swap分区
swapon /dev/sdc2
#卸载swap分区
swapoff /dev/sdc2