這篇主要講了
1.設備的基本信息,及基本使用 掛載 卸載等
2.設備的分區方法 ,及普通分區的管理(修改標籤,開機自動化掛載等)
3.swap分區的管理 ,swap分區是直接被系統利用的分區不需要掛載
4.分區對不同用戶設置配額
5.分區加密 對加密分區讀寫 破壞加密分區
(一)設備的基本信息及使用
一.設備的查看
1.發現系統中的設備
(1)fdisk -l
[root@server ~]# fdisk -l
Disk /dev/vda: 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: 0x00013f3e
Device Boot Start End Blocks Id System ##第一塊硬盤分區信息
/dev/vda1 * 2048 20970332 10484142+ 83 Linux
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
(2)cat /proc/partitions ##查看分區表
[root@server ~]# cat /proc/partitions
major minor #blocks name
253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
partprobe ##同步分區表 (看的系統中的)
2.系統發現的,但是沒有投入使用 隨時可以使用的設備
(1)blkid ##查看設備的id信息
【root@server ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs“
設備名字 uid 文件系統類型
3.被系統發現並正在使用的設備
(1)df (看的硬盤中的)
-h ##單位爲1g=2^n (更精確)
[root@server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 6.8G 3.3G 68% /
devtmpfs 482M 0 482M 0% /dev
tmpfs 498M 84K 497M 1% /dev/shm
tmpfs 498M 14M 485M 3% /run
tmpfs 498M 0 498M 0% /sys/fs/cgroup
-H
##單位爲1g=10^n
[root@server ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 11G 7.3G 3.5G 68% /
devtmpfs 506M 0 506M 0% /dev
tmpfs 522M 87k 522M 1% /dev/shm
tmpfs 522M 14M 508M 3% /run
tmpfs 522M 0 522M 0% /sys/fs/cgroup
二.設備名稱的讀取
1./dev/xd*
x=s /dev/sd* ##sate硬盤,或者iscsi網絡存儲
x=v /dev/vd* ##虛擬硬盤,一般出現在虛擬機裏
x=h /dev/hd* ##ide硬盤 ,一般出現在老式電腦裏
*=a~... ##/dev/vda, 系統中的第一塊虛擬硬盤
/dev/sda1 ##系統中的第一塊sate硬盤的第一個分區
2./dev/cdrom,/dev/sr[0-...] ##系統中的光驅
3./dev/mapper/* ##系統中的虛擬設備
三.設備的使用
設備必須用目錄來對設備中的內容進行讀取
所以設備使用時需要作掛載動作
1.blkid ##識別設備
[root@really ~]# blkid
/dev/sda1: UUID="B01E51981E515904" TYPE="ntfs"
/dev/sda2: UUID="d2f71dd0-0b65-4c28-b6b0-da684548456f" TYPE="xfs"
/dev/sda3: UUID="373992f9-e6b5-4901-b734-8cfb74f61b0d" TYPE="swap"
/dev/sda5: UUID="e39bbd52-0703-4015-819d-8664d40e7c4a" TYPE="xfs"
/dev/sdb1: LABEL="M-gM-3M-;M-gM-;M-^_" UUID="0000678400004823" TYPE="ntfs"
/dev/sdb5: LABEL="M-hM-=M-/M-dM-;M-6" UUID="0000678400004823" TYPE="ntfs"
/dev/sdb6: LABEL="M-fM-^VM-^GM-fM-!M-#" UUID="0000678400004823" TYPE="ntfs"
/dev/sdb7: LABEL="M-eM-(M-1M-dM-9M-^P" UUID="0000678400004823" TYPE="ntfs"
/dev/loop0: UUID="2015-10-30-11-11-49-00" LABEL="RHEL-7.2 Server.x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/sdc1: LABEL="HP v285w" UUID="9B03-2CED" TYPE="vfat" ##插入的u盤
[root@really ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 56237232 40605444 15631788 73% /
devtmpfs 3870272 0 3870272 0% /dev
tmpfs 3879028 568 3878460 1% /dev/shm
tmpfs 3879028 9256 3869772 1% /run
tmpfs 3879028 0 3879028 0% /sys/fs/cgroup
/dev/sda2 508588 120876 387712 24% /boot
/dev/loop0 3947824 3947824 0 100% /var/www/html/rh7.2
/dev/sdc1 31020992 2929920 28091072 10% /run/media/kiosk/HP v285w ##u盤掛載位置
2.mount 設備 掛載點
##掛載設備(掛載在一個目錄後 可查看設備裏的內容 不能查看原來目錄裏的東西)
(1)##默認不加參數爲讀寫
(2)-o ro ##-o 指定動作 ro表示read only
[root@really mnt]# mount -o ro /dev/sdc1 /mnt
[root@really mnt]# ls -lr /mnt
total 32
drwxr-xr-x. 8 root root 16384 Oct 30 15:31 ????
drwxr-xr-x. 4 root root 16384 Oct 28 11:34 ??
[root@really mnt]# touch file /mnt
touch: setting times of ‘/mnt’: Read-only file system
(3)-o remount,rw 設備或掛載點 ##熱更改爲讀寫 不需要解掛載(在設備使用時將參數改爲rw)
[root@really mnt]# mount -o remount,rw /dev/sdc1
[root@really mnt]# touch /mnt/file
[root@really mnt]# ls -lr /mnt
total 32
-rwxr-xr-x. 1 root root 0 Nov 6 11:30 file
drwxr-xr-x. 8 root root 16384 Oct 30 15:31 ????
drwxr-xr-x. 4 root root 16384 Oct 28 11:34 ??
3.umount 設備|掛載點 ##卸載設備(可接設別或掛載點 任意)
[root@really mnt]# umount /dev/sdc1 ##卸載u盤掛載
[root@really mnt]# df ##查看正在使用的設備
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 56237232 40606232 15631000 73% /
devtmpfs 3870272 0 3870272 0% /dev
tmpfs 3879028 568 3878460 1% /dev/shm
tmpfs 3879028 9252 3869776 1% /run
tmpfs 3879028 0 3879028 0% /sys/fs/cgroup
/dev/sda2 508588 120876 387712 24% /boot
/dev/loop0 3947824 3947824 0 100% /var/www/html/rh7.2
注意:當卸載設備時出現下列情況
[root@server zl]# umount /dev/vdb1
umount: /zl: target is busy. ##出現如下報錯時
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
表示設備正在被系統的某個程序使用的處理方法:
(1)進程發現的方式
1.fuser -vm 設備
[root@foundation14 ~]# fuser -vm /dev/sdb1
USER PID ACCESS COMMAND
/dev/sdb1: root kernel mount /mnt
root 20071 ..c.. bash
root 20720 F.c.. vim
2.lsof 設備
[root@foundation14 ~]# lsof /dev/sdb1
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 20071 root cwd DIR 8,17 16384 1 /mnt
vim 20720 root cwd DIR 8,17 16384 1 /mnt
vim 20720 root 3u REG 8,17 12288 3096 /mnt/.file.swo
(2)關閉進程的方法
1.fuser -kvm 設備
[root@foundation14 ~]# fuser -kvm /dev/sdb1
USER PID ACCESS COMMAND
/dev/sdb1: root kernel mount /mnt
root 15647 ..c.. bash
root 20021 F.c.. vim
[root@foundation14 ~]# umount /dev/sdb1
[root@foundation14 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 266049616 23050820 242998796 9% /
devtmpfs 1868044 0 1868044 0% /dev
tmpfs 1881152 516 1880636 1% /dev/shm
tmpfs 1881152 9016 1872136 1% /run
tmpfs 1881152 0 1881152 0% /sys/fs/cgroup
/dev/sda2 505580 149488 356092 30% /boot
/dev/loop0 3947824 3947824 0 100% /var/www/html/rh7.2
/dev/loop1 3947824 3947824 0 100% /rh7.2
tmpfs 376232 20 376212 1% /run/user/1000
2.kill -9 uid
[root@foundation14 ~]# kill -9 2007
-bash: kill: (2007) - No such process
[root@foundation14 ~]# kill -9 20071
[root@foundation14 ~]# umount /dev/sdb1
[root@foundation14 ~]# df
(二)設備的分區
一.設備分區信息
1.mbr 主引導 446bit(字節) 磁頭去找系統的啓動分區
2.mbr + 55aa (2個字節 硬盤有效性標示類似於目錄)+mpt (主分區表64字節)=512
3.一個主分區佔用主分區表16個字節記錄分區信息
4.一塊硬盤上如果用mbr分區方式 最多可以存在四個主分區
5.『分區表記錄的爲主分區
擴展分區彌補分區表不足 記錄邏輯分區』(mbr分區方式,一個分區最大2tb)
二.分區的劃分
1.[root@node1 ~]# fdisk -l ##發現系統中的設備
Disk /dev/vda: 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: 0x00013f3e
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 20970332 10484142+ 83 Linux ##vda1 已經被全部使用
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors ##vdb還沒有分區
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
2.[root@node1 ~]# fdisk /dev/vdb ##進入/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 0x12a6a759.
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
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 ##拓展分區
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): wq ##保存分區策略並退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3.[root@node1 ~]# cat /proc/partitions ##查看新建分區有沒有被系統識別
major minor #blocks name
253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
253 17 102400 vdb1 ##被識別
[root@node1 ~]# mount /dev/vdb1 /mnt ##可以識別但不能使用
mount: /dev/vdb1 is write-protected, mounting read-only
mount: unknown filesystem type '(null)' ##沒有識別硬盤信息的軟件(文件系統)
##文件系統包括
#ext2-4 日誌文件系統(可以支持數據32TB分區)
#fwt(4TB)
#wrfs(32TB)
#xfs (18EB 吞吐速度可達到7GB/s 硬盤達不到 大數據常用)
4.[root@node1 ~]# mkfs.xfs /dev/vdb1
##格式化設備
meta-data=/dev/vdb1 isize=256 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@node1 ~]# blkid ##查看可用設備
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/vdb1: UUID="22987d47-c812-47b3-9fa1-af8436dec326" TYPE="xfs" ##可以看到被格式化好的設備
[root@node1 ~]# mount /dev/vdb1 /mnt ##掛載設備 使設備投入使用
[root@node1 ~]# cd /mnt
[root@node1 mnt]# ls
[root@node1 mnt]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3831836 6642064 37% /
devtmpfs 481120 0 481120 0% /dev
tmpfs 496708 84 496624 1% /dev/shm
tmpfs 496708 13064 483644 3% /run
tmpfs 496708 0 496708 0% /sys/fs/cgroup
/dev/vdb1 98988 5280 93708 6% /mnt ##掛載的設備
三.設備永久掛載
1.[root@node1 mnt]# vim /etc/fstab
##設備掛載配置文件
設備 掛載點 文件系統類型 掛載參數 是否備份設備 是否檢測設備
/dev/vdb1 /zl xfs default 0 0
2.[root@node1 mnt]# mount -a
##讓fstab中未生效的策略生效
[root@node1 mnt]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3831848 6642052 37% /
devtmpfs 481120 0 481120 0% /dev
tmpfs 496708 84 496624 1% /dev/shm
tmpfs 496708 13064 483644 3% /run
tmpfs 496708 0 496708 0% /sys/fs/cgroup
/dev/vdb1 98988 5280 93708 6% /zl
3.排錯 如配置文件寫錯 會導致系統啓動失敗 用之前學習的重置root密碼類似的方式 修改配置文件
四.刪除分區
1.[root@node1 mnt]# vim /etc/fstab
##刪除永久掛載配置策略
2.[root@node1 mnt]# umount /dev/vdb1
##卸載掛載
[root@node1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3832384 6641516 37% /
devtmpfs 481120 0 481120 0% /dev
tmpfs 496708 84 496624 1% /dev/shm
tmpfs 496708 13064 483644 3% /run
tmpfs 496708 0 496708 0% /sys/fs/cgroup
3.[root@server ~]# 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): d
Selected partition 1
Partition 1 is deleted
五.分區方式修改
一.mbr----->gpt
1.[root@node1 mnt]# parted /dev/vdb ##修改硬盤分區方式
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel ##修改分區方式
New disk label type? gpt ##改爲gpt
Warning: The existing disk label on /dev/vdb will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? y ##是否更改
(parted) quit ##退出
Information: You may need to update /etc/fstab. ##提示有新的更改 建議同步配置文件
2.[root@node1 mnt]# fdisk -l ##查看
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: gpt ##改爲gpt了
3.[root@node1 mnt]# fdisk /dev/vdb ##在gpt分區模式下新建立分區
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
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): n
Partition number (1-128, default 1): 1 ##可以存在128個分區
二.gpt--------->mbr
1.[root@node1 mnt]# parted /dev/vdb
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
New disk label type? msdos
Warning: The existing disk label on /dev/vdb will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? y
(parted) quit
Information: You may need to update /etc/fstab.
2.[root@node1 mnt]# fdisk -l
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: 0x00033857
(三)swap分區的管理
一.swap 分區的查看
[root@foundation14 ~]# swapon -s
Filename Type Size Used Priority
/dev/sda3 partition 3933180 0 -1
二.swap 分區的建立
1.[root@node1 ~]# 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): n ##新建分區
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (206848-20971519, default 206848):
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +100M
Partition 2 of type Linux and of size 100 MiB is set
Command (m for help): t ##更改分區id
Partition number (1,2, default 2): 2 ##選擇更改哪個分區
Hex code (type L to list all codes): l ##列出所有分區id
Hex code (type L to list all codes): 82 ##更改id的編號
Changed type of partition 'Linux' to 'Linux swap / Solaris' ##更改成功
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
2.[root@node1 ~]# mkswap /dev/vdb2 ##格式化新建分區
Setting up swapspace version 1, size = 102396 KiB
no label, UUID=0722a0b2-503c-43cb-aad1-a92b65284ec4
[root@node1 ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/vdb1: UUID="cb24b1a8-b3b9-4e61-ab84-ef86c9df0903" TYPE="swap"
/dev/vdb2: UUID="0722a0b2-503c-43cb-aad1-a92b65284ec4" TYPE="swap"
3.[root@node1 ~]# swapon -a /dev/vdb2
##激活swap 使系統利用此設備(swap是系統利用設備 不需要掛載)
[root@node1 ~]# fdisk -l
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 411647 102400 82 Linux swap / Solaris
4.[root@node1 ~]# vim /etc/fstab ##開機自動激活swap
/dev/vdb2 swap swap defaults 0 0
5.[root@node1 ~]# swapoff /dev/vdb2 ##關閉
三.當磁盤全部被佔用 不能創建新分區時 可以用文件來代替
1.[root@node1 ~]# dd if=/dev/zero of=/swapfile bs=1M count=1000 ##從/dev/zero(爲空) 截取1M的片段1000個(1G) 新建爲/swapfile文件
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 14.8073 s, 70.8 MB/s
[root@node1 ~]# du -sh /swapfile ##查看新建文件大小
1000M /swapfile
2.[root@node1 ~]# mkswap /swapfile ##格式化文件
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=5d6920f6-584e-48f4-a236-7c4ef31c911d
[root@node1 ~]# blkid ##查看不到/swapfile 因爲其表示設備是文件
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/vdb1: UUID="cb24b1a8-b3b9-4e61-ab84-ef86c9df0903" TYPE="swap"
/dev/vdb2: UUID="0722a0b2-503c-43cb-aad1-a92b65284ec4" TYPE="swap"
3.[root@node1 ~]# vim /etc/fstab ##編輯配置文件
/swapfile swap swap defaults 0 0
4.[root@node1 ~]# swapon -a ##激活
swapon: /swapfile: insecure permissions 0644, 0600 suggested.
[root@node1 ~]# swapon -s ##查看
Filename Type Size Used Priority
/dev/vdb2 partition 102396 0 -1
/swapfile file 1023996 0 -2
(四)磁盤配額
爲磁盤使用用戶分配額度
分區配額針對設備
1.[root@node1 ~]# mount -o usrquota /dev/vdb1 /zl/ ##激活設置配額參數
2.[root@node1 ~]# chmod 777 /zl/ ##加權限 爲下面實驗做準備
3.[root@node1 ~]# edquota -u student /dev/vdb1 ##編輯對於/dev/vdb1硬盤的student用戶的使用限額
Disk quotas for user student (uid 1000):
Filesystem blocks soft hard inodes soft hard
/dev/vdb1 0 0 204800 0 0 0
4.效果
(1)[student@node1 ~]$ dd if=/dev/zero of=/zl/fiel bs=1M count=20 ##在/zl中創建20M的文件
20+0 records in
20+0 records out
20971520 bytes (21 MB) copied, 0.0400231 s, 524 MB/s
[student@node1 ~]$ du -sh /zl/file ##成功創建20M文件
20M /zl/file
(2)[student@node1 ~]$ dd if=/dev/zero of=/zl/fiel bs=1M count=220 ##在/zl中創建220M的文件
dd: error writing ‘/zl/fiel’: Disk quota exceeded
201+0 records in
200+0 records out
209715200 bytes (210 MB) copied, 0.744319 s, 282 MB/s
[student@node1 ~]$ du -sh /zl/file ##只創建出200M文件 因爲之前設置的student用戶使用此設備的配額爲200M
200M /zl/file
5.開機自動激活配額
/dev/vdb1 /zl xfs defaults,usrquota 0 0
(五)分區加密
一.分區加密
1.[root@localhost ~]# fdisk /dev/vdb ##新建分區
2.[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:
3.[root@localhost mapper]# cryptsetup open /dev/vdb1 zl ##解密設備
Enter passphrase for /dev/vdb1:
4.[root@localhost mapper]# mkfs.xfs /dev/mapper/zl ####用管理文件格式化設備(/dev/mapper/zl 爲設備加密時的形態)
meta-data=/dev/mapper/zl isize=256 agcount=4, agsize=655168 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=2620672, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
5.[root@localhost mapper]# mount /dev/mapper/zl ##掛載設備 設備內容可讀寫
mount: can't find /dev/mapper/zl in /etc/fstab
[root@localhost mapper]# mount /dev/mapper/zl /mnt/
[root@localhost mapper]# touch /mnt/file{1..5}
[root@localhost mapper]# cd /mnt
[root@localhost mnt]# ls
file1 file2 file3 file4 file5
6.[root@localhost ~]# umount /mnt ##卸載設備
7.[root@localhost ~]# cryptsetup close zl ##關閉設備加密層
[root@localhost ~]# mount /dev/mapper/zl /mnt/ ##無法使用設備
mount: special device /dev/mapper/zl does not exist
[root@localhost ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/vdb1: UUID="eb723191-7d41-40b5-a06a-00fc027ad663" TYPE="crypto_LUKS" ##設備加密
二.開機自動加密
1.[root@localhost ~]# vim /etc/fstab
/dev/mapper/zl /mnt xfs defaults 0 0
2.[root@localhost ~]# vim /etc/crypttab
zl /dev/vdb1 /root/passfile
3.[root@localhost ~]# vim /root/passfile
19970214
4.root@localhost ~]# chmod 600 /root/passfile
5.[root@localhost ~]# cryptsetup luksAddKey /dev/vdb1 /root/passfile
Enter any passphrase:
三.加密的清除
1.[root@localhost ~]# umount /dev/mapper/zl ##卸載設備
2.[root@localhost ~]# cryptsetup close zl ##關閉設備加密層
3.[root@localhost ~]# mkfs.xfs /dev/vdb1 ##格式化設備 破壞加密
mkfs.xfs: /dev/vdb1 appears to contain an existing filesystem (crypto_LUKS).
mkfs.xfs: Use the -f option to force overwrite.
4.[root@localhost ~]# mkfs.xfs /dev/vdb1 -f ##強制執行3.
meta-data=/dev/vdb1 isize=256 agcount=4, agsize=655296 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=2621184, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
5.[root@localhost ~]# vim /etc/fstab ##刪除加密時修改的配置文件
[root@localhost ~]# cat /etc/fstab
#
## /etc/fstab
## Created by anaconda on Wed May 7 01:22:57 2014
##
## Accessible filesystems, by reference, are maintained under '/dev/disk'
## See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
##
#UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 / xfs defaults 1 1
6.[root@localhost ~]# vim /etc/crypttab ##刪除加密時修改的配置文件
[root@localhost ~]# cat /etc/crypttab ##內容爲空