Linux 磁盘管理
一、实验环境
1、VMware WorkStation虚拟机安装操作系统:Red Hat Enterprice Linux 5.5;
2、磁盘:除Linux系统磁盘外,挂载3块大小为1G,一块大小为2G(做LVM实验时使用),类型为SCSI的磁盘;
二、实验目标
1、了解各种磁盘阵列的的优缺点与应用环境,以及Linux下软件配置RAID的方法;
2、实现Linux下LVM(逻辑卷管理)对RAID组成的逻辑磁盘配置与应用;
3、应用Linux提供的“磁盘配额(Disk Quota)”子系统管理逻辑卷。
三、实验内容
(一)、配置软件RAID
1、检查raid工具mdadm
1-1、检查系统是否已安装mdadm工具包
[root@localhost ~]# rpm -q mdadm
mdadm-2.6.9-3.el5
1-2、如果没有安装,手动安装mdadm-2.6.9-3.el5.rpm这个包。
2、准备实验磁盘
2-1、查看磁盘:
[root@localhost ~]# fdisk -l
Disk /dev/sda: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1402 11261533+ 83 Linux
/dev/sda2 1403 1566 1317330 82 Linux swap / Solaris
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdc doesn't contain a valid partition table
Disk /dev/sdd: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdd doesn't contain a valid partition table
2-2、对磁盘/dev/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. 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)
Command (m for help): n #新建分区;
Command action
e extended
p primary partition (1-4)
p #分区类型为主分区;
Partition number (1-4): 1 #第一个分区;
First cylinder (1-130, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130):
Using default value 130 #使用全部空间(分一个区),以上两项直接回车;
Command (m for help): t #选择分区格式;
Selected partition 1
Hex code (type L to list codes): fd #选择分区格式为fd;
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): w #保存并退出。
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
2-3、磁盘/dev/sdc和/dev/sdd的分区方法与上面步骤一致。完成后,查看全部分区。
[root@localhost ~]# fdisk -l
Disk /dev/sda: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1402 11261533+ 83 Linux
/dev/sda2 1403 1566 1317330 82 Linux swap / Solaris
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 130 1044193+ fd Linux raid autodetect
Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 130 1044193+ fd Linux raid autodetect
Disk /dev/sdd: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdd1 1 130 1044193+ fd Linux raid autodetect
3、创建磁盘阵列
3-1、创建磁盘阵列RAID0
[root@localhost ~]# mdadm --create --verbose /dev/md0 --level=0 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1
mdadm: chunk size defaults to 64K
mdadm: array /dev/md0 started.
3-1-1、可以简写为[root@localhost ~]# mdadm -Cv /dev/md0 -l0 -n3 /dev/sd{b,c,d}1
3-1-2、还可以增加-c128参数,指定chunk size为128K(默认64K)
3-2、RAID1、RAID5创建过程和上面的方法相同。
4、mdadm的配置文件:mdadm不采用/etc/mdadm.conf作为主要配置文件,它可以完全不依赖该文件而不会影响阵列的正常工作。该配置文件的主要作用是方便跟踪软RAID的配置。对该配置文件进行配置是有好处的,但不是必须的。推荐对该文件进行配置。
4-1、格式:
DEVICE 参与阵列的设备
ARRAY 阵列的描述
4-2、创建mdadm.conf 配置文件
[root@localhost ~]# mdadm --detail --scan >> /etc/mdadm.conf
[root@localhost ~]# vi /etc/mdadm.conf
[root@localhost ~]# cat /etc/mdadm.conf
DEVICE /dev/sdb1 /dev/sdc1 /dev/sdd1
ARRAY /dev/md0 level=raid0 num-devices=3 metadata=0.90 UUID=75e92985:cb128e1d:a99bce53:46f65900
5、格式化磁盘阵列
5-1、格式化磁盘阵列 /dev/md0
[root@localhost ~]# mkfs.ext3 /dev/md0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
391680 inodes, 783072 blocks
39153 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.