#####unit2.4#####
#####管理系统中的简单分区和文件系统######
1.分区
[root@localhost ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
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 (2 primary, 0 extended, 2 free) ##分区类型主分区
e extended ##分区类型扩展分区
Select (default p): p ##默认分区
Partition number (3,4, default 3): 3 ##主分区ID
First sector (206848-20971519, default 206848): ##此分区起始位置
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +100M ##分区大小
Partition 3 of type Linux and of size 100 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: 0x1009d016
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 63 2047 992+ 83 Linux
/dev/vdb3 206848 411647 102400 83 Linux
Partition table entries are not in disk order
Command (m for help): wq ##保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
[root@localhost ~]# partprobe ##同步分区表
[root@localhost ~]# cat /proc/partitions ##查看分区信息
mkfs.xfs /dev/vdb3 ##格式化
2.挂载文件
临时挂载:mount /dev/vdb1 /mnt
永久挂载:vim /etc/fstab ##x修改配置文件
内容编辑:/dev/vdb1 /mnt xfs defaults 0 0
mount -a ##使修改的配置文件生效
3.swap分区
1)创建swap交换分区
fdisk /dev/vdb ##创建一个新的分区
Command (m for help): t ##修改格式
82 ##swap分区代码
partprobe
mkswap /dev/vdb1 ##将分区用作交换区
swapon -a /dev/vdb1 ##激活新交换区
swapon -s ##将显示当前交换区的状态
swapoff /dev/vdb1 ##停用该特定交换区
swapon -a /dev/vdb1 -p 1 ##修改交换区等级
2)自动创建交换分区
vim /etc/fstab ##设置自动挂载
pri ##分区等级
4.分配用户额度
mkdir /pub/
umount /pub/ ##取消挂载/pub/目录
mount -o usrquota,grpquota /dev/vdb1 /pub/ ##挂载文件,用户配额,组配额
quotaon -ugv /dev/vdb1 ##开启用户配额,组配额
edquota -u westos ##给westos用户分配配额
su - westos
dd if=/dev/zero of=/pub/file bs=1M count=300
5.磁盘阵列管理
监控命令:watch -n 1 cat /proc/mdstat
新建3个分区
partprobe
mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3} ##把新建的3个分区磁盘,2个读写,一个备用 建立阵列
mkfs.xfs /dev/md0
mount /dev/md0 /mnt 把设备md0挂载到/mnt
监控命令:watch -n 1 'cat /proc/mdstat;echo ====;df -h'
mdadm -D /dev/md0 ##查看设备
mdadm -f /dev/md0 /dev/vdb2 ##手动破坏/dev/vdb2
mdadm -r /dev/md0 /dev/vdb2 ##删除/dev/vdb2
mdadm -a /dev/md0 /dev/vdb2 ##创建/dev/vdb2
mdadm -S /dev/md0 ##删除设备 (在这之前要取消挂载,删除完毕后删除分区,然后partprobe同步分区记录)
6.磁盘加密
1)磁盘加密
fdisk /dev/vdb
[root@localhost ~]# cryptsetup luksFormat /dev/vdb1 ##创建加密卷并设置密码
WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.
Are you sure? (Type uppercase yes): YES
Enter passphrase:
Verify passphrase:
[root@localhost ~]# cryptsetup open /dev/vdb1 westos ##将加密卷解锁为westos
Enter passphrase for /dev/vdb1:
mkfs.xfs /dev/mapper/westos
mount /dev/mapper/westos /mnt/
umount /mnt/
cryptsetup close westos ##锁定加密卷
2)加密磁盘永久挂载
vim /etc/fstab ##设置自动挂载
vim /etc/crypttab ##设置分区加密文件
vim /root/diskpass ##设置密码
chmod 600 /root/diskpass ##给密码文件权限
cryptsetup luksAddKey /dev/vdb1 /root/diskpass ##给文件添加密码
3)加密清除
vim /etc/fstab
vim /etc/crypttab
rm -fr /root/diskpass
umount /mnt/
cryptsetup close westos
mkfs.xfs /dev/vdb1