unit4 管理系統中的簡單分區和文件系統node
###磁盤劃分###
分爲主分區<最多四個>和擴展分區(可劃分爲邏輯分區<通常16個>)
口令:fdisk /dev/vdb
過程:
[root@station ~]# 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 0x7718cb65.
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 savingchanges
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): 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: 0x7718cb65
Device Boot Start End Blocks Id System
Command (m for help): n ##建立一個新分區
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended ##擴展分區
Select (default p): p ##主分區
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):+1G ##所劃分大小
Partition 1 of type Linux and of size 1 GiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (2099200-20971519, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-20971519, default 20971519):+500M
Partition 2 of type Linux and of size 500 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: 0x7718cb65
Device Boot Start End Blocks Id System
/dev/vdb1 2048 2099199 1048576 83 Linux
/dev/vdb2 2099200 3123199 512000 83 Linux
Command (m for help): wq ##保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@station ~]# partprobe ##同步分區表(在磁盤劃分每步以後都要進行的操做)
####磁盤分區查看####
[root@station ~]# cat /proc/partitions ##查看磁盤分區
linux
[root@station ~]# blkid ##查看可用分區vim
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1"TYPE="xfs"
/dev/vdb5: UUID="e8fc576b-5c7c-4cba-9541-68d6ecca5958"TYPE="xfs"
[root@station ~]# mkfs.xfs /dev/vdb3 ##格式化vdb3分區
meta-data=/dev/vdb3 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@station ~]# blkid ##查看可用分區
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1"TYPE="xfs"
/dev/vdb5: UUID="e8fc576b-5c7c-4cba-9541-68d6ecca5958"TYPE="xfs"
/dev/vdb3: UUID="24af62cd-d6a3-4a62-8954-e7e0b9261cfb"TYPE="xfs" ##和上面對比出現此類型
[root@station ~]# vim /etc/fstabapp
[root@station ~]# mount -a ##文檔的當即生效
[root@station ~]# df ##查看掛載
dom
[root@station ~]# mount /dev/vdb1 /mnt/ ##掛載
[root@station ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3178824 7295076 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17028 925632 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/vdb1 1038336 32928 1005408 4% /mnt
[root@station ~]# 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)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
sunrpc on /proc/fs/nfsd type nfsd (rw,relatime)
gvfsd-fuse on /run/user/0/gvfs type fuse.gvfsd-fuse(rw,nosuid,nodev,relatime,user_id=0,group_id=0)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/vdb5 on /mnt type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/vdb3 on /mnt type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
[root@station ~]# man mount ##可用來查看mount命令
####磁盤分區的劃分####
[root@station ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3240564 7233336 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 472 942188 1% /dev/shm
tmpfs 942660 17056 925604 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/vdb5 98988 5280 93708 6% /mnt
[root@station ~]# umount /mnt/ ##卸載
[root@station ~]# vim /etc/fstab
[root@station ~]# fdisk /dev/vdb(同上系統磁盤劃分)
[root@station ~]# partprobe ##同步分區表
Error: Partition(s) 5 on /dev/vdb have been written, but we have been unable toinform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remainin use. You should reboot now beforemaking further changes.
[root@station ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3240564 7233336 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 472 942188 1% /dev/shm
tmpfs 942660 17040 925620 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
####swap分區的創建與優先級的改變####
[root@station ~]# swapon -s ##顯示簡短的裝置訊息
[root@station ~]# 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
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):+4G
Partition 1 of type Linux and of size 4 GiB is set
Command (m for help): t ##更改文件系統
Selected partition 1
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-FSdata
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS /.
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de DellUtility
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 OnTrackDM 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 DM6Aux 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 ##改成swap格式
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: 0x193165fb
Device Boot Start End Blocks Id System
/dev/vdb1 2048 8390655 4194304 82 Linux swap / Solaris
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@station ~]# partprobe ##同步分區表
[root@station ~]# cat /proc/partitions ##查看已劃分的磁盤
major minor #blocks name
253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
253 17 4194304 vdb1
[root@station ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1"TYPE="xfs"
[root@station ~]# mkswap /dev/vdb1 ##更改分區爲swap格式
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=2b215655-7b6c-4f89-a685-07ff48ea6dc8
[root@station ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1"TYPE="xfs"
/dev/vdb1: UUID="2b215655-7b6c-4f89-a685-07ff48ea6dc8"TYPE="swap"
[root@station ~]# swapon -a /dev/vdb1 ##自動啓動此swap裝置
[root@station ~]# swapon -s ##顯示簡短的裝置訊息
Filename Type Size Used Priority
/dev/vdb1 partition 4194300 0 -1
[root@station ~]# 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
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (8390656-20971519, default 8390656):
Using default value 8390656
Last sector, +sectors or +size{K,M,G} (8390656-20971519, default 20971519):+1G
Partition 2 of type Linux and of size 1 GiB is set
Command (m for help): t #更改格式
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 82 ##選swap格式
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: 0x193165fb
Device Boot Start End Blocks Id System
/dev/vdb1 2048 8390655 4194304 82 Linux swap / Solaris
/dev/vdb2 8390656 10487807 1048576 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 orresource 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@station ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1"TYPE="xfs"
/dev/vdb1: UUID="2b215655-7b6c-4f89-a685-07ff48ea6dc8"TYPE="swap"
[root@station ~]# mkswap /dev/vdb2 ##更改格式
/dev/vdb2: No such file or directory
[root@station ~]# part
parted partprobe partx
[root@station ~]# partprobe ##同步分區表
[root@station ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/vdb1: UUID="2b215655-7b6c-4f89-a685-07ff48ea6dc8"TYPE="swap"
[root@station ~]# mkswap /dev/vdb2
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=fb1c1a9f-c380-43c3-bb6a-afbf8105cfa8
[root@station ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1"TYPE="xfs"
/dev/vdb1: UUID="2b215655-7b6c-4f89-a685-07ff48ea6dc8"TYPE="swap"
/dev/vdb2: UUID="fb1c1a9f-c380-43c3-bb6a-afbf8105cfa8"TYPE="swap"
[root@station ~]# swapon -a /dev/vdb2 ##激活vdb2
[root@station ~]# swapon -s ##查看是否激活
Filename Type Size Used Priority
/dev/vdb1 partition 4194300 0 -1
/dev/vdb2 partition 1048572 0 -2
[root@station ~]# swapoff /dev/vdb2 ##關閉vdb2
[root@station ~]# swapon -a /dev/vdb2 -p 1 (臨時)##激活同時優先級爲1
[root@station ~]# swapon -s ##查看是否激活
Filename Type Size Used Priority
/dev/vdb1 partition 4194300 0 -1
/dev/vdb2 partition 1048572 0 1
[root@station ~]# vim /etc/fstab (永久更改優先級)
[root@station ~]# swapon -s
Filename Type Size Used Priority
/dev/vdb1 partition 4194300 0 -1
/dev/vdb2 partition 1048572 0 1
###磁盤分區的刪除###
[root@station ~]# swapon -s ##查看激活的設備
Filename Type Size Used Priority
/dev/vdb1 partition 4194300 0 -1
/dev/vdb2 partition 1048572 0 1
[root@station ~]# swapoff /dev/vdb{1,2} ##關閉已經激活的設備
[root@station ~]# 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): 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: 0x193165fb
Device Boot Start End Blocks Id System
/dev/vdb1 2048 8390655 4194304 82 Linux swap / Solaris
/dev/vdb2 8390656 10487807 1048576 82 Linux swap / Solaris
Command (m for help): d ###刪除
Partition number (1,2, default 2): 1
Partition 1 is deleted
Command (m for help): d
Selected partition 2
Partition 2 is deleted
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: 0x193165fb
Device Boot Start End Blocks Id System
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@station ~]# partprobe ##同步分區表
[root@station ~]# cat /proc/partitions ##查看存在分區
major minor #blocks name
253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
###非交互式創建分區####
[root@station ~]# vim fdisk.sh ##寫自動劃分腳本
[root@station ~]# chmod +x fdisk.sh ##加執行權限
[root@station ~]# ./fdisk.sh /dev/vdb p +100M ##劃分大小爲100M的分區
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): Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): Partition number (3,4, default 3): First sector(3123200-20971519, default 3123200): Using default value 3123200
Last sector, +sectors or +size{K,M,G} (3123200-20971519, default 20971519):Partition 3 of type Linux and of size 100 MiB is set
Command (m for help): The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
###磁盤配額#####
[root@station ~]# 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
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):+500M
Partition 1 of type Linux and of size 500 MiB is set
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 orresource 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@station ~]# mkdir /pub/
[root@station ~]# mount /dev/vdb1 /pub/
[root@station ~]# su - westos
Last login: Sat Apr 22 01:57:03 EDT 2017 on pts/1
[westos@station ~]$ dd if=/dev/zero of=/pub/file bs=1M count=1000 ##從/dev/zero劃分大小爲1G的到/pub/file
dd: error writing ‘/pub/file’: No space left on device
472+0 records in
471+0 records out
494383104 bytes (494 MB) copied, 2.02753 s, 244 MB/s
[westos@station ~]$ dd if=/dev/zero of=/pub/file bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 1.47655 s, 71.0 MB/s
[westos@station ~]$ exit
logout
[root@station ~]# umount /pub/
[root@station ~]# mount -o usrquota,grpquota /dev/vdb1 /pub/ ##磁盤參數(-o)去掛載<用戶和組>
[root@station ~]# quotaon -ugv /dev/vdb1 ##激活參數(ugv用戶,組,顯示激活過程)
quotaon: Enforcing group quota already on /dev/vdb1
quotaon: Enforcing user quota already on /dev/vdb1
[root@station ~]# edquota -u westos ##查看文件配置內容(設定限額)
[root@station ~]# ls -l /pub/
total 102400
-rwxrwxrwx. 1 root root 104857600 Apr 22 02:04 file
[root@station ~]# edquota -u westos
[root@station ~]# ls /pub/
file
[root@station ~]# su - westos
Last login: Sat Apr 22 02:03:58 EDT 2017 on pts/1
[westos@station ~]$ 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.216038 s, 485 MB/s
[westos@station ~]$ exit
logout
[root@station ~]# edquota -u westos ##查看文件配額的顯示
###磁盤並列(raid)####
[root@station ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3241352 7232548 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 472 942188 1% /dev/shm
tmpfs 942660 17036 925624 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
[root@station ~]# fdisk /dev/vdb
###同上
[root@station ~]# partprobe ##同步分區表
[root@station ~]# mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3} ##創建原本不存在的設備,用兩塊空閒一塊創建raid1
mdadm: Note: this array has metadata at the start and
may not be suitable as a bootdevice. If you plan to
store '/boot' on this device pleaseensure that
your boot-loader understands md/v1.xmetadata, or use
--metadata=0.90
Continue creating array? yes
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@station ~]# mkfs.xfs /dev/md0 ##格式化
meta-data=/dev/md0 isize=256 agcount=4,agsize=31980 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=127920, 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@station ~]# mount /dev/md0 /mnt ##掛載
[root@station ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3241360 7232540 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 472 942188 1% /dev/shm
tmpfs 942660 17084 925576 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/md0 508268 25744 482524 6% /mnt
[root@station ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 3.1G 6.9G 31% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 472K 921M 1% /dev/shm
tmpfs 921M 17M 904M 2% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/md0 497M 26M 472M 6% /mnt
[root@station ~]# mdadm -D /dev/md0 ##查看設備信息
ide
[root@station ~]# mdadm -f /dev/md0 /dev/vdb2 ##手動使使第二塊壞掉
mdadm: set /dev/vdb2 faulty in /dev/md0
[root@station ~]# mdadm -r /dev/md0 /dev/vdb2 ##刪除第二塊
mdadm: hot removed /dev/vdb2 from /dev/md0
[root@station ~]# mdadm -D /dev/md0 ##查看設備信息
/dev/md0:
Version : 1.2
Creation Time : Sat Apr 22 02:45:232017
Raid Level : raid1
Array Size : 511680 (499.77 MiB523.96 MB)
Used Dev Size : 511680 (499.77 MiB523.96 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock ispersistent
Update Time : Sat Apr 22 02:55:212017
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Name : station.domain13.example.com:0 (local to hoststation.domain13.example.com)
UUID :fb08cc81:d5ba9e1d:5defa070:44de50ca
Events : 37
Number Major Minor RaidDevice State
0 253 17 0 active sync /dev/vdb1
2 253 19 1 active sync /dev/vdb3
[root@station ~]# mdadm -a /dev/md0 /dev/vdb2 ##添加新設備
mdadm: added /dev/vdb2
[root@station ~]# mdadm -D /dev/md0 /dev/vdb2 ##再次查看設備信息
/dev/md0:
Version : 1.2
Creation Time : Sat Apr 22 02:45:232017
Raid Level : raid1
Array Size : 511680 (499.77 MiB523.96 MB)
Used Dev Size : 511680 (499.77 MiB523.96 MB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock ispersistent
Update Time : Sat Apr 22 02:55:412017
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Name :station.domain13.example.com:0 (local tohost station.domain13.example.com)
UUID :fb08cc81:d5ba9e1d:5defa070:44de50ca
Events : 38
Number Major Minor RaidDevice State
0 253 17 0 active sync /dev/vdb1
2 253 19 1 active sync /dev/vdb3
3 253 18 - spare /dev/vdb2
mdadm: /dev/vdb2 does not appear to be an md deviceui
實驗監控命令:
watch -n 1 cat /proc/mdstat
watch -n 1 'cat /proc/mdstat;echo ====;df -h'
###刪除設備###
[root@station ~]# umount /mnt ##卸載
[root@station ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3240512 7233388 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 472 942188 1% /dev/shm
tmpfs 942660 17116 925544 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
[root@station ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Sat Apr 22 02:45:232017
Raid Level : raid1
Array Size : 511680 (499.77 MiB523.96 MB)
Used Dev Size : 511680 (499.77 MiB523.96 MB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock ispersistent
Update Time : Sat Apr 22 03:04:362017
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Name : station.domain13.example.com:0 (local to hoststation.domain13.example.com)
UUID :fb08cc81:d5ba9e1d:5defa070:44de50ca
Events : 38
Number Major Minor RaidDevice State
0 253 17 0 active sync /dev/vdb1
2 253 19 1 active sync /dev/vdb3
3 253 18 - spare /dev/vdb2
[root@station ~]# mdadm -S /dev/md0 ###中止設備
mdadm: stopped /dev/md0
[root@station ~]# fdisk /dev/vdb ##新建磁盤設備
同上
[root@station ~]# partprobe ##同步分區表
this