Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2477664
  • 博文数量: 225
  • 博客积分: 11622
  • 博客等级: 上将
  • 技术积分: 7358
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-18 10:05
个人简介

我们的生活是多么美好呀!!!!

文章存档

2013年(2)

2012年(9)

2011年(59)

2010年(8)

2009年(35)

2008年(112)

分类: LINUX

2009-06-01 11:12:13

为新添加的硬盘分区和格式化
    [root@llk726 dev]# fdisk /dev/sdb
    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): 1
    Last cylinder or +size or +sizeM or +sizeK (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
    Device Boot Start End Blocks Id System
    /dev/sdb1 1 130 1044193+ 83 Linux
    Command (m for help): t (更改ID号)
    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): p
    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
    Command (m for help): w(保存推出)
    The partition table has been altered!
    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@localhost ~]# mkfs -t ext3 /dev/sdb1
    mke2fs 1.35 (28-Feb-2004)
    max_blocks 267313152, rsv_groups = 8158, rsv_gdb = 63
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    130560 inodes, 261048 blocks
    13052 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
    16320 inodes per group
    Superblock backups stored on blocks:
    32768, 98304, 163840, 229376
    Writing inode tables: done
    inode.i_blocks = 2528, i_size = 4243456
    Creating journal (4096 blocks): done
    Writing superblocks and filesystem accounting information: done
    This filesystem will be automatically checked every 30 mounts or
    180 days, whichever comes first. Use tune2fs -c or -i to override.
    其余硬盘进行相同处理

    查看硬盘分区情况
    [root@llk726 dev]# fdisk -l
    Disk /dev/sda: 8589 MB, 8589934592 bytes
    255 heads, 63 sectors/track, 1044 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Device Boot Start End Blocks Id System
    /dev/sda1 * 1 13 104391 83 Linux
    /dev/sda2 14 395 3068415 83 Linux
    /dev/sda3 396 446 409657+ 82 Linux swap / Solaris
    /dev/sda4 447 1044 4803435 5 Extended
    /dev/sda5 447 1044 4803403+ 83 Linux
    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
    Disk /dev/sde: 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/sde1 1 130 1044193+ fd Linux raid autodetect
    Disk /dev/sdf: 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/sdf1 1 130 1044193+ fd Linux raid autodetect

    创建RAID 5
    [root@llk726 dev]# mdadm -Cv /dev/md0 -l5 -n4 -x1 -c128 /dev/sd[b,c,d,e,f]1
    mdadm: layout defaults to left-symmetric
    mdadm: /dev/sdb1 appears to contain an ext2fs file system
    size=1044192K mtime=Thu Jan 1 08:00:00 1970
    mdadm: /dev/sdc1 appears to contain an ext2fs file system
    size=1044192K mtime=Thu Jan 1 08:00:00 1970
    mdadm: /dev/sdd1 appears to contain an ext2fs file system
    size=1044192K mtime=Thu Jan 1 08:00:00 1970
    mdadm: /dev/sde1 appears to contain an ext2fs file system
    size=1044192K mtime=Thu Jan 1 08:00:00 1970
    mdadm: /dev/sdf1 appears to contain an ext2fs file system
    size=1044192K mtime=Thu Jan 1 08:00:00 1970
    mdadm: size set to 1044096K
    Continue creating array?
    Continue creating array? (y/n) y
    mdadm: array /dev/md0 started.
    -C”指创建一个新的阵列;“/dev/md0”表示阵列设备名称;“-l5”表示设置阵列模式,可以选择0、1、4、 5、6,它们分别对应于RAID0、RAID1、RAID4、RAID5、RAID6,这里设为RAID5模式;“-n3”指设置阵列中活动设备的数目,该数目加上备用设备的数目应等于阵列中的总设备数; “-x1”设置阵列中备份设备的数目,当前阵列中含有1个备份设备;“-c128”指设置块的尺寸为128KB,缺省为64KB;“/dev/sd[b, c,d,e,f]1”指当前阵列中包含的所有设备标识符,也可以分开来写,中间用空格分开,其中最后一个为备份设备。

    以上做完如果重启机器,他的raid 不能保存,需要手工维护/etc/mdadm.conf文件
    [root@llk726 etc]# echo DEVICE /dev/hdb1 /dev/hdc1 /dev/hdd1 /dev/hde1 /dev/hdf1> /etc/mdadm.conf
    [root@llk726 etc]# mdadm --detail -scan >> /etc/mdadm.conf

    创建文件系统并挂接
    RAID5已经启动并处于运行状态,现在要做的就是在其上创建一个文件系统,这里使用mkfs命令,文件系统类型为ext3。命令如下:
    # mkfs -t ext3 /dev/md0
    当新的文件系统生成之后,就可以将/dev/md0挂接到指定的目录了。命令如下:
    # mount -t ext3 /dev/md0 /home/raid5
    为了让系统在启动时自动将/dev/md0挂接到/home/raid5,还需要修改/etc/fstab文件,添加如下内容:
    /dev/md0 /home/raid5 ext3 defaults 0 0

    raid5的恢复
    将/dev/sdb1标记为已损坏的设备
    [root@llk726 etc]# mdadm -f /dev/md0 /dev/sdb1
    mdadm: set /dev/sdb1 faulty in /dev/md0
    [root@llk726 etc]# cat /proc/mdstat
    Personalities : [raid6] [raid5] [raid4]
    md0 : active raid5 sdf1[4] sde1[3] sdd1[2] sdc1[1] sdb1[5](F)
    3132288 blocks level 5, 128k chunk, algorithm 2 [4/3] [_UUU]
    [===>.................] recovery = 15.6% (164056/1044096) finish=2.1min speed=6835K/sec
    unused devices:
    等一会再查看一下,刚才作为备用的磁盘己经加到raid5中,并做好了数据同步
    [root@llk726 etc]# cat /proc/mdstat
    Personalities : [raid6] [raid5] [raid4]
    md0 : active raid5 sdf1[0] sde1[3] sdd1[2] sdc1[1] sdb1[4](F)
    3132288 blocks level 5, 128k chunk, algorithm 2 [4/4] [UUUU]
    unused devices:
   

    移除坏掉的磁盘
    [root@llk726 etc]# mdadm --remove /dev/md0 /dev/sdb1
    mdadm: hot removed /dev/sdb1
    [root@llk726 etc]# cat /proc/mdstat
    Personalities : [raid6] [raid5] [raid4]
    md0 : active raid5 sdf1[0] sde1[3] sdd1[2] sdc1[1]
    3132288 blocks level 5, 128k chunk, algorithm 2 [4/4] [UUUU]
    unused devices:
    添加一块新磁盘,作为备份用(先要进行fdisk /dev/sd*分区和格式化)
    [root@llk726 etc]# mdadm -a /dev/md0 /dev/sdb1
    mdadm: added /dev/sdb1
    [root@llk726 etc]# cat /proc/mdstat
    Personalities : [raid6] [raid5] [raid4]
    md0 : active raid5 sdb1[4](S) sdf1[0] sde1[3] sdd1[2] sdc1[1]
    3132288 blocks level 5, 128k chunk, algorithm 2 [4/4] [UUUU]
    unused devices:
    这时sdb1作为备份设备再次出现在阵列中

阅读(853) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~