######管理系統存儲######node
####1.分區劃分####linux
Command actionvim
a toggle a bootable flagapp
b edit bsd disklabelide
c toggle the dos compatibility flagui
d delete a partition ####刪除分區this
g create a new empty GPT partition table加密
G create an IRIX (SGI) partition tablespa
l list known partition typesdebug
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)
[root@localhost ~]# fdisk -l ###顯示系統中全部能夠使用的設備
Disk /dev/vda: 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: 0x00013f3e
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 20970332 10484142+ 83 Linux
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
[root@desktop28 ~]# fdisk /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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x0374426c.
Command (m for help): n ####增長一個新的分區
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p ###p爲主分區
Partition number (1-4, default 1): ####默認主分區id
First sector (2048-20971519, default 2048): ####此分區的起始位置
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M ####分區大小
Partition 1 of type Linux and of size 100 MiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (206848-20971519, default 206848):
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +100M
Partition 2 of type Linux and of size 100 MiB is set
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (411648-20971519, default 411648):
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-20971519, default 20971519): +100M
Partition 3 of type Linux and of size 100 MiB is set
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e):
Using default response e ###e爲拓展分區(最多分四個分區第四個爲拓展分區,要給他剩下的所有空間,拓展分區裏面能夠繼續分,爲邏輯分區)
Selected partition 4
First sector (616448-20971519, default 616448):
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-20971519, default 20971519):
Using default value 20971519
Partition 4 of type Extended and of size 9.7 GiB is set
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (618496-20971519, default 618496):
Using default value 618496
Last sector, +sectors or +size{K,M,G} (618496-20971519, default 20971519): +100M
Partition 5 of type Linux and of size 100 MiB is set
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: 0x0374426c
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 411647 102400 83 Linux
/dev/vdb3 411648 616447 102400 83 Linux
/dev/vdb4 616448 20971519 10177536 5 Extended
/dev/vdb5 618496 823295 102400 83 Linux
Command (m for help): wq ####保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@desktop28 ~]# partprobe ####同步分區列表
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@localhost ~]# cat /proc/partitions ####查看磁盤分區
major minor #blocks name
253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
253 17 102400 vdb1
253 18 102400 vdb2
253 19 102400 vdb3
253 20 1 vdb4
253 21 101376 vdb5
11 0 3799040 sr0
######掛載#####
[root@localhost ~]# mount /dev/vdb5 /mnt/
mount: /dev/vdb5 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'
[root@localhost ~]# mkfs.xfs /dev/vdb5 ####格式化(安裝.xfs文件)
meta-data=/dev/vdb5 isize=256 agcount=4, agsize=6336 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=25344, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mount /dev/vdb5 /mnt/ ###臨時掛載
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3813008 6660892 37% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17024 925636 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/vdb5 97964 5228 92736 6% /mnt
[root@localhost ~]# mount
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=927072k,nr_inodes=231768,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/vda1 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
sunrpc on /proc/fs/nfsd type nfsd (rw,relatime)
/dev/vdb5 on /mnt type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
[root@localhost ~]# vim /etc/fstab ##永久掛載(0 0 :不備份不檢測)
/dev/vdb5 /mnt/ xfs defaults 0 0
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3812972 6660928 37% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17024 925636 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/vdb5 97964 5228 92736 6% /mnt
[root@localhost ~]# umount /mnt/
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3812952 6660948 37% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17024 925636 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
[root@localhost ~]# mount -a #####讀取/etc/fstab
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3812952 6660948 37% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17024 925636 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/vdb5 97964 5228 92736 6% /mnt
[root@localhost ~]# blkid ###顯示系統正在使用設備id
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/vdb5: UUID="f8173528-d977-436b-b08c-cc66cdb8d60f" TYPE="xfs"
/dev/sr0: UUID="2015-02-19-11-11-02-00" LABEL="RHEL-7.1 Server.x86_64" TYPE="iso9660" PTTYPE="dos"
###########2.swap######
[root@desktop28 ~]# fdisk /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): n
All primary partitions are in use
Adding logical partition 6
First sector (825344-20971519, default 825344):
Using default value 825344
Last sector, +sectors or +size{K,M,G} (825344-20971519, default 20971519): +1000M
Partition 6 of type Linux and of size 1000 MiB is set
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: 0x0374426c
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 411647 102400 83 Linux
/dev/vdb3 411648 616447 102400 83 Linux
/dev/vdb4 616448 20971519 10177536 5 Extended
/dev/vdb5 618496 823295 102400 83 Linux
/dev/vdb6 825344 2873343 1024000 83 Linux
Command (m for help): t ####修改分區功能id
Partition number (1-6, default 6): 6
Hex code (type L to list all codes): l
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'
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: 0x0374426c
Device Boot Start End Blocks Id System
/dev/vdb1 2048 206847 102400 83 Linux
/dev/vdb2 206848 411647 102400 83 Linux
/dev/vdb3 411648 616447 102400 83 Linux
/dev/vdb4 616448 20971519 10177536 5 Extended
/dev/vdb5 618496 823295 102400 83 Linux
/dev/vdb6 825344 2873343 1024000 82 Linux swap / Solaris
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@desktop28 ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@desktop28 ~]# mkswap /dev/vdb6 #####命令格式化分區爲swap格式
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=b62379d4-c43f-432b-be9f-d335c57b0434
[root@desktop28 ~]# swapon -s ####
[root@desktop28 ~]# swapon -a /dev/vdb6 ####enable all swaps from /etc/fstab
[root@desktop28 ~]# swapon -s
FilenameTypeSizeUsedPriority
/dev/vdb6 partition10239960-1
[root@desktop28 ~]# vim /etc/fstab
[root@desktop28 ~]# swapoff /dev/vdb6 ##disable all swaps from /dev/vdb6
設備
/dev/vdb6 swap swap defaults 0 0
[root@desktop28 ~]# swapon -s
[root@desktop28 ~]# swapon -a
[root@desktop28 ~]# swapon -s
FilenameTypeSizeUsedPriority
/dev/vdb6 partition10239960-1
#########3.磁盤加密#########
1.磁盤加密
[root@desktop28 mapper]# cryptsetup luksFormat /dev/vdb5 ####對/dev/vdb5進行加密
WARNING!
========
This will overwrite data on /dev/vdb5 irrevocably.
Are you sure? (Type uppercase yes): YES ####(要用大寫)
Enter passphrase:
Verify passphrase:
[root@desktop28 mapper]# mount /dev/vdb5 /mnt/ ####掛載/dev/vdb5 到/mnt/
mount: unknown filesystem type 'crypto_LUKS' ###顯示磁盤已經加密
[root@desktop28 mapper]# cryptsetup open /dev/vdb5 westos ####開鎖(westos:給定一個文件名稱,這個文件會出如今/dev/mapper/下面,)
Enter passphrase for /dev/vdb5: ####輸入密碼
[root@desktop28 mapper]# ll /dev/mapper/
total 0
crw-------. 1 root root 10, 236 Nov 18 20:03 control
lrwxrwxrwx. 1 root root 7 Nov 18 21:37 westos -> ../dm-0
[root@desktop28 mapper]# mount /dev/mapper/westos /mnt/ ####掛載
mount: /dev/mapper/westos is write-protected, mounting read-only
mount: unknown filesystem type '(null)'
[root@desktop28 mapper]# mkfs.xfs /dev/mapper/westos ####格式化(注意:掛載前要對其進行格式化處理)
meta-data=/dev/mapper/westos isize=256 agcount=4, agsize=6272 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=25088, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@desktop28 mapper]# mount /dev/mapper/westos /mnt/
[root@desktop28 mapper]# cd /mnt
[root@desktop28 mnt]# ls
[root@desktop28 mnt]# touch file{1..5}
[root@desktop28 mnt]# ls
file1 file2 file3 file4 file5
[root@desktop28 mnt]# cd
[root@desktop28 ~]# umount /mnt/
[root@desktop28 mnt]# ls
[root@desktop28 mnt]# cryptsetup close westos ####關閉westos
[root@desktop28 mnt]# ll /dev/mapper/
total 0
crw-------. 1 root root 10, 236 Nov 18 20:03 control
[root@desktop28 mnt]# mount /dev/mapper/westos /mnt/
mount: special device /dev/mapper/westos does not exist
2.加密磁盤的永久掛載
[root@desktop28 mapper]# vim /etc/crypttab
解密後設備管理文件 設備 加密字符存放文件
westos /dev/vdb5 /root/lukspsfile
[root@desktop28 mapper]# vim /root/lukspsfile
輸入設定密碼
[root@desktop28 mapper]# chmod 600 /root/lukspsfile
[root@desktop28 mapper]# vim /etc/fstab #####關機重啓後自動執行
/dev/mapper/westos /mnt/ xfs defaults 0 0
[root@desktop28 mapper]# cryptsetup luksAddKey /dev/vdb2 /root/luksfile
Enter any passphrase: ####輸入設定好的密碼
[root@desktop28 mnt]# reboot ###關機重啓,開機後自動掛載
[root@desktop28 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3219328 7254572 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17080 925580 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/mapper/westos 96940 5176 91764 6% /mnt
/dev/sr0 3798292 3798292 0 100% /run/media/root/RHEL-7.1 Server.x86_64
3.加密清楚
[root@desktop28 ~]# vim /etc/fstab
刪除/dev/mapper/westos /mnt/ xfs defaults 0 0
[root@desktop28 ~]# vim /etc/crypttab
刪除解密後設備管理文件 設備 加密字符存放文件
westos /dev/vdb5 /root/lukspsfile
[root@desktop28 ~]# rm -fr /root/lukspsfile ####刪除加密字符存放文件
[root@desktop28 ~]# umount /mnt/
[root@desktop28 ~]# cryptsetup close westos
[root@desktop28 ~]# mkfs.xfs /dev/vdb5 ###格式化/dev/vdb5
mkfs.xfs: /dev/vdb5 appears to contain an existing filesystem (crypto_LUKS).
mkfs.xfs: Use the -f option to force overwrite.
[root@desktop28 ~]# mkfs.xfs /dev/vdb5 -f ###強制格式化
meta-data=/dev/vdb5 isize=256 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@desktop28 ~]# mount /dev/vdb5 /mnt/
#####磁盤陣列######
[root@desktop28 ~]# fdisk /dev/vdb
磁盤分區,分三個同樣大的分區,分區功能id爲fd。
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: 0x0374426c
Device Boot Start End Blocks Id System
/dev/vdb1 2048 2099199 1048576 fd Linux raid autodetect
/dev/vdb2 2099200 4196351 1048576 fd Linux raid autodetect
/dev/vdb3 4196352 6293503 1048576 fd Linux raid autodetect
監控命令:watch -n 1 cat /proc/mdstat
[root@localhost ~]# mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3} ###建一個新的陣列(-C /dev/md0建一個新的陣列;-a yes 有一個/proc/mdstat;-l 1 級別爲1;-n 2 使用兩個;-x 1 一個備用)
mdadm: /dev/vdb1 appears to be part of a raid array:
level=raid1 devices=2 ctime=Sat Nov 19 02:39:55 2016
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
mdadm: /dev/vdb2 appears to be part of a raid array:
level=raid1 devices=2 ctime=Sat Nov 19 02:39:55 2016
mdadm: /dev/vdb3 appears to be part of a raid array:
level=raid1 devices=2 ctime=Sat Nov 19 02:39:55 2016
Continue creating array? yes
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@localhost ~]# mount /dev/md0 /mnt/
[root@localhost ~]# mdadm -D /dev/md0 ###顯示磁盤陣列狀況
/dev/md0:
Version : 1.2
Creation Time : Sat Nov 19 02:45:58 2016
Raid Level : raid1
Array Size : 1048000 (1023.61 MiB 1073.15 MB)
Used Dev Size : 1048000 (1023.61 MiB 1073.15 MB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Sat Nov 19 02:47:10 2016
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Name : localhost:0 (local to host localhost)
UUID : e2215abd:a63d553a:30f55154:42231172
Events : 17
Number Major Minor RaidDevice State
0 253 17 0 active sync /dev/vdb1
1 253 18 1 active sync /dev/vdb2
2 253 19 - spare /dev/vdb3
[root@localhost ~]# mdadm -f /dev/md0 /dev/vdb1 ####破壞/dev/vdb1
mdadm: set /dev/vdb1 faulty in /dev/md0
[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Sat Nov 19 02:45:58 2016
Raid Level : raid1
Array Size : 1048000 (1023.61 MiB 1073.15 MB)
Used Dev Size : 1048000 (1023.61 MiB 1073.15 MB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Sat Nov 19 02:48:33 2016
State : clean, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 1
Spare Devices : 1
Rebuild Status : 62% complete
Name : localhost:0 (local to host localhost)
UUID : e2215abd:a63d553a:30f55154:42231172
Events : 29
Number Major Minor RaidDevice State
2 253 19 0 spare rebuilding /dev/vdb3
1 253 18 1 active sync /dev/vdb2
0 253 17 - faulty /dev/vdb1
[root@localhost ~]# mdadm -r /dev/md0 /dev/vdb1 ####移除/dev/vdb1
mdadm: hot removed /dev/vdb1 from /dev/md0
[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Sat Nov 19 02:45:58 2016
Raid Level : raid1
Array Size : 1048000 (1023.61 MiB 1073.15 MB)
Used Dev Size : 1048000 (1023.61 MiB 1073.15 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Sat Nov 19 02:49:02 2016
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Name : localhost:0 (local to host localhost)
UUID : e2215abd:a63d553a:30f55154:42231172
Events : 39
Number Major Minor RaidDevice State
2 253 19 0 active sync /dev/vdb3
1 253 18 1 active sync /dev/vdb2
[root@localhost ~]# mdadm -a /dev/md0 /dev/vdb1 ###添加/dev/vdb1
mdadm: added /dev/vdb1
[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Sat Nov 19 02:45:58 2016
Raid Level : raid1
Array Size : 1048000 (1023.61 MiB 1073.15 MB)
Used Dev Size : 1048000 (1023.61 MiB 1073.15 MB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Sat Nov 19 02:49:43 2016
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Name : localhost:0 (local to host localhost)
UUID : e2215abd:a63d553a:30f55154:42231172
Events : 40
Number Major Minor RaidDevice State
2 253 19 0 active sync /dev/vdb3
1 253 18 1 active sync /dev/vdb2
3 253 17 - spare /dev/vdb1
[root@localhost ~]# umount /mnt
[root@localhost ~]# mdadm -S /dev/md0 ####中止磁盤陣列
mdadm: stopped /dev/md0
[root@localhost ~]# mdadm -D /dev/md0
mdadm: cannot open /dev/md0: No such file or directory
#####配額#####
分一個磁盤/dev/vdb1,大小爲5G.
[root@desktop28 ~]# mkfs.xfs /dev/vdb1 ####格式化
mkfs.xfs: /dev/vdb1 appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.
[root@desktop28 ~]# mkfs.xfs /dev/vdb1 -f
meta-data=/dev/vdb1 isize=256 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@desktop28 ~]# mkdir /pub ###創建一個/pub目錄
[root@desktop28 ~]# mount /dev/vdb1 /pub ##掛載/dev/vdb1到/pub
[root@desktop28 ~]# chmod 1777 /pub ####給權限(文件只能全部人刪除)
[root@desktop28 ~]# su - westos
Last login: Sat Nov 19 00:56:26 EST 2016 on pts/0
[westos@desktop28 ~]$ dd if=/dev/zero of=/pub/file bs=1M count=3000 ###截取3G的文件到/pub/file
3000+0 records in
3000+0 records out
3145728000 bytes (3.1 GB) copied, 47.9492 s, 65.6 MB/s
[westos@desktop28 ~]$ du -sh /pub/file ###查看文件大小
3.0G/pub/file
[westos@desktop28 ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 3.7G 6.4G 37% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 80K 921M 1% /dev/shm
tmpfs 921M 17M 904M 2% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/vdb1 5.0G 3.0G 2.1G 60% /pub
[westos@desktop28 ~]$ logout
[root@desktop28 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3809528 6664372 37% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17016 925644 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/vdb1 5232640 3104928 2127712 60% /pub
[root@desktop28 ~]# umount /pub/
開始配額:
[root@desktop28 ~]# mount -o usrquota /dev/vdb1 /pub ###掛載
[root@desktop28 ~]# mount
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=927072k,nr_inodes=231768,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/vda1 on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=30,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
sunrpc on /proc/fs/nfsd type nfsd (rw,relatime)
/dev/vdb1 on /pub type xfs (rw,relatime,seclabel,attr2,inode64,usrquota)
[root@desktop28 ~]# quotaon -uv /dev/vdb1 ###
quotaon: Enforcing user quota already on /dev/vdb1
[root@desktop28 ~]# edquota -u westos ###
[root@desktop28 ~]# rm -fr /pub/* ###刪除
[root@desktop28 ~]# edquota -u westos
###配額1000M
Disk quotas for user westos (uid 1001):
Filesystem blocks soft hard inodes soft hard
/dev/vdb1 0 0 1024000 0 0
[root@desktop28 ~]# su - westos
[westos@desktop28 ~]$ dd if=/dev/zero of=/pub/file bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.113085 s, 927 MB/s
[westos@desktop28 ~]$ dd if=/dev/zero of=/pub/file bs=1M count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 8.05441 s, 130 MB/s
[westos@desktop28 ~]$ dd if=/dev/zero of=/pub/file bs=1M count=1010 ###截取內容大於設定配額報錯
dd: error writing ‘/pub/file’: Disk quota exceeded
1001+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 10.2889 s, 102 MB/s
[westos@desktop28 ~]$ du -sh /pub/file
1000M/pub/file
[westos@desktop28 ~]$ touch /pub/file1
touch: cannot touch ‘/pub/file1’: Disk quota exceeded ###也不能新建文件
[root@desktop28 ~]# vim /etc/fstab ###重啓後自動配額
/dev/vdb1 /pub xfs defaults,usrquota 0 0
[root@desktop28 ~]# quotaoff -uv /dev/vdb1 ####關閉配額
Disabling user quota enforcement on /dev/vdb1
/dev/vdb1: user quotas turned off
[root@desktop28 ~]# su - westos
Last login: Sat Nov 19 01:08:49 EST 2016 on pts/0
[westos@desktop28 ~]$ dd if=/dev/zero of=/pub/file bs=1M count=1010
1010+0 records in
1010+0 records out
1059061760 bytes (1.1 GB) copied, 10.5216 s, 101 MB/s