Linux学习笔记18

来源:互联网 发布:深圳cnc编程学徒招聘 编辑:程序博客网 时间:2024/06/05 14:09


Ⅱ. 第四单元


#1.分区方式#


[root@diskctrl ~]# 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.

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 ##改变分区功能标签

   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): enter

Using default response p

Partition number (1-4, default 1): enter##指定使用的分区表号

First sector (2048-20971519, default 2048):enter ##分区起始快,选择默认

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):+500M ##设备大小指定

 

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: 0xedc42ff5

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048     1026047      512000   83   Linux##被划分出来的分区

 

Command (m for help):  wq    ##保存更改方式并退出

 

 

[root@diskctrl ~]# partprobe ##同步分区表

[root@diskctrl ~]# cat /proc/partitions ##查看系统能识别的分区

major minor  #blocks  name

 

 253        0   10485760 vda

 253        1   10484142 vda1

 253       16   10485760 vdb

 253       17    1048576 vdb1



#2.如何使用新建立的分区#


格式化

挂载


vim /etc/fstab ##实现永久挂载

 




#新建分区脚本#

vim /bin/fdisk.sh

1 #!/bin/bash

2 fdisk   $1<<end

3 n ##新建分区

4 $2 ##指定分区类型

5 ##默认分区表号

6 ##默认分区起始块

7 $3 ##指定分区大小

8 wq ##保存更改方式退出

9 end

 


chmod +x /bin/fdisk.sh


 


#3.设备删除#


卸载


删除 /etc/fstab中设备的自动挂载条目



fdisk删除分区

 


#4.swap分区的管理#


swapon -s  ##查看系统中的swap分区



建立swap分区

mkswap /dev/vdb1 ###把/dev/vdb1格式化成swap格式

swapon -a /dev/vdb1 ##激活



vim /etc/fstab ##开机自动激活

/dev/vdb1 swap swap defautls 0 0

 


 


删除/etc/fstab中的swap自动激活条目

swapoff /dev/vdb1 ##关闭激活的swap分区

 


#5.分区加密#


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: ##确认密码

 

[root@diskctrl ~]# cryptsetup open /dev/vdb1  HnSoi##解密

Enter passphrase for /dev/vdb1:

 

[root@diskctrl ~]# mkfs.xfs  /dev/mapper/HnSoi ##用管理文件格式化设备

[root@diskctrl ~]# mount /dev/mapper/HnSoi  /mnt/##使用设备

[root@diskctrl ~]# umount /dev/mapper/HnSoi   ##卸载设备

[root@diskctrl mnt]# cryptsetup close HnSoi ##关闭设备加密层




#6.自动挂载加密设备#


[root@diskctrl ~]# vim /etc/crypttab ##设定开机解密

解密后名称 设备 密码文件

[root@diskctrl ~]# vim /etc/fstab ##开机自动挂载加密设备

/dev/mapper/westos /mnt xfs defaults 0 0

[root@diskctrl ~]# vim /root/passwd ##系统自动读取密码记录文件

解密密码

[root@diskctrl ~]# cryptsetup luksAddKey /dev/vdb1  /root/passwd##把密码记录文件与设备关联

Enter any passphrase: ##设备解密密码

 

 

 

#7.raid 磁盘阵列#


建立3个分区,并设定3个分区的功能标签位raid



mdadm  -C /dev/md0 -a yes -l 1 -n 2  -x 1  /dev/vdb{1..3}

-C ##建立

-a ##文件不存在建立文件

-l ##raid级别

-n ##设备个数

-x ##闲置设备个数




mdadm -D /dev/md0 ##设备配置信息



mdadm /dev/md0 -f /dev/vdb1 ##损坏设备1





mdadm /dev/md0 -r /dev/vdb1 ##移除设备1



mdadm /dev/md0 -a /dev/vdb1 ##恢复设备1




mdadm -S /dev/md0 ##停止设备

 


#设备删除#


[root@station ~]# umount /mnt/

[root@station ~]# mdadm -S /dev/md0

mdadm: stopped /dev/md0

[root@station ~]# fdisk /dev/vdb

欢迎使用 fdisk (util-linux 2.23.2)。

 

更改将停留在内存中,直到您决定将更改写入磁盘。

使用写入命令前请三思。

 

 

命令(输入 m 获取帮助):d

分区号 (1-3,默认 3):

分区 3 已删除

 

命令(输入 m 获取帮助):d

分区号 (1,2,默认 2):

分区 2 已删除

 

命令(输入 m 获取帮助):d

已选择分区 1

分区 1 已删除

 

命令(输入 m 获取帮助):wq

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

正在同步磁盘。

[root@station ~]# partprobe 


0 0
原创粉丝点击