首页 > 代码库 > 2 unit 4
2 unit 4
###unit.4管理系统存储###
###1.分区划分
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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x6490d17b.
Command (m for help): m##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): 1##主分区id
First sector (2048-20971519, default 2048): ##此分区起始位置
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M##主分区大小
Partition 1 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: 0x6490d17b
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
Command (m for help): wq##保存退出,如果按q表示放弃更改退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@desktop18 ~]# partprobe ##同步分区表
[root@desktop18 ~]# cat /proc/partitions ##查看
mkfs.xfs /dev/vdb5##格式化
mount /dev/vdb5 /mnt##挂载
###2.swap
swapon -s##查看系统中的swap分区
建立swap分区
mkswap/dev/vdb1##把/dev/vdb1格式化成swap格式
swapon -a /dev/vdb1##激活
vim /etc/fstab##开机自动激活
/dev/vdb1swapswapdefautls0 0
删除/etc/fstab中的swap自动激活条目
swapoff /dev/vdb1##关闭激活的swap分区
###3.磁盘加密
1.磁盘加密
fdisk/dev/vdb##分区
cryptestup luksFormat /dev/vdb1##加密磁盘
cryptestup open /dev/vdb1 westos##打开磁盘
mkfs.xfs /dev/mapper/westos##格式化
mount /dev/mapper/westos /mnt##挂载
umount /mnt##卸载
cryptestuo close westos##关闭
2.加密磁盘的永久挂载
vim /etc/crypttab##加密磁盘配置文件
解密后设备管理文件设备加密字符存放文件##格式
westos/dev/vdb1/root/lukspsfile
vim /root/lukspsfile
密码
chmod 600 /root/lukspsfile
cryptsetup luksAddKey /dev/vdb1 /root/lukspsfile
vim /etc/fstab
/dev/mapper/westos/mntxfsdefaults0 0
reboot
###加密清除
vim /etc/fstab
> /etc/crypttab
rm -fr /root/lukspsdile
umount /mnt
cryptsetup close wesstos
mkfs.xfs /dev/vdb1 -f
###4.磁盘阵列
fdisk /dev/vdb
mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3}
mkfs.xfs /dev/md0
mount /dev/md0 /mnt
watch -n 1 cat /proc/mdstat
mdadm -f /dev/md0 /dev/vdb1
mdadm -D /dev/md0
mdadm -r /dev/md0 /dev/vdb1
mdadm -a /dev/md0 /dev/vdb1
umoun /mnt
mdadm -S /dev.md0
mdadm-C##建立
mdadm-a##文件不存在建立文件
mdadm-l##raid级别
mdadm-n##设备个数
mdadm-x##闲置设备个数
mdadm-r##删除
mdadm-f##破坏
mdadm-D##查看使用情况
mdadm-S##停止
###5.配额
fdisk /dev/vdb
mkdir /pub
mkfs.xfs /dev/vdb1 -f
mount -o usrquota /dev/vdb1 /pub
quotaon -uv /dev/vdb1
edquota -u student
Disk quotas for user student (uid 1000):
Filesystem blocks soft hard inodes soft hard
/dev/vdb1 0 0 40000 0 0 0
su - student
dd if=/dev/zero of=/pub/file1 bs=1M count=500
dd: error writing ‘/pub/file1’: Disk quota exceeded
40+0 records in
39+0 records out
40960000 bytes (41 MB) copied, 0.0517844 s, 791 MB/s
qupta
Disk quotas for user student (uid 1000):
Filesystem blocks quota limit grace files quota limit grace
/dev/vdb1 40000* 0 40000 1 0 0
开机自动挂载
vim /etc/fstab
/dev/vdb1/mntxfsdefaults,usrquota0 0
本文出自 “12115084” 博客,请务必保留此出处http://12125084.blog.51cto.com/12115084/1871582
2 unit 4