###linux系统中的磁盘管理
##1.本地存储设备的识别
fdisk -l #真实存在的设备
cat /proc/partitions #系统识别的设备
blkid #系统正在使用的设备
df #系统正在挂在的设备
##2.设备的挂载和卸载
1.设备名称
/dev/xdx #/dev/hd0 /dev/hd1 /dev/sda /dev/sdb /dev/sda1 /dev/sdb1
/dev/sr0 #光驱
/dev/mapper/* #虚拟设备(用软件模拟出来的)
2.设备的挂载
mount 设备 挂载点
mount /dev/sdb1/ /mnt
umount /mnt | /dev/sdb1
mount -o ro /dev/sdb1 /mnt
mount 查看挂载信息
mount -o remount,rw /dev/sdb1/ | /mnt
3.解决设备正忙问题
[root@foundation16 mnt]# umount /mnt/
umount: /mnt: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
解决方法1:
[root@foundation16 mnt]# lsof /mnt
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
Output information may be incomplete.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 7363 root cwd DIR 8,17 32768 1 /mnt
lsof 7441 root cwd DIR 8,17 32768 1 /mnt
lsof 7442 root cwd DIR 8,17 32768 1 /mnt
[root@foundation16 mnt]# kill -9 7363
Killed
su
umount /mnt
解决方法2:
root@foundation16 mnt]# fuser -vm /mnt/ #查看
[root@foundation16 mnt]# fuser -kvm /mnt/ #查看并结束
USER PID ACCESS COMMAND
/mnt: root kernel mount /mnt
root 7486 ..c.. bash
Killed
su
umount /mnt
###磁盘分区
1.fdisk -l
2.fdisk /dev/vdb
m
d 删除
n 新建
p 显示分区信息
q 退出
t 修改分区id
w 保存
###建立主分区
Command (m for help): n #新建
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p #主分区
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +500M #主分区大小
Partition 1 of type Linux and of size 500 MiB is set
###
Command (m for help): p #显示信息
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x94fdf673
Device Boot Start End Blocks Id System
/dev/vdb1 2048 1026047 512000 83 Linux
##当系统已经有三个分区时
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 (3074048-20971519, default 3074048):
Using default value 3074048
Last sector, +sectors or +size{K,M,G} (3074048-20971519, default 20971519):
Using default value 20971519
Partition 4 of type Extended and of size 8.5 GiB is set
###
Command (m for help): p
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x94fdf673
Device Boot Start End Blocks Id System
/dev/vdb1 2048 1026047 512000 83 Linux
/dev/vdb2 1026048 2050047 512000 83 Linux
/dev/vdb3 2050048 3074047 512000 83 Linux
/dev/vdb4 3074048 20971519 8948736 5 Extended
###把所有剩余的空间都给扩展分区
###4.给设备安装文件系统
mkfs.xfs /dev/vdb1
mount /dev/vdb1 /mnt
vim /etc/fstab
设备 挂载点 文件系统 挂载参数 是否备份 是否检测
/dev/vdb1 /mnt xfs defults 0 0
###5.swap分区管理
1.swap分区建立
划分分区并设定分区标签为82
partprode
mkswap /dev/vdb
swapon -a /dev/vdb6
swapon -s
Filename type size used priority
/dev/vdb6 partition 51196 0 -1
vim /etc/fstab
/dev/vdb6 swap swap defaults 0 0
2.swap分区的删除
vim /etc/fstab
swapoff /dev/vdb6
swapon -s
###6.配额
1.分区,格式化
mkdir /public
mount -o usrquota /dev/vdb7 /public
b
dequota -u student
测试:
###7.磁盘加密
cryptsetup luksFormat /dev/vdb8
cryptsetup close messi 关闭之后,/dev/mapper/messi文件消失,挂载原始设备也不能查看其中的内容
cryptopen /dev/vdb8 messi
mount /dev/mapper/messi /mnt