磁盘加密及init_crypto脚本分析.docx
文本预览下载声明
LINUX磁盘加密之CRYPTO近分析rc.sysinit启动脚本,正遇磁盘加密之部分,经一番细研,非三言二意可所得。故,捋整究探,分二段于下:挪步接踵设建为先,启动方法分析佐后。使用crypto可以对多数类unix系统中的块设备进行底层数据加密,即在文件系统之下加密。对块设备加密完成后,再对该设备进行文件系统的格式化处理。对加密后的设备进行使用,需通过打开设备(这是需要输入密码)、挂载设备两步来实现。加密设备的退卸,反之即可。若需开机自动挂载(即在/etc/fstab里指明),密码读取的方式可以通过两种方法:手动输入、使用/etc/crypttab指定设备对应的密码文件,具体实现可见第二部分的启动方法分析。接下来首先看如何一步一步实现设备加密。块设备加密创建新的块设备(磁盘、分区、块设备的文件等);使用cryptsetup luksFormat命令把块设备格式化为加密设备,当需要输入yes时记得是大写;使用cryptsetup luksAddKey给加密设备添加密码文件;所谓的密钥文件没有任何变化;使用cryptsetup luksOpen打开设备;格式化打开的设备;修改/etc/fstab使其开机自动挂载;修改/etc/crypttab使其开机时使用密码文件,自动解密;开机测试(reboot)存在于/etc/init.d/function文件中,有关于crypto的方法分析方法init_crypto();通过文件重定向来使用 read注意,这里read命令将会产生一种不直观的行为. 1) 重新从文件的开头开始读入变量. 2) 每个变量都设置成了以空白分割的字符串, 而不是之前的以整行的内容作为变量的值. 3) 而最后一个变量将会取得第一行剩余的全部部分(不管是否以空白分割). 4) 如果需要赋值的变量的个数比文件中第一行一空白分割的字符串的个数多的话, 那么这些变量将会被赋空值.使用read命令读取Linux系统上的文件。?每次调用read命令都会读取文件中的一行文本。当文件没有可读的行时,read命令将以非零状态退出。局部变量 如果变量用 local 来声明,那么它只能在该变量声明的代码块(block of code)中可见. 这个代码块就是局部范围. 在一个函数内,局部变量意味着只能在函数代码块内它才 有意义.ExpressionMeaning${#string}Length of?$string${string:position}Extract substring from?$string?at?$position${string:position:length}Extract?$length?characters substring from?$string?at?$position${string#substring}Strip shortest match of?$substring?from front of?$string${string##substring}Strip longest match of?$substring?from front of?$string${string%substring}Strip shortest match of?$substring?from back of?$string${string%%substring}Strip longest match of?$substring?from back of?$string${string/substring/replacement}Replace first match of?$substring?with?$replacement${string//substring/replacement}Replace?all?matches of?$substring?with?$replacement${string/#substring/replacement}If?$substring?matches?front?end of?$string, substitute?$replacement?for?$substring${string/%substring/replacement}If?$substring?matches?back?end of?$string, substitute?$replacement?for?$substringexpr match $string $substringLength of matching?$substring* at beginning of?$stringexpr $string : $substringLength of matching?$substr
显示全部