#1.本地存储设备的识别
fdisk -l ##真实存在的设备
cat /proc/partition ##系统识别的设备
blkid ##系统可使用的设备
df ##系统正在挂载的设备
#2.设备的挂载和卸载
1.设备名称
/dev/xdx ##/dev/hd0 /dev/hd1
/dev/sr0 ##光驱
/dev/mapper/* ##虚拟设备
2.设备的挂载
mount 设备 挂载点
mount /dev/sdb1 /mnt ##挂载sdb1到mnt
mount /mnt | /dev/sdb1 ##卸载
umount /mnt | /dev/sdb1 ##只读挂载
mount ##查看挂载信息
mount -o remount,rw /dev/sdb1 | /mnt ##重新读写挂载
3.解决设备正忙的情况
[root@foundation55 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: fuser -kvm /mnt
解决方法2: 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 13376 root cwd DIR 8,17 16384 1 /mnt
kill -9 13376
umount /mnt
#3.磁盘分区####
1.硬盘0磁道1扇区的512个字节中记录的信息如下
512=446 + 64 + 2
^ ^ ^
mbr(主引导记录) mpt(主分区标) 55aa(硬盘的有效性标示)
硬盘分区标 64
1个分区占用16个字节
1快硬盘上最多可以划分4个主分区
##3.磁盘分区步骤
1.fdisk -l
2.fdisk /dev/vdb
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 ##修改分区id
u change display/entry units
v verify the partition table
w write table to disk and exit ##保存分区标信息到硬盘
x extra functionality (experts only)
Command (m for help): n ##新建
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): ##主分区
Using default response p
Partition number (1-4, default 1): ##id用默认
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: 0x80b5d9fb
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): e ##3个主分区出现,要划分扩展分区
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: 0x80b5d9fb
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.给设备安装文件系统##
ext3 rhel5及之前的脚本 最多支持32TB文件系统和2T文件,实际2Tb文件系统,16G文件
ext4 rhel6 1EB 16TB
xfs rhel7 18EB 9eb 7G/s
mkfs.xfs /dev/vdb1
mount /dev/vdb1 /mnt
vim /etc/fstab ##设置开机自动挂载
设备 挂载点 文件系统 挂载参数 是否备份 是否检测
/dev/vdb /mnt xfs defaults 0 0
##5.swap分区管理##
1)swap分区的建立
划分分区并设定分区标签为82
mkswap /dev/vdb6
swapon -a /dev/vdb6
swapon -s
vim /etc/fstab
/dev/vdb6 swap swap defaults 0 0
2)swap分区的删除
vim /etc/fstab
swapoff /dev/vdb6
swapon -s
##6.配额##
磁盘配额就是管理员可以为用户所能使用的磁盘空间进行配额限制,每一用户只能使用最大配额范围内的磁盘空间,且配额是针对于分区的。
mount -o usrquota /dev/vdb5 /public(创建一个需要挂载的目录)
chmod 777 /public
edquota -u student
vim /etc/fstab ##永久挂载到/public
/dev/vdb5 /public xfs defaults,usrquota 0 0
测试
[student@..] dd if=/dev/zero of=/public/studentfile bs=1k count=?
( 超过80kb无法再写入)
##7.磁盘加密##
1.cryptsetup LuksFormat /dev/vdb6 ## 注:在确定是否时输入的必须是YES, 必须大写。
2.cryptsetup open /dev/vdb6 westos ## 映射
3.mkfs.xfs /dev/mapper/westos ##格式化加密分区
4.mount /dev/mapper/westo /mnt ##创建挂载点并挂载
touch /mnt/file{1..5}
umount /mnt
cryptsetup close westos ##关闭加密分区
cryptsetup open /dev/vdb6 westos
mount /dev/mapper/westos /mnt
#加密磁盘开机自动挂载
vim /etc/fstab
/dev/mapper/westos /mnt xfs defaults 0 0
vim /etc/crypttab
westos /dev/vdb5 /root/westoskey
vim /root/westoskey
2018westos
cryptsetup luksAddKey /dev/vdb8 /root/westoskey 添加密码文件到/dev/vdb5