Chinaunix首页 | 论坛 | 博客
  • 博客访问: 33566
  • 博文数量: 8
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 110
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-14 20:48
文章分类
文章存档

2014年(8)

我的朋友

分类: LINUX

2014-03-30 18:11:36

磁盘划分限定:
4个主分区
3个主分区(p)+1扩展分区(e)
1个扩展分区可以分多个逻辑分区(l)


===============================================================================================================


RAID 0:


[root@localhost ~]# fdisk /dev/sdb


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


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): +100M


Command (m for help): l


 0  Empty           1e  Hidden W95 FAT1 80  Old Minix       bf  Solaris        
 1  FAT12           24  NEC DOS         81  Minix / old Lin c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          82  Linux swap / So c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  83  Linux           c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     84  OS/2 hidden C:  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   85  Linux extended  da  Non-FS data    
 6  FAT16           42  SFS             86  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS       4d  QNX4.x          87  NTFS volume set de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 88  Linux plaintext df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 8e  Linux LVM       e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      93  Amoeba          e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 94  Amoeba BBT      e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            9f  BSD/OS          eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi ee  EFI GPT        
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a5  FreeBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a6  OpenBSD         f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a7  NeXTSTEP        f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a8  Darwin UFS      f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       a9  NetBSD          f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys ab  Darwin boot     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            


Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (14-130, default 14): 
Using default value 14
Last cylinder or +size or +sizeM or +sizeK (14-130, default 130): +100M


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          13      104391   83  Linux
/dev/sdb2              14          26      104422+  83  Linux
Command (m for help): 
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)


Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 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          13      104391   fd  Linux raid autodetect
/dev/sdb2              14          26      104422+  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 ~]# partprobe                   
[root@localhost ~]# mdadm -C /dev/md0 -l 0 -n 2 /dev/sdb1 /dev/sdb2       //将新建分区组成RAID0
mdadm: array /dev/md0 started.             (raid0)
[root@localhost ~]# cat /proc/mdstat 
Personalities : [raid0] 
md0 : active raid0 sdb2[1] sdb1[0]
      208640 blocks 64k chunks
      
unused devices:
[root@localhost ~]# mke2fs -j /dev/md0  (格式化)
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
52208 inodes, 208640 blocks
10432 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
26 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729, 204801


Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done


This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


[root@localhost ~]# mkdir /raiddata
[root@localhost ~]# ls /raiddata/
[root@localhost ~]# ls -l /raiddata/
鎬昏? 0
[root@localhost ~]# mount /dev/md0 /raiddata/  挂载
[root@localhost ~]# ls -l /raiddata/
鎬昏? 12
drwx------ 2 root root 12288 02-06 23:09 lost+found
[root@localhost ~]# df -h
/dev/sda2             4.0G  2.9G  891M  77% /
/dev/sda1              99M   12M   83M  12% /boot
tmpfs                 252M     0  252M   0% /dev/shm
/dev/md0              198M  5.8M  182M   4% /raiddata
[root@localhost ~]# vi /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs  =[' defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP-sda3         swap                    swap    defaults        0 0
/dev/md0               /raiddata                     ext3      defaults        1 2
~
~
~
~
"/etc/fstab" 9L, 609C written
[root@localhost ~]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/md0 on /raiddata type ext3 (rw)
[root@localhost ~]# reboot


Broadcast message from root (pts/1) (Mon Feb  6 23:14:07 2012):


The system is going down for reboot NOW!


[root@localhost ~]# mdadm /dev/md0 -f /dev/sdb2  
[root@localhost ~]# mdadm /dev/md0 -r /dev/sdb2   
更换硬盘
恢复数据:
[root@localhost ~]# mdadm /dev/md0 -a /dev/sdb2


=================================================================================================================
RAID5:至少需要三个磁盘。。。。
实验环境:1个系统分区3个工作分区1个备用工作分区 一共5个分区
[root@localhost ~]# fdisk -l


Disk /dev/sda: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 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         541     4241160   83  Linux
/dev/sda3             542         606      522112+  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          13      104391   83  Linux


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


Disk /dev/sde: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


Disk /dev/sde doesn't contain a valid partition table


进行磁盘分区:
[root@localhost ~]# fdisk /dev/sdc
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): p


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


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): +100M


Command (m for help): p


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          13      104391   83  Linux


Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)


Command (m for help): p


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          13      104391   fd  Linux raid autodetect


Command (m for help): w
The partition table has been altered!


Calling ioctl() to re-read partition table.
Syncing disks.


依次将其他3个磁盘进行分区
。。。。。。


[root@localhost ~]# partprobe  (即可生效)
[root@localhost ~]# mdadm -C /dev/md0 -l5 -n3 -x1 /dev/sd[b-e]1    \\将新建分区组建成RAID5!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                                                          l5: RAID5 
                                                          n3: 3工作区 
                                                          x1:1备份区(热备盘)
----------------------------------------------------------------------------------------------------------------------------------------------
格式化RAID:
[root@localhost ~]# mkfs.ext3 /dev/md0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
52208 inodes, 208640 blocks
10432 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
26 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729, 204801


Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done


This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


