Linux學習筆記18


Ⅱ. 第四單元


#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 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章