二:Unit 4

######################################

###########II 第四單元################

######################################

##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                ##指定劃分設備的分區類型

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Partition number (1-4, default 1):1        ##指定使用的分區表號

First sector (2048-20971519, default 2048):enter    ##分區起始快,選擇默認

Using default value 2048

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

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

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048     2099199     1048576   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 實現永久掛載

 

 

##3.設備刪除

卸載

刪除 /etc/fstab中設備的自動掛載條目

fdisk刪除分區

 

##4.swap分區的管理

swapon -s            ##查看系統中的swap分區

建立swap分區

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

swapon -a /dev/vdb1        ##激活

vim /etc/fstab        ##開機自動激活

/dev/vdb1swapswapdefautls0 0

 

 

刪除/etc/fstab中的swap自動激活條目

swapoff /dev/vdb1        ##關閉激活的swap分區

 

 

 

##5.磁盤加密

1.磁盤加密

fdisk /dev/vdb                ##分區

cryptsetup luksFormat /dev/vdb1         ##加密

cryptsetup open /dev/vdb1 westos       ##打開

mkfs.xfs /dev/mapper/westos           ##格式化

mount /dev/mapper/westos /mnt/        ##掛載

umount /mnt/                   ##卸載

cryptsetup close westos              ##退出

2.加密磁盤的永久掛載

vim /etc/cryppttabb

解密後設備管理文件設備加密字符存放文件

redhat/dev/vdb1/root/lukspsfile

 

vim /root/lukspsfile

1996022419

chmod 600 /root/lukspsfile

 

cryptsetup luksAddKey /dev/vdb1 /root/lukspsfile    ##把密碼記錄文件與設備關聯

 

vim /etc/fstab

/dev/mapper/redhat/mntxfsdefaults0 0            ##開機自動掛載加密設備

 

reboot

 

 

3.加密清除

vim /etc/fstab

> /etc/crypttab

rem -fr /root/lukspsfile

umount /mnt/

cryptsetup close redhat

mkfs.xfs /dev/vdb1

df

 

 


##6.磁盤陣列

fdisk /dev/vdb##劃分三個分區

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

      創建          若沒有則新建級別使用的盤塊閒置盤塊

mkfs.xfs /dev/md0            ##格式化

mount /dev/md0 /mnt/            ##掛載

watch -n 1 cat /proc/mdstat        ##監控命令

 

 

mdadm -f /dev/md0 /dev/vdb1    ##停止

mdadm -D /dev/md0         ##查看狀態

mdadm -r /dev/md0 /dev/vdb1    ##刪除

mdadm -a /dev/md0 /dev/vdb1    ##新建

umount /mnt/            ##卸載

mdadm -S /dev/md0         ##停止使用(當只省一塊分區時先卸載再執行-S)

 

 

 

 

 

##7.配額

fdisk /dev/vdb            ##新建vdb1

mkfs.xfs /dev/vdb1

mkdir /pub                ##新建目錄

chmod 1777 /pub            ##設置/pub權限

mount -o usrquota /dev/vdb1 /pub    ##掛載

quotaon -uv /dev/vdb1

edquota -u student            ##設置

 

 

 

su - student                ##切換用戶

dd if=/dev/zero of=/pub/file bs=1M count=500

 

 

 

 

quota                ##查看

 


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