挂载文件系统:
[root@localhost ~]# mkdir /raid5
[root@localhost ~]# mount /dev/md0 /raid5/       
[root@localhost ~]# df -h
文件系统              容量  已用 可用 已用% 挂载点
/dev/sda2             4.0G  2.9G  936M  76% /
/dev/sda1              99M   12M   83M  12% /boot
tmpfs                 252M     0  252M   0% /dev/shm
/dev/md0              198M  5.8M  182M   4% /raid5   \\ 理论上3个工作分区一共300M 实际存储容量为200M
[root@localhost ~]# ll
总计 156496
lrwxrwxrwx 1 root root        17 02-13 13:28 aa -> /root/install.log
-rw------- 1 root root      1280 02-06 08:04 anaconda-ks.cfg
drwxr-xr-x 2 root root      4096 02-06 00:14 Desktop
-rw-r--r-- 1 root root 160021215 02-13 23:29 hh.flv
-rw-r--r-- 1 root root     31964 02-06 08:04 install.log
-rw-r--r-- 1 root root      5502 02-06 08:03 install.log.syslog
-rw-r--r-- 1 root root       493 02-06 00:19 scsrun.log
[root@localhost ~]# cp hh.flv /raid5/     在RAID5中存储一个较大文件方便等下查看实验效果!!!!
[root@localhost ~]# df -h
文件系统              容量  已用 可用 已用% 挂载点
/dev/sda2             4.0G  3.0G  783M  80% /
/dev/sda1              99M   12M   83M  12% /boot
tmpfs                 252M     0  252M   0% /dev/shm
/dev/md0              198M  159M   29M  85% /raid5
[root@localhost ~]# cat /proc/mdstat                                              \\查看RAID设备相关信息
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdd[2]sde1[3](S) sdc1[1] sdb1[0]                                   ---此时,sde1成为备份磁盘
      208640 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
[root@localhost ~]# mdadm /dev/md0 -f /dev/sdb1                // 模拟sdb1坏掉
mdadm: set /dev/sdb1 faulty in /dev/md0
[root@localhost ~]# mdadm /dev/md0 -r /dev/sdb1              //模拟sdb1热拔出
mdadm: hot removed /dev/sdb1
[root@localhost ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdd1[2] sde1[0] sdc1[1]        //备份用的sde1代替了sdb1   计数由3-->0
      208640 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
      
unused devices:
[root@localhost ~]# mdadm /dev/md0 -f /dev/sdc1
mdadm: set /dev/sdc1 faulty in /dev/md0
[root@localhost ~]# mdadm /dev/md0 -r /dev/sdc1
mdadm: hot removed /dev/sdc1
[root@localhost ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdd1[2] sde1[0]                                        
      208640 blocks level 5, 64k chunk, algorithm 2 [3/2] [U_U]
      
unused devices:


恢复数据:
[root@localhost ~]# mdadm /dev/md0 -a /dev/sdb1  ----插回sdb1
mdadm: added /dev/sdb1
[root@localhost ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdb1[3] sdd1[2] sde1[0]
      208640 blocks level 5, 64k chunk, algorithm 2 [3/2] [U_U]
      [=====>...............]  recovery = 26.4% (27904/104320) finish=0.1min speed=6976K/sec        ----正在恢复数据
      
unused devices:
[root@localhost ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdb1[3] sdd1[2] sde1[0]     
      208640 blocks level 5, 64k chunk, algorithm 2 [3/2] [U_U]
      [===========>.........]  recovery = 56.8% (60288/104320) finish=0.1min speed=6698K/sec
      
unused devices:
[root@localhost ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdb1[1] sdd1[2] sde1[0]    \\ sdb1代替原来sdc1存储其数据
      208640 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
      
unused devices:
[root@localhost ~]# mdadm /dev/md0 -a /dev/sdc1  插回一个正常的sdc1
mdadm: added /dev/sdc1
[root@localhost ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sdc1[3](S) sdb1[1] sdd1[2] sde1[0]                                   \\此时,sdc1成为备份磁盘(原先备份盘是sde1)
      208640 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]


[root@localhost ~]# mdadm -D /dev/md0                              \\查看RAID基本信息
/dev/md0:
        Version : 0.90
  Creation Time : Mon Feb 13 23:04:00 2012
     Raid Level : raid5
     Array Size : 208640 (203.78 MiB 213.65 MB)
  Used Dev Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 3
  Total Devices : 4
Preferred Minor : 0
    Persistence : Superblock is persistent


    Update Time : Mon Feb 13 23:32:54 2012
          State : clean
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1


         Layout : left-symmetric
     Chunk Size : 64K


           UUID : e85ef82c:98f3d55c:ec09a842:090663e9
         Events : 0.16


    Number   Major   Minor   RaidDevice State
       0       8       65        0      active sync   /dev/sde1
       1       8       17        1      active sync   /dev/sdb1
       2       8       49        2      active sync   /dev/sdd1


       3       8       33        -      spare   /dev/sdc1
      
unused devices:


==================================================
设置RAID5系统启动自动运行:
[root@localhost ~]# mdadm -A /dev/md0 /dev/sd[b-e]1


[root@localhost ~]# mdadm -Ds >/etc/mdadm.conf
[root@localhost ~]# vi /etc/mdadm.conf
device /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
ARRAY /dev/md0 level=raid5 num-devices=3 metadata=0.90 spares=1 UUID=e85ef82c:98f3d55c:ec09a842:090663e9


最后修改/etc/fstab自动挂载
阅读(1756) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~