首页 > 代码库 > 第二本书 第四单元总结
第二本书 第四单元总结
################################
####第二本书 第四单元##############
###############################
一.分区划分
fdisk /dev/vdb
The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
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 (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): ##默认位主分区
Using default response p
Partition number (3,4, default 3): ##主分区id
First sector (976773120-976773167, default 976773120): ##此分区起始位置
Using default value 976773120
Last sector, +sectors or +size{K,M,G} (976773120-976773167, default 976773167):+100M ##分区大小
Command (m for help): p
Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0xaa46f25b
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 167776255 83887104 7 HPFS/NTFS/exFAT
/dev/sda2 167776256 976773119 404498432 f W95 Ext‘d (LBA)
/dev/sda5 167778304 438312959 135267328 7 HPFS/NTFS/exFAT
/dev/sda6 438315008 708849663 135267328 7 HPFS/NTFS/exFAT
/dev/sda7 708851712 708855807 2048 83 Linux
/dev/sda8 708857856 709881855 512000 83 Linux
/dev/sda9 709883904 717486079 3801088 82 Linux swap / Solaris
/dev/sda10 717488128 976773119 129642496 83 Linux
Command (m for help): wq ##保存退出,如果按q表示放弃更改退出
二.swap
换空间或交换区是磁盘驱动器上的空间 , 用作当前未使用部分内存的溢出。这样 , 系统就能在主内存中留出空间用于储存当前正在处理的数据 , 并在系统面临主内存空间不足的风险时提供应急溢出
mkswap /dev/vdaN 会准备好将分区用作交换区
blkid /dev/vdaN 将确定 UUID
将新交换空间添加到 /etc/fstab :
UUID=uuid swap swap defaults 0 0
/dev/vdaN
swapon -a 将激活新交换区
swapon -s 将显示当前交换区的状态
swapoff /dev/vdaN 将停用该特定交换区
三.磁盘
1.磁盘加密
fdisk /dev/vdb
cryptsetup luksFormat /dev/vdb1
WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.
Are you sure? (Type uppercase yes): YES ##确定加密
Enter passphrase: ##密码大于8位,并且不能太简单
Verify passphrase: ##确认密码
cryptsetup open /dev/vdb1 westos ##解密
mkfs.xfs /devmapper/westos ##用管理文件格式化设备
mount /dev/mapper/westos /mnt/ ##使用设备
umount /mnt/ ##使用设备
cryptsetup close westos ##关闭设备加密层
2.加密磁盘的永久挂载
vim /etc/crypttab
解密后设备管理文件 设备 加密字符存放文件
redhat /dev/vdb1 /root/lukspsfile
vim /root/luspsfile
chmod 600 /root/lukspsfile
cryptsetup luksAddKey /dev/vdb1 /root/lukspsfile
vim 600 /root/lukspsfile
cryptsetup luksAddKey /dev/vdb1 /root/lukspsfile
vim /etc/fstab
/dev/mapper/redhat /mnt xfs defaults
reboot
3.加密清除
vim /etc/fatab
> /etc/crypttab
rm -fr /root/lukspsfile
umount /mnt/
cryptsetup close redhat
mkfs.xfs /dev/vdb1
4.磁盘阵列
fdisk /dev/vdb ##创建分区
mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3}
-C ##建立
-a ##文件不存在建立文件
-l ##raid级别
-n ##设备个数
-x ##闲置设备个数
mkfs.xfs /dev/md0
mount /dev/md0 /mnt/
watch -n 1 cat /proc/mdstat
mdadm -f /dev/md0 /dev/vdb1 ##损坏设备1
mdadm -D /dev/md0
mdadm -r /dev/md0 /dev/vdb1 ##移除设备1
mdadm -a /dev/md0 /dev/vdb1 ##恢复设备1
umount /mnt/
mdadm -S /dev/md0 ##停止设备
5.配额
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 102400 0 40000 1 0 0
su - student
dd if=/dev/zero of=/pub/file bs=1M count=500
dd:error writing ‘/pub/file‘: Disk quota exceeded
本文出自 “12100661” 博客,谢绝转载!
第二本书 第四单元总结