unit2.4管理系统中的简单分区和文件系统
来源:互联网 发布:linux 查看文件夹时间 编辑:程序博客网 时间:2024/06/10 09:45
#########################unit2.4##################################################
管理系统中的简单分区和文件系统
**********简单分区和文件系统
1, 存储是每个计算机系统的基本需求。 Red Hat EnterpriseLinux 提供了一些强大的工具 , 它们能在大量的场景中管理多种类型的存储设备
2, disk 是用于管理磁盘分区的实用程序。您可以通过选择 -l选项和指定磁盘名称 ( fdisk -cul /dev/vda ) 运行该实用程序 , 以查看磁盘及其分区。您可以通过交互式地运行该实用程序 , 并选择相应的菜单选项 ( fdisk -cu /dev/vda ) 进行更改。 -c 禁用旧的 DOS 兼容模式 , -u 以扇区 ( 而不是柱面 , 已经过时 ) 的格式显示输出
¥¥¥¥¥¥一,查看可被系统识别的设备信息
查看系统设备信息
1,fdisk -l
– 显示系统中所有可以使用的设备信息
2, blkid
– 显示系统正在使用的设备 id
[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@localhost ~]# 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 0x81c63cb5.
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 (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): +100M
Partition 1 of type Linux and of size 100 MiB is set
Command (m for help): wq ##将分好的区写入磁盘中,退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# partprobe ##重新读取分区(与系统同步)
[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
¥¥¥¥¥¥三,分区创建扩展分区和逻辑分区
[root@localhost ~]# 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):
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 (3 primary, 0 extended, 1 free)
e extended
Select (default e): ##第4分区时,会默认为扩展分区
Using default response 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 ##第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): 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):
Using default value 20971519
Partition 6 of type Linux and of size 9.6 GiB is set
Command (m for help): wq ###写入分区,退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# partprobe
[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 102400 vdb5
253 22 10073088 vdb6
¥¥¥¥¥四,格式化分区设备(即创建新的文件系统)
******文件系统比较*******
1, ext4 是 Red Hat Enterprise Linux 6 的标准文件系统。它非常强大可靠 , 具有多项可以提高现代工作量处理性能的功能
2, ext2 是常用于 Linux 中的较旧的文件系统。它简单可靠 , 非常适合小型存储设备 , 但是效率低于 ext4
3,vfat 支持包括一系列相关文件系统 ( VFAT/FAT16 和FAT32 ), 这些文件系统针对较旧版本的 Microsoft Windows开发 , 在大量的系统和设备上受支持
4,xfs 在 Red Hat Enterprise Linux 7 的标准文件系统其具备数据完全性 、性能稳定、扩展性强( 18eb )、传输速率高( 7G/s )
相应的操作:
# mkfs -t ext4|xfs /dev/vda3
# blkid /dev/vda3
/dev/vda3: UUID="cffde973-ab02-4b52-a09c-2a7ee610255c"
TYPE="ext4"
# mkdir /test
向 /etc/fstab 添加一个条目 :(开机自动挂载)
UUID="cffde973-ab02-4b52-a09c-2a7ee610255c" /test [ext4|xfs] defaults
1 2
测试挂载 :
# mount /test
删除现有文件系统
1. 通过使用 umount /mountpoint 卸载文件系统。
2. 在 /etc/fstab 中删除相应条目。
3. 删除挂载点目录 : rmdir /mountpoint
实例如下:
[root@localhost ~]# mkfs.xfs /dev/vdb6 ##逻辑分区和主分区可进行格式化,二扩展分区不可以
meta-data=/dev/vdb6 isize=256 agcount=4, agsize=629568 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=2518272, 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@localhost ~]# blkid ##查看系统正使用的设备
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/vdb6: UUID="82014b39-6bbd-4465-8e40-3d91ab07cf62" TYPE="xfs"
¥¥¥¥¥¥五,格式化后进行挂载
1,临时挂载
[root@localhost ~]# mount /dev/vdb6 /mnt/ ##挂载到/mnt/
[root@localhost ~]# df ##查看正在挂载的设备
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3162832 7311068 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 140 942520 1% /dev/shm
tmpfs 942660 17080 925580 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/vdb6 10062848 32928 10029920 1% /mnt
[root@localhost ~]# umount /mnt/ ##卸载
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3162816 7311084 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 140 942520 1% /dev/shm
tmpfs 942660 17080 925580 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
2.开机自动挂载
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed May 7 01:22:57 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 / xfs defaults 1 1
/dev/vdb6 /mnt xfs defaults 0 0
##设备/dev/vdb 开机自动默认挂载到/mnt/ 不检测,不备份
3,挂载所有系统文件
[root@localhost ~]# mount -a ##挂载所有的(包括刚新建的)
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3160844 7313056 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 140 942520 1% /dev/shm
tmpfs 942660 17080 925580 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/vdb6 10062848 32928 10029920 1% /mnt
¥¥¥¥¥¥六,删除分区
1,一般的临时挂载,先卸载,然后删除分区
[root@localhost ~]# 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): d ##删除分区
Partition number (1-6, default 6):
Partition 6 is deleted
....
Command (m for help): d
Selected partition 1
Partition 1 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: 0x81c63cb5
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.
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@localhost ~]# partprobe
Error: Partition(s) 6 on /dev/vdb have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.
##分区6虽然被写入,但不能被内核识别,原因:正在被使用。
2,使用开机自动挂载的,先卸载,再删除相应的配置内容,最后删除分区
[root@localhost ~]# df 查看正在挂载的设备(/dev/vdb6被挂载到/mnt/)
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3160864 7313036 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 140 942520 1% /dev/shm
tmpfs 942660 17060 925600 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/vdb6 10062848 32928 10029920 1% /mnt
[root@localhost ~]# umount /mnt/ ##先卸载
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3160888 7313012 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 140 942520 1% /dev/shm
tmpfs 942660 17060 925600 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
[root@localhost ~]# vim /etc/fstab ##去掉开机自动挂载的配置内容
******再次删除已建的分区。
[root@localhost ~]# 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): d
No partition is defined yet!
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: 0x81c63cb5
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@localhost ~]# partprobe ##与系统同步(正常)
[root@localhost ~]# cat /proc/partitions
major minor #blocks name
253 0 10485760 vda
253 1 10484142 vda1
253 16 10485760 vdb
¥¥¥¥¥¥七,使用脚本分区以及相应挂载的目录的权限情况
1,使用脚本进行分区
[root@localhost ~]# vim fdisk.sh
[root@localhost ~]# cat fdisk.sh
#!/bin/bash
fdisk $1<<end
n
$2
$3
wq
end
[root@localhost ~]# sh fdisk.sh /dev/vdb p +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 (0 primary, 0 extended, 4 free)
e extended
Select (default 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): Partition 1 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@localhost ~]# mkfs.xfs /dev/vdb1
meta-data=/dev/vdb1 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
2,挂载的相应目录的权限
[root@localhost ~]# mkdir /pub
[root@localhost ~]# chmod 777 /pub/
[root@localhost ~]# ls -ld /pub/
drwxrwxrwx. 2 root root 6 Apr 24 08:01 /pub/
****挂载后,目录权限改变*****
[root@localhost ~]# mount /dev/vdb1 /pub/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 3.1G 7.0G 31% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 84K 921M 1% /dev/shm
tmpfs 921M 17M 904M 2% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/vdb1 97M 5.2M 92M 6% /pub
[root@localhost ~]# ls -ld /pub/
drwxr-xr-x. 2 root root 6 Apr 24 08:11 /pub/
使用*****quota****
[root@localhost ~]# useradd westos
useradd: user 'westos' already exists
[root@localhost ~]# id student
uid=1000(student) gid=1000(student) groups=1000(student),10(wheel)
[root@localhost ~]# umount /pub/
****挂载后,保持目录权限不变
[root@localhost ~]# mount -o usrquota,grpquota /dev/vdb1 /pub/
[root@localhost ~]# ls -ld /pub/
drwxrwxrwx. 2 root root 6 Apr 24 08:23 /pub/
[root@localhost ~]# quotaon -ugv /dev/vdb1###激活quota
quotaon: Enforcing group quota already on /dev/vdb1
quotaon: Enforcing user quota already on /dev/vdb1
[root@localhost ~]# edquota -u westos ##编写指定用户
[root@localhost ~]# ls -l /pub/
total 0
[root@localhost ~]# su - westos
[westos@localhost ~]$ dd if=/dev/zero of=/pub/file bs=1M count=201
dd: error writing ‘/pub/file’: No space left on device
92+0 records in
91+0 records out
95920128 bytes (96 MB) copied, 0.115362 s, 831 MB/s
[westos@localhost ~]$ du -sh /pub/file ##查看总量
92M /pub/file
[westos@localhost ~]$ dd if=/dev/zero of=/pub/file bs=1M count=10000
dd: error writing ‘/pub/file’: No space left on device
92+0 records in
91+0 records out
95920128 bytes (96 MB) copied, 0.118412 s, 810 MB/s
[westos@localhost ~]$ df
df: ‘/run/user/0/gvfs’: Permission denied
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3161856 7312044 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17020 925640 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/vdb1 98988 98968 20 100% /pub
[westos@localhost ~]$ su -
Password:
Last login: Mon Apr 24 08:00:00 EDT 2017 from 172.25.254.90 on pts/0
[root@localhost ~]# edquota -u westos
(如图一)
¥¥¥¥¥¥八,关于raid
1,创建raid
[root@localhost ~]# 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):
Using default response 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): +1G
Partition 1 of type Linux and of size 1 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-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): fd ##创建Linux raid auto
Changed type of partition 'Linux' to 'Linux raid autodetect'
.............
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: 0x81c63cb5
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
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# partprobe
2,raid的使用
[root@localhost ~]# mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3} ##创建/dev/md0下的三个设备(/dev/vdb{1..3}),2个使用,1个备用。
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
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@localhost ~]# mkfs.xfs /dev/md0 ##格式化md0
meta-data=/dev/md0 isize=256 agcount=4, agsize=65500 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=262000, 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/md0 /mnt/
[root@localhost ~]# df -h
文件系统 容量 已用 可用已用% 挂载点
/dev/vda1 10G 3.1G 7.0G 31% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 84K 921M 1% /dev/shm
tmpfs 921M 17M 904M 2% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/md0 1021M 33M 988M 4% /mnt
[root@localhost ~]# mdadm -D /dev/md0 ##查看/dev/md0以及其相应的设备状态
/dev/md0:
Version : 1.2
Creation Time : Mon Apr 24 09:30:54 2017
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
.................
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 ##/dev/vdb3闲置(备用)
[root@localhost ~]# mdadm -f /dev/md0 /dev/vdb2 ###破坏掉/dev/vdb2
mdadm: set /dev/vdb2 faulty in /dev/md0
[root@localhost ~]# mdadm -r /dev/md0 /dev/vdb2 ##删除/dev/vdb2
mdadm: hot removed /dev/vdb2 from /dev/md0
[root@localhost ~]# mdadm -D /dev/md0 ##再次查看/dev/md0
/dev/md0:
Version : 1.2
Creation Time : Mon Apr 24 09:30:54 2017
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
..................
Number Major Minor RaidDevice State
0 253 17 0 active sync /dev/vdb1
2 253 19 1 active sync /dev/vdb3
[root@localhost ~]# mdadm -a /dev/md0 /dev/vdb2 ##添加/dev/vdb2
mdadm: added /dev/vdb2
[root@localhost ~]# mdadm -D /dev/md0 ##再次查看
/dev/md0:
Version : 1.2
Creation Time : Mon Apr 24 09:30:54 2017
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
..................
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@localhost ~]# mdadm -S /dev/md0 ###停止/dev/md0,提示有被挂载的
mdadm: Cannot get exclusive access to /dev/md0:Perhaps a running process, mounted filesystem or active volume group?
**查看挂载目录****
[root@localhost ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/vda1 10473900 3161792 7312108 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17064 925596 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/md0 1044588 32928 1011660 4% /mnt
[root@localhost ~]# umount /mnt/ ##卸载
[root@localhost ~]# mdadm -S /dev/md0 ##停止/dev/md0成功
mdadm: stopped /dev/md0
以上的监控命令:
[root@localhost ~]# watch -n 1 cat /proc/mdstat
[root@localhost ~]# watch -n 1 'cat /proc/mdstat;echo =====;df -h'
¥¥¥¥¥¥九,swap 交换分区
1, 换空间或交换区是磁盘驱动器上的空间 , 用作当前未使用部分内存的溢出。这样 , 系统就能在主内存中留出空间用于储存当前正在处理的数据 , 并在系统面临主内存空间不足的风险时提供应急溢出
www.westos.org管理交换分区
2, 使用 fdisk 创建新分区。此外 , 在用 fdisk 保存更改之前 , 将分区类型更改为 “ 0x82 LinuxSwap”
3, mkswap /dev/vdaN 会准备好将分区用作交换区
4, blkid /dev/vdaN 将确定 UUID
5,将新交换空间添加到 /etc/fstab :UUID=uuid swap swap defaults 0 0
6,swapon -a 将激活新交换区
7,swapon -s 将显示当前交换区的状态
8, swapoff /dev/vdaN 将停用该特定交换区
****实例如下:
[root@localhost ~]# fdisk /dev/vdb ###创建类型为82的Swap分区
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):
Using default response 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): +1G
Partition 1 of type Linux and of size 1 GiB is set
Command (m for help): t
Selected partitvolumeion 1
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'
..............................
Device Boot Start End Blocks Id System
/dev/vdb1 2048 2099199 1048576 82 Linux swap / Solaris
/dev/vdb2 2099200 4196351 1048576 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@localhost ~]# partprobe
[root@localhost ~]# mkfs.xfs /dev/vdb -f
meta-data=/dev/vdb isize=256 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=2621440, 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@localhost ~]# mkswap /dev/vdb1 ##准备好将分区用作交换区
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=c5736adc-b4bd-4aa5-a720-99512aab134b
[root@localhost ~]# mkswap /dev/vdb2
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=84e3d098-834c-45c7-802c-57af110d0808
[root@localhost ~]# swapon -a /dev/vdb1 ##激活新交换区
[root@localhost ~]# swapon -a /dev/vdb2
[root@localhost ~]# swapon -s ##查看交换区的状态
Filename Type Size Used Priority
/dev/vdb1 partition 1048572 0 -1
/dev/vdb2 partition 1048572 0 -2
*****改变优先级******
[root@localhost ~]# swapoff /dev/vdb2 ##停用交换区
[root@localhost ~]# swapon -s
Filename Type Size Used Priority
/dev/vdb1 partition 1048572 0 -1
[root@localhost ~]# man swapon
[root@localhost ~]# swapon -a /dev/vdb2 -p 1 ##将交换区/dev/vdb2的优先级改为1
[root@localhost ~]# swapon -s
Filename Type Size Used Priority
/dev/vdb1 partition 1048572 0 -1
/dev/vdb2 partition 1048572 0 1
*****修改配置文件,开机自动改变优先级*****
[root@localhost ~]# swapoff /dev/vdb1
[root@localhost ~]# swapoff /dev/vdb2
[root@localhost ~]# swapon -s
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# swapon -a
[root@localhost ~]# swapon -s
Filename Type Size Used Priority
/dev/vdb1 partition 1048572 0 -1
/dev/vdb2 partition 1048572 0 1
******配置文件内容,如下:
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed May 7 01:22:57 2014
.....................
UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 / xfs defaults 1 1
/dev/vdb1 swap swap defaults 0 0
/dev/vdb2 swap swap defaults,pri=1 0 0
¥¥¥¥¥¥¥¥十,磁盘加密保护
1,LUKS ( Linux 统一密钥设置 ) 是标准的设备加密格式
2, LUKS 可以对分区或卷进行加密
3, 必须首先对加密的卷进行解密 , 才能挂载其中的文件系统
www.westos.org创建新加密的卷
4, 使用 fdisk 创建新分区
5, cryptsetup luksFormat /dev/vdaN 可对新分区进行加密 ,并设置解密密码
6,您输入正确的解密密码之后 , cryptsetup luksOpen /dev/vdaN name 会将加密的卷 /dev/vdaN 解锁为/dev/mapper/name
7, 解密的卷上创建 xfs 文件系统 : mkfs -t xfs /dev/mapper/name
8,创建目录挂载点 , 并挂载文件系统 : mkdir /secret
– mount /dev/mapper/name /secret
9, 完成之后 , umount /dev/mapper/name 并运行cryptsetup luksClose name 以锁定加密的卷
*****实例如下:*****
[root@localhost ~]# cryptsetup luksFormat /dev/vdb1 ##对新分区进行加密,并设置解密密码
WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.
Are you sure? (Type uppercase yes): YES
Enter passphrase:
Verify passphrase:
[root@localhost ~]# cryptsetup open /dev/vdb1 westos ##打开加密的设备,并且打开后为westos,输入密码。
Enter passphrase for /dev/vdb1:
[root@localhost ~]# ll /dev/mapper/westos ##打开后与原来的为同一个指向内容。
lrwxrwxrwx. 1 root root 7 Apr 25 08:19 /dev/mapper/westos -> ../dm-0
[root@localhost ~]# mkfs.xfs /dev/mapper/westos
meta-data=/dev/mapper/westos isize=256 agcount=4, agsize=31872 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=127488, 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/mapper/westos /mnt/ ##挂载打开后的westos
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
[root@localhost mnt]# touch file{1..10}
[root@localhost mnt]# cd
[root@localhost ~]# umount /mnt/
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
[root@localhost mnt]# mount /dev/mapper/westos /mnt/
[root@localhost mnt]# umount /mnt/
[root@localhost mnt]# ll /dev/mapper/
total 0
crw-------. 1 root root 10, 236 Apr 25 05:24 control
lrwxrwxrwx. 1 root root 7 Apr 25 08:20 westos -> ../dm-0
[root@localhost mnt]# cryptsetup close westos ##锁定加密的卷
[root@localhost mnt]# ll /dev/mapper/
total 0
crw-------. 1 root root 10, 236 Apr 25 05:24 control
[root@localhost mnt]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3187488 7286412 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17056 925604 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
[root@localhost mnt]# mount /dev/vdb1 /mnt/ ##被加密的设备不能直接被挂载
mount: unknown filesystem type 'crypto_LUKS'
[root@localhost mnt]# cryptsetup open /dev/vdb1 westos
Enter passphrase for /dev/vdb1:
[root@localhost mnt]# mount /dev/mapper/westos /mnt/
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
[root@localhost mnt]# vim /etc/fstab
[root@localhost mnt]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed May 7 01:22:57 2014
....................................
UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 / xfs defaults 1 1
/dev/mapper/westos /mnt xfs defaults 0 0
[root@localhost mnt]# vim /etc/crypttab ##编写配置文件,开机后自动解密
[root@localhost mnt]# cat /etc/crypttab ##(内容如下)
westos /dev/vdb1 /root/diskpass
[root@localhost mnt]# cd
[root@localhost ~]# ll
total 16
-rw-------. 1 root root 8619 May 6 2014 anaconda-ks.cfg
drwxr-xr-x. 2 root root 6 Apr 21 01:53 Desktop
drwxr-xr-x. 2 root root 6 Apr 21 01:53 Documents
drwxr-xr-x. 2 root root 6 Apr 21 01:53 Downloads
-rw-r--r--. 1 root root 45 Apr 24 08:08 fdisk.sh
drwxr-xr-x. 2 root root 6 Apr 21 01:53 Music
drwxr-xr-x. 2 root root 6 Apr 21 01:53 Pictures
drwxr-xr-x. 2 root root 6 Apr 21 01:53 Public
drwxr-xr-x. 2 root root 6 Apr 21 01:53 Templates
drwxr-xr-x. 2 root root 6 Apr 21 01:53 Videos
[root@localhost ~]# vim /root/diskpass ##密码写进此文件中
[root@localhost ~]# chmod 600 /root/diskpass ##改变权限(不让自己以外的人看到密码)
[root@localhost ~]# cryptsetup luksAddKey /dev/vdb1 /root/diskpass ##给到/root/diskpass的密码
Enter any passphrase:
[root@localhost ~]# vim /etc/resolv.conf
[root@localhost ~]# reboot ##重启查看。
Connection to 172.25.254.135 closed by remote host.
Connection to 172.25.254.135 closed.
[root@localhost ~]# df ##自动挂载到/mnt
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3187984 7285916 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 84 942576 1% /dev/shm
tmpfs 942660 17032 925628 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/mapper/westos 506540 25656 480884 6% /mnt
- unit2.4管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- 第四 管理系统中的简单分区和文件系统
- unit4~~管理系统中的简单分区和文件系统
- RHEL-RH134-UNIT4--管理系统中的简单分区和文件系统
- 管理系统简单的分区和文件系统
- liunx初级学习之管理系统中的简单分区和文件系统2-4
- Linux--RH134---unit 4 管理系统中的简单分区和文件系统
- 系统中的简单分区和文件系统
- Linux高级管理之管理系统中的简单分区和文件系统
- Linux运维笔记----管理系统中的简单分区和文件系统
- Linux学习第四单元-管理系统中的简单分区和文件系统
- Linux运维笔记-文档总结-管理系统中的简单分区和文件系统
- 管理系统分区及文件系统
- 斗地主AI算法——第三章の数据处理
- ibatis日志输出配置
- UICollectionView 适配 iPhone 7 Plus
- 信号
- Nutch爬去目录内容
- unit2.4管理系统中的简单分区和文件系统
- [2017][04][26]期中考分析
- 博客将搬家到博客园
- Bootstrap 常用知识点汇集
- linux基础swap自动创建脚本
- Spring中jdbcTemplate用法
- html5基础标签整理
- CSS3动画实现背景滚动
- AndroidStudio gradle配置