1.自动挂载磁盘
添加、选中磁盘,点继续,一路回车,完成了点确定。
重启虚拟机。
可以看到有sdb存在,这个是新添加的硬盘。
[root@localhost ~]# fdisk /dev/sdb #对硬盘进行分区编辑
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xc4d39f99.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p #查看分区,目前没有,所以为空
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc4d39f99
Device Boot Start End Blocks Id System
Command (m for help): n #创建磁盘
Command action
e extended
p primary partition (1-4)
P #创建主分区
Partition number (1-4): 1 #主分区编号为1
First cylinder (1-130, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): +1G #设置大小
Value out of range.
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130
Command (m for help): p #查看分区
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc4d39f99
Device Boot Start End Blocks Id System
/dev/sdb1 1 130 1044193+ 83 Linux
Command (m for help): w #保存退出
fdisk里的选项:
M:查看操作指令的帮助信息
p:列表查看分区信息
n: 新建分区
d: 删除分区
t: 变更分区类型
w:保存分区设置并退出
q:放弃分区设置并退出
L:查看磁盘的格式
[root@localhost ~]# mkfs.ext4 /dev/sdb
mke2fs 1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mkdir /aaa
[root@localhost ~]# mount /dev/sdb /aaa
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 19G 1001M 17G 6% /
tmpfs 242M 0 242M 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/sdb 1008M 34M 924M 4% /aaa
出现了挂载。
[root@localhost ~]# vi /etc/fstab 末尾添加以下:
/dev/sdb /aaa ext4 defaults 0 0
关机重启,就实现了自动挂载。
改变inode数:
1。卸载文件系统
umount /dav/sda6
2。建立文件系统,指定inode节点数
mkfs.ext3 /dev/sda6 -N 18276352
3。修改fstab文件
vi /etc/fstab
/dev/sda6 /data0 ext3 defaults 0 0
4,挂载文件系统
mount -a
4。查看修改后的inode参数
dumpe2fs -h /dev/sda6 | grep node #显示磁盘状态
创建swap分区:
目标:
挂载了一个4G的磁盘,1G作为主分区,剩下的作为扩展分区,在扩展分区上1G作为swap分区,2G作为逻辑分区。
[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x3d6121f6.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n #创建
Command action
e extended
p primary partition (1-4)
P #主分区
Partition number (1-4): 1 #第一个主分区
First cylinder (1-522, default 1): 1 #第一位置开始划分
Last cylinder, +cylinders or +size{K,M,G} (1-522, default 522): +1G #大小是1G
Command (m for help): n #创建
Command action
e extended
p primary partition (1-4)
e #扩展分区
Partition number (1-4): 4 #第四个位置做为扩展分区
First cylinder (133-522, default 133): #回车,默认133位置开始
Using default value 133
Last cylinder, +cylinders or +size{K,M,G} (133-522, default 522): #回车,默认全部
Using default value 522
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l #逻辑分区
First cylinder (133-522, default 133): #默认当前位置开始
Using default value 133
Last cylinder, +cylinders or +size{K,M,G} (133-522, default 522): +1G #划分1G
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l #逻辑分区
First cylinder (265-522, default 265): #回车,默认当前位置
Using default value 265
Last cylinder, +cylinders or +size{K,M,G} (265-522, default 522): #回车,默认剩下的
Using default value 522
Command (m for help): p #查看分区
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x3d6121f6
Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb4 133 522 3132675 5 Extended
/dev/sdb5 133 264 1060258+ 83 Linux
/dev/sdb6 265 522 2072353+ 83 Linux
Command (m for help): t #转化格式
Partition number (1-6): 5 #选择第五个分区
Hex code (type L to list codes): 82 #要转化的格式
Changed system type of partition 5 to 82 (Linux swap / Solaris)
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xec6feb06
Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb4 133 522 3132675 5 Extended
/dev/sdb5 133 264 1060258+ 82 Linux swap / Solaris
/dev/sdb6 265 522 2072353+ 83 Linux
Command (m for help): L #查看磁盘都有哪些格式
Command (m for help): w #保存退出
[root@localhost ~]# mkfs.ext3 -N 4096 /dev/sdb1 #指定inode数格式化
[root@localhost ~]# dumpe2fs -h /dev/sdb1|grep Inode #查看Inode大小和数量
dumpe2fs 1.41.12 (17-May-2010)
Inode count: 4176
Inodes per group: 464
Inode blocks per group: 29
Inode size: 256
[root@localhost ~]# mkswap /dev/sdb5 #格式化swap分区
Setting up swapspace version 1, size = 1060252 KiB
no label, UUID=1119d45f-a6be-40f9-b67e-e0bc403af60c
[root@cnode6_8 ~]# partx -a /dev/sdb //通知内核新增分区
[root@localhost ~]# top #看swap分区大小
[root@localhost ~]# swapon /dev/sdb5 #开启swap分区
[root@localhost ~]# top #再次看swap大小
也可以用 meminfo里面的数据查看swap
[root@localhost ~]# cat /proc/meminfo
或者用swapon -s 查看
[root@localhost ~]# mkfs.ext4 -N 1000 /dev/sdb6
[root@localhost ~]# dumpe2fs -h /dev/sdb6
[root@localhost ~]# mount /dev/sdb6 /aaa
[root@localhost ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/VolGroup-lv_root 1215840 21430 1194410 2% /
tmpfs 61778 1 61777 1% /dev/shm
/dev/sda1 128016 38 127978 1% /boot
/dev/sdb6 1024 11 1013 2% /aaa
[root@localhost aaa]# touch a{1..1014}
touch: cannot touch `a1014': No space left on device #Inode数已经占满!!!
[root@localhost aaa]# ls
a1 a144 a201 a26 a317 a375 a432 a490 a548 a605 a663 a720 a779 a836 a894 a951
a10 a145 a202 a260 a318 a376 a433 a491 a549 a606 a664 a721 a78 a837 a895 a952
a100 a146 a203 a261 a319 a377 a434 a492 a55 a607 a665 a722 a780 a838 a896 a953
1. LVM磁盘阵列
目标:创建一个磁盘阵列,里面有两块物理卷,一块逻辑卷组,可以给逻辑卷动态扩容。
卷组名:gdoo,卷名是doo。
新添加两块磁盘,大小都是5G:
[root@localhost ~]# fdisk -l |egrep "sdb|sdc"
Disk /dev/sdb: 5368 MB, 5368709120 bytes
Disk /dev/sdc: 5368 MB, 5368709120 bytes
用fdisk命令将sdb和sdc创建,格式都改为8e
[root@localhost ~]# fdisk -l |egrep "sdb|sdc"
Disk /dev/sdb: 5368 MB, 5368709120 bytes
/dev/sdb1 1 652 5237158+ 8e Linux LVM
Disk /dev/sdc: 5368 MB, 5368709120 bytes
/dev/sdc1 1 652 5237158+ 8e Linux LVM
[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdc1 #创建物理卷
dev_is_mpath: failed to get device for 8:17
Physical volume "/dev/sdb1" successfully created
dev_is_mpath: failed to get device for 8:33
Physical volume "/dev/sdc1" successfully created
[root@localhost ~]# vgcreate gdoo /dev/sdb1 /dev/sdc1 #创建逻辑卷组
Volume group "gdoo" successfully created
[root@localhost ~]# lvcreate -L 6G -n doo gdoo #向卷组gdoo里面抽取6G空间作为逻辑卷doo的大小。
Logical volume "doo" created
[root@localhost ~]# mkfs.ext3 /dev/gdoo/doo #格式化逻辑卷doo
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
[root@localhost ~]# mount /dev/gdoo/doo /aaa
[root@localhost ~]# df -hT #目前是6G
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root ext4 19G 1001M 17G 6% /
tmpfs tmpfs 242M 0 242M 0% /dev/shm
/dev/sda1 ext4 485M 33M 427M 8% /boot
/dev/mapper/gdoo-doo ext3 6.0G 141M 5.5G 3% /aaa
[root@localhost ~]# lvextend -L +3G /dev/gdoo//doo #逻辑卷doo扩容
Extending logical volume doo to 9.00 GiB
Logical volume doo successfully resized
[root@localhost ~]# resize2fs /dev/gdoo/doo #让系统识别文件系统大小
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/gdoo/doo is mounted on /aaa; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/gdoo/doo to 2359296 (4k) blocks.
The filesystem on /dev/gdoo/doo is now 2359296 blocks long.
[root@localhost ~]# df -hT #此时逻辑卷doo大小变为9G了
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root ext4 19G 1001M 17G 6% /
tmpfs tmpfs 242M 0 242M 0% /dev/shm
/dev/sda1 ext4 485M 33M 427M 8% /boot
/dev/mapper/gdoo-doo ext3 8.9G 142M 8.3G 2% /aaa
- 2. Read
RAID0:
RAID 0
也称为条带模式(striped),即把连续的数据分散到多个磁盘上存取,如图 1 所示。当系统有数据请求就可以被多个磁盘并行的执行,每个磁盘执行属于它自己的那部分数据请求。这种数据上的并行操作可
以充分利用总线的带宽,显著提高磁盘整体存取性能。因为读取和写入是在设备上并行完成的,读取和写入性能将会增加,这通常是运行 RAID 0 的主要原因。但 RAID 0 没有数据冗余,如果驱动器出现故障,那么将无法恢复任何数据。
RAID1:
RAID 1
RAID 1 又称为镜像(Mirroring),一个具有全冗余的模式,如图 2 所示。RAID 1 可以用于两个或 2xN 个磁盘,并使用 0 块或更多的备用磁盘,每次写数据时会同时写入镜像盘。这种阵列可靠性很高,但其有 效容量减小到总容量的一半,同时这些磁盘的大小应该相等,否则总容量只具有最小磁盘的大小。
RAID 5
在希望结合大量物理磁盘并且仍然保留一些冗余时,RAID 5 可能是最有用的 RAID 模式。RAID 5 可 以用在三块或更多的磁盘上,并使用 0 块或更多的备用磁盘。就像 RAID 4 一样,得到的 RAID5 设备的 大小是(N-1)*S。
madmd命令
-C 创建一个软RAID
-A 加载一个已存在的阵列
-D 输出指定RAID的设备详细信息
-S 停止指定的RAID设备
-l 指定级别 有:0 1 4 5 6
-n 指定阵列中活动磁盘的数目
-x 备用磁盘数
-s 扫描配置文件得到阵列缺失信息
-a 添加设备到阵列
-G 改变阵列的大小
-c 设定阵列的chunk大小
[root@localhost yum.repos.d]# fdisk -l |grep "sd" #把sdb sdc sdd sde磁盘变为fd格式,步骤省略
Disk /dev/sda: 21.5 GB, 21474836480 bytes
/dev/sda1 * 1 64 512000 83 Linux
/dev/sda2 64 2611 20458496 8e Linux LVM
Disk /dev/sdb: 2147 MB, 2147483648 bytes
/dev/sdb1 1 261 2096451 fd Linux raid autodetect
Disk /dev/sdc: 2147 MB, 2147483648 bytes
/dev/sdc1 1 261 2096451 fd Linux raid autodetect
Disk /dev/sdd: 2147 MB, 2147483648 bytes
/dev/sdd1 1 261 2096451 fd Linux raid autodetect
Disk /dev/sde: 2147 MB, 2147483648 bytes
/dev/sde1 1 261 2096451 fd Linux raid autodetect
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]# mdadm -C /dev/md5 -l 5 -n 3 -x 1 -a yes /dev/sd[b-e]1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@localhost yum.repos.d]# mdadm -D /dev/md5
[root@localhost yum.repos.d]# mdadm -D -s #需要手动创建配置文件实现重启电脑自动加载
ARRAY /dev/md5 metadata=1.2 spares=1 name=localhost.localdomain:5 UUID=22761e72:5940bc19:a1711462:dd2fe398
[root@localhost yum.repos.d]# mdadm -D -s >/etc/mdadm.conf
[root@localhost yum.repos.d]# vi /etc/mdadm.conf
[root@localhost yum.repos.d]# mkfs.ext3 /dev/md5
[root@localhost yum.repos.d]# mount /dev/md5 /aaa
[root@localhost yum.repos.d]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 19G 1005M 17G 6% /
tmpfs 242M 0 242M 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/sr0 4.2G 4.2G 0 100% /media/cdrom
/dev/md5 4.0G 73M 3.7G 2% /aaa
[root@localhost yum.repos.d]# cat /proc/mdstat #查看RAID信息
[root@localhost yum.repos.d]# mdadm /dev/md5 -f /dev/sdc1 #模拟故障
mdadm: set /dev/sdc1 faulty in /dev/md5
[root@localhost yum.repos.d]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Sun Dec 4 05:24:04 2016
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Sun Dec 4 05:35:00 2016
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 1
Spare Devices : 0
[root@localhost yum.repos.d]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md5 : active raid5 sdd1[4] sde1[3] sdc1[1](F) sdb1[0]
4190208 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>
[root@localhost yum.repos.d]# mdadm /dev/md5 -r /dev/sdc1 #移除/dev/sdc1
mdadm: hot removed /dev/sdc1 from /dev/md5
[root@localhost yum.repos.d]# mdadm /dev/md5 -a /dev/sdc1 #添加好的磁盘
mdadm: added /dev/sdc1
[root@localhost yum.repos.d]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Sun Dec 4 05:24:04 2016
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Sun Dec 4 05:32:50 2016
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
[root@bogon ~]# mdadm /dev/md5 -a /dev/sdf1 #再添加一块活动磁盘
[root@bogon ~]# mdadm -G /dev/md5 -n 4 #改变阵列的大小
[root@bogon ~]# resize2fs /dev/md5 #让系统再次识别文件系统