第二本書 第四單元總結

################################
####第二本書 第四單元##############
###############################
一.分區劃分
fdisk /dev/vdb
The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
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           ##修改分區功能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 (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p):                                     ##默認位主分區
Using default response p
Partition number (3,4, default 3):                      ##主分區id
First sector (976773120-976773167, default 976773120):  ##此分區起始位置
Using default value 976773120
Last sector, +sectors or +size{K,M,G} (976773120-976773167, default 976773167):+100M  ##分區大小

Command (m for help): p

Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0xaa46f25b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   167776255    83887104    7  HPFS/NTFS/exFAT
/dev/sda2       167776256   976773119   404498432    f  W95 Ext'd (LBA)
/dev/sda5       167778304   438312959   135267328    7  HPFS/NTFS/exFAT
/dev/sda6       438315008   708849663   135267328    7  HPFS/NTFS/exFAT
/dev/sda7       708851712   708855807        2048   83  Linux
/dev/sda8       708857856   709881855      512000   83  Linux
/dev/sda9       709883904   717486079     3801088   82  Linux swap / Solaris
/dev/sda10      717488128   976773119   129642496   83  Linux


Command (m for help): wq           ##保存退出,如果按q表示放棄更改退出


二.swap
換空間或交換區是磁盤驅動器上的空間 , 用作當前未使用部分內存的溢出。這樣 , 系統就能在主內存中留出空間用於儲存當前正在處理的數據 , 並在系統面臨主內存空間不足的風險時提供應急溢出


mkswap /dev/vdaN 會準備好將分區用作交換區
blkid /dev/vdaN 將確定 UUID
   將新交換空間添加到 /etc/fstab :
  UUID=uuid swap swap defaults 0 0
  /dev/vdaN
swapon -a 將激活新交換區
swapon -s 將顯示當前交換區的狀態
swapoff /dev/vdaN 將停用該特定交換區

三.磁盤
1.磁盤加密
fdisk /dev/vdb
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:                    ##確認密碼

cryptsetup open /dev/vdb1 westos   ##解密
mkfs.xfs  /devmapper/westos        ##用管理文件格式化設備
mount /dev/mapper/westos /mnt/     ##使用設備
umount /mnt/                       ##使用設備
cryptsetup close westos            ##關閉設備加密層

2.加密磁盤的永久掛載
vim /etc/crypttab
解密後設備管理文件      設備                  加密字符存放文件
redhat          /dev/vdb1    /root/lukspsfile
vim /root/luspsfile
chmod 600 /root/lukspsfile
cryptsetup luksAddKey /dev/vdb1  /root/lukspsfile
vim 600 /root/lukspsfile
cryptsetup luksAddKey  /dev/vdb1  /root/lukspsfile
vim /etc/fstab
/dev/mapper/redhat   /mnt   xfs   defaults
reboot

3.加密清除
vim /etc/fatab
> /etc/crypttab
rm -fr /root/lukspsfile
umount /mnt/
cryptsetup close redhat
mkfs.xfs /dev/vdb1

4.磁盤陣列
fdisk /dev/vdb   ##創建分區

mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3}
    -C    ##建立
    -a    ##文件不存在建立文件
    -l    ##raid級別
    -n    ##設備個數
    -x    ##閒置設備個數

mkfs.xfs /dev/md0
mount /dev/md0 /mnt/
watch -n 1 cat /proc/mdstat

mdadm -f /dev/md0 /dev/vdb1    ##損壞設備1
mdadm -D /dev/md0
mdadm -r /dev/md0 /dev/vdb1    ##移除設備1
mdadm -a /dev/md0 /dev/vdb1    ##恢復設備1
umount /mnt/
mdadm -S /dev/md0              ##停止設備

5.配額
mount -o usrquota /dev/vdb1 /pub
quotaon -uv /dev/vdb1
edquota -u student
Disk quotas for user student (uid 1000):
 Filesystem         blocks       soft          hard     inodes  soft   hard
   /dev/vdb1        102400        0            40000       1     0       0
su - student
dd if=/dev/zero of=/pub/file bs=1M count=500
dd:error writing '/pub/file': Disk quota exceeded
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章