Linux是一类Unix计算机操作系统的统称。Linux操作系统的内核的名字也是“Linux”。如何对linux系统进行分区和分区加密呢?下文给出了详细的描述。
redhat企业6中有强大的图形分区工具,这里我分享下我所了解的通过命令行对磁盘进行分区
1、分区
[root@burvis~]#fdisk/dev/sda
WARNING:DOS-compatiblemodeisdeprecated.It'sstronglyrecommendedto
switchoffthemode(command'c')andchangedisplayunitsto
sectors(command'u').
Command(mforhelp):
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
这里如果你用虚拟机的话可以用#fdisk-cu/dev/vda
这里我用虚拟机作演示
我们先按m获取帮助
Commandaction
atoggleabootableflag
beditbsddisklabel
ctogglethedoscompatibilityflag
ddeleteapartition
llistknownpartitiontypes
mprintthismenu
naddanewpartition
ocreateanewemptyDOSpartitiontable
pprintthepartitiontable
qquitwithoutsavingchanges
screateanewemptySundisklabel
tchangeapartition'ssystemid
uchangedisplay/entryunits
vverifythepartitiontable
wwritetabletodiskandexit
xextrafunctionality(expertsonly)
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
这里主要用到的有
n新建一个分区
d删除一个分区
t改变分区类型(进去后按l可以查看所有类型)
p查看分区状况
w写入并退出
q退出不写入
m获取帮助
接下来我们p查看分区信息
Command(mforhelp):p
Disk/dev/vda:6442MB,6442450944bytes
16heads,63sectors/track,12483cylinders,total12582912sectors
Units=sectorsof1*512=512bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x0008f7fd
DeviceBootStartEndBlocksIdSystem
/dev/vda1*204852633526214483Linux
/dev/vda2526336991436746940168eLinuxLVM
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
按n新建一个分区
Command(mforhelp):p
Disk/dev/vda:6442MB,6442450944bytes
16heads,63sectors/track,12483cylinders,total12582912sectors
Units=sectorsof1*512=512bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x0008f7fd
DeviceBootStartEndBlocksIdSystem
/dev/vda1*204852633526214483Linux
/dev/vda2526336991436746940168eLinuxLVM
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
这里按e为扩展分区,p为主分区
我们建一个扩展分区
输入e
选择第三个分区
选择起始点,可以直接回车选择默认
选择终止点,这里可以像我一样用+1G,表示给1G的空间,或者可以直接输入终止点的位置
e
Partitionnumber(1-4):3
Firstsector(9914368-12582911,default9914368):
Usingdefaultvalue9914368
Lastsector,+sectorsor+size{K,M,G}(9914368-12582911,default12582911):+1G
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
我们再输入p看一下分区信息
DeviceBootStartEndBlocksIdSystem
/dev/vda1*204852633526214483Linux
/dev/vda2526336991436746940168eLinuxLVM
/dev/vda399143681201151910485765Extended
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
然后我们再到扩展分区中去新建分区
按n
Command(mforhelp):n
Commandaction
llogical(5orover)
pprimarypartition(1-4)
l
Firstsector(9916416-12011519,default9916416):
Usingdefaultvalue9916416
Lastsector,+sectorsor+size{K,M,G}(9916416-12011519,default12011519):+200M
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
这里选择l,我们给他200M的空间
输入p再看下分区信息。
Command(mforhelp):p
Disk/dev/vda:6442MB,6442450944bytes
16heads,63sectors/track,12483cylinders,total12582912sectors
Units=sectorsof1*512=512bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0x0008f7fd
DeviceBootStartEndBlocksIdSystem
/dev/vda1*204852633526214483Linux
/dev/vda2526336991436746940168eLinuxLVM
/dev/vda399143681201151910485765Extended
/dev/vda599164161032601520480083Linux
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
ok,我们已经分出了一个200M的分区,按w写入并退出
这个时候我们可以ll一下/dev/vda*
发现之前分出的vda3与vda5没有显示
这里我们用以下partx刷新添加
[root@burvis~]#partx-a/dev/vda
BLKPG:Deviceorresourcebusy
erroraddingpartition1
BLKPG:Deviceorresourcebusy
erroraddingpartition2
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
我们在ll一下可以看到已经出来了
[root@server27~]#ll/dev/vda
vdavda1vda2vda3vda5
- 1.
- 2.
- 3.
- 4.
接下来我们就可以对我们的分区进行加密了
2、分区加密
这是对新分区进行加密,并设置密码
这里要注意的地方是大小写
[root@burvis~]#cryptsetupluksFormat/dev/vda5
WARNING!
========
Thiswilloverwritedataon/dev/vda5irrevocably.
Areyousure?(Typeuppercaseyes):YES//YES一定要大写
EnterLUKSpassphrase://密码
Verifypassphrase://确认密码
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
这个时候我们的分区已经被加密,我们要使用必须先解密
这里通过luksOpen来进行解密后面‘burvis’可以写随意的名字,然后会将加密卷/dev/vda5解锁为/dev/mapper/burvis,之后,我们用的都是/dev/mapperburvis了,而不是/dev/vda5
[root@burvis~]#cryptsetupluksOpen/dev/vda5burvis
Enterpassphrasefor/dev/vda5://输入密码
- 1.
- 2.
- 3.
- 4.
然后对解密的卷进行格式化
[root@server27~]#mkfs.ext4/dev/mapper/burvis
- 1.
- 2.
接下来就是把分区挂载到我们的系统上
我们可以建一个挂载的目录,然后把分区挂上去
[root@burvis~]#mkdir/burvis
[root@burvis~]#mount/dev/mapper/burvis/burvis
- 1.
- 2.
- 3.
- 4.
现在我们可以df一下
[root@server27~]#df
Filesystem1K-blocksUsedAvailableUse%Mountedon
/dev/mapper/vgsrv-root
3418812225069299445270%/
tmpfs5107602605105001%/dev/shm
/dev/vda12538713035821040613%/boot
/dev/mapper/vgsrv-home
253871102682304965%/home
/dev/mapper/burvis19633956461805564%/burvis
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
当我们用完我们的加密分区后,就可以卸载它然后再锁住,这样数据就又会保护起来
我们要先卸载我们挂上去的分区,然后再锁住,如果不能锁住,可以尝试下把挂载目录删了
[root@burvis~]#umount/dev/mapper/burvis
[root@burvis~]#cryptsetupluksCloseburvis
- 1.
- 2.
- 3.
- 4.
如果下次先再用,就重复luksOpen就可以了
鉴于开机自动挂载加密分区不安全,没有什么意义,这里就不多加介绍,只附上我的笔记
永久挂载
修改fstab
/dev/mapper/name/*************
编辑/etc/crypttab
vi/etc/crypttab
name/dev/vda*这样子开机会要求输入密码
如果不想输入密码
先编辑一个密码放置的文件比如/root/name
#vi/etc/crypttab
name/dev/vda*/root/name
#echo密码>/root/name
#chownroot/roo/name
#chmod600/root/name
#cryptsetupluksAddKey/dev/vda*/root/name
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
要求输入密码
完成
总结:
希望本文介绍的linux系统进行分区与加密的方法能够对读者有所帮助,更多有关linux操作系统的知识还有待于读者去探索和学习。
【编辑推荐】