linux 分区格式化挂载 物理卷 逻辑卷

今天我们主要说说分区、格式化、SWAP、LVM、软件RAID的创建哈~

格式化
查看当前分区:fdisk   -l
image
这个命令我们以前是讲过的,我现在问下,ID那项是什么意思?
image
83 是代表EXT2和EXT3
82 是代表SWAP分区
硬盘结构我们就不讲了,相信大家都有基础。我们就直接进入操作
LINUX分区使用的工具是FDISK
对系统的第一个硬盘分区
#fdisk   /dev/sda 
如果是对第二个硬盘分区,就是fdisk /dev/sdb
大家运行这个命令:#fdisk   /dev/sda 
image
大家都进入这个界面了吧?这是主菜单,按m就有提示
image
我们主要掌握的是以下几个参数:
D删除一个分区
N创建一个分区
Q 不保存退出
T改变分区ID
W保存退出 
问下,LINUX对SCSI硬盘最多支持多少分区?
最多支持4个主分区,总分区数最多15个,fdisk 命令最多支持16个分区,IDE硬盘要多一些
现在我们创建一个分区 大小为500MB,在主菜单输入n
First cylinder (2690-3916, default 2690):
这个表示第一个柱面空间的块是 2690-3916,default2690的意思就是默认从2690开始。我们直接点回车,使用默认的
image 
Last cylinder or +size or +sizeM or +sizeK (2690-3916, default 3916):
这里就是输入分区的大小,默认是以块为单位,我们要分500MB,我们就输入+500M哈~然后回车,分区就算完成了。
image
系统默认的分区ID就是83,所以我们没必要修改,直接按w保存退出
image
大家看见 The new table will be used at the next reboot没?意思就是这个分区在下次启动的时候才能使用,我们可以使用一个命令,让这个分区马上生效哈~
输入#partprobe,自己使用命令补全哈
image
然后用fdisk -l查看下, 最后一个,就是我们新建的分区
image
看见了吧,现在我们就格式这个分区,看到分区的号码/dev/sda7 ,等下我们格式化的时候要用
格式化的标准命令:
#mkfs    -t   ext3   /dev/sda7 
我的是第7个分区,你们是第几个就用第几个
-t 后面跟的就是文件系统的类型
image
现在我们要挂载这个分区。挂载我已经教过了,相信大家还没忘记吧
先在/mnt/下面建立一个目录
#mkdir   /mnt/backup 
backup就是我建立的目录
然后我们手动挂载哈~
#mount   -t   ext3   /dev/sda7    /mnt/backup 
具体情况以你的分区号和建立的目录名为准

image

然后CD到这目录里面去,如果看见有一个LOST+fount目录,就说明你分区挂载成功了,现在就可以往分区里面写入数据了
image
如果想把这个分区开机挂载,就把它写入/etc/fstab
刚才我们格式化使用的命令是#mkfs   -t   ext3   /dev/sdax
还有专门用于格式EXT3系统的命令:#mkfs.ext3   /dev/sdax 就行了
大家OK的话,我们下面就开始学习用命令创建LVM逻辑卷 
LVM的优点就是可以随意拉升和缩小。在基础部分我们已经用图形界面创建过,现在我们使用命令来创建
第一步:划分物理分区 
使用和刚才一样de方法
#fdisk   /dev/sda 
输入n哈~然后回车使用默认的起始点,接着输入大小哈。我们创建一个300M大小的空间,输入+300M 
image
注意,这里比刚才多一步,由于LVM的ID和EXT3不一样,而系统默认是的EXT3,所以这里我们需要修改一下
在主菜单输入T 
系统会让你选择要改变ID的分区,输入我们刚创建的分区,也就是最后一个8

image

Hex code (type L to list codes): 
这里输入分区类型,LVM是8e,如果你不记得了,可以使用l 查看分区ID的对应列表
输入l后,系统会列出所有分区对应的ID号
image
在列表中,我们可以看见LINUX LVM对应的是8e,所以我们直接输入8e,然后回车,
在主菜单输入p,查看当前分区情况
image
看见最后你分出来的分区ID已经是8e,那么就可以输入w 保存退出
退出以后,记得要重启这个分区才能生效。我们要使用一个命令让它立即生效
#partprobe 

image

到这里,第一步创建物理分区完成哈~
第二步:创建LVM的物理卷
使用命令
#pvcreate   /dev/sdax 
sdax就是你刚才创建的分区
创建成功后,可以使用pvdisplay 查看
image
image
那我们在这里暂停一下,给大家回顾下什么是LVM
LVM就想一种磁盘管理方式,叫逻辑卷管理器,从 Red Hat Linux 8.0 开始,逻辑卷管理器(LVM)可以在硬盘驱动器分配上使用,LVM 是一种把硬盘驱动器空间分配成逻辑卷的方法,这样硬盘就不必使用分区而被简易地重划大小。 

image

LVM有点象WIN下的动态磁盘,动态磁盘知道吗?LVM 是一种把硬盘驱动器空间分配成逻辑卷的方法,这样硬盘就不必使用分区而被简易地重划大小。主要就是这个功能,可以随意扩展或者缩小某个分区的大小,前提这个分区是逻辑卷管理的。
image
嗯,这个就是它的主要功能 
从硬盘驱动器中创建物理卷(physical volumes-PV)。
从物理卷中创建卷组(volume groups-VG)。
从卷组中创建逻辑卷(logical volumes-LV),并分派逻辑卷挂载点 
其中只有逻辑卷才可以写数据
 
image
没有大小限制哈,只要你硬盘有空间,比如刚才我们说的硬盘只支持15个分区,那么我们就可以使用LVM来把分区数量无限化 

image

对 ,分一个物理分区,建立一个物理卷,然后这个物理卷建立一个卷组,我们就可以在这个卷组里面去分无数个逻辑卷,而且逻辑卷可以随意扩大缩小,不会对物理分 区有影响,逻辑卷的功能也和物理分区差不多,一样可以格式化成随意的文件系统,挂载到随意的目录。 同时也支持quota 
好了,我们继续哈~
刚才我们创建了物理卷PV-(physical volumes),可以使用pvdisplay查看。
PV创建好以后,我们就要创建卷组了,volume groups-VG ,卷组是在物理卷的基础上创建的,也就把物理卷的空间拿来给卷组管理,然后逻辑卷就可以向卷组要空间了
第三步:创建卷组
#vgcreate    卷组名      物理卷
#vgcreate     myvg        /dev/sda8
 
创建成功后,可以使用vgdisplay 来查看卷组

image

第四步:创建逻辑卷 (重点)
#lvcreate  -L  大小  卷组名  -n  逻辑卷名称
我就从卷组里面分100M出来创建一个逻辑卷
#lvcreate  -L  100M  myvg  -n  mylv1 
image
OK,现在我们格式化mylv1为ext3文件格式并挂载到/mnt/mylv1目录
第五步:格式化、挂载逻辑卷
#mkfs.ext3   /dev/myvg/mylv1 
image
#mkdir   /mnt/mylv1 
#mount   -t   ext3   /dev/myvg/mylv1   /mnt/mylv1 
然后进入这个目录,能够看见lost+fount目录就成功了
image
这个逻辑卷使用fdisk -l  是查看不到滴,只有使用lvdisplay 查看
[root@rhel5 /mnt/mylv1]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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        1318    10482412+  83  Linux
/dev/sda3            1319        1971     5245222+  83  Linux
/dev/sda4            1972        3916    15623212+   5  Extended
/dev/sda5            1972        2624     5245191   83  Linux
/dev/sda6            2625        2689      522081   82  Linux swap / Solaris
/dev/sda7            2690        2751      497983+  83  Linux
/dev/sda8            2752        2788      297171   8e  Linux LVM
[root@rhel5 /mnt/mylv1]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/myvg/mylv1
  VG Name                myvg
  LV UUID                xXbNEd-LAQa-xLtB-c92X-3BJ9-qfWu-z54ejZ
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                100.00 MB
  Current LE             25
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:0
[root@rhel5 /mnt/mylv1]#
如果要查看这个逻辑卷挂在到哪了,可以使用#mount 查看
image
现在我们再在刚才的卷组里面划分一个逻辑卷mylv2出来,大小是150M,文件格式为ext3,挂载到/mnt/mylv2
#lvcreate   -L  150M   myvg   -n   mylv2
#mkfs.ext3   /dev/myvg/mylv2
#mkdir   /mnt/mylv2
#mount   -t   ext3   /dev/myvg/mylv2   /mnt/mylv2 
就这四条命令就OK了哈~
image
现在mylv1是100M,mylv2是150M哈~
我现在要把mylv2减少50M ,将这50M添加到mylv1里面去哈,大家看下面
使用命令 
#lvresize   -L   绝对大小   对象
#lvresize   -L   100M   /dev/myvg/mylv2
 
image
然后确定大小
resize2fs   /dev/myvg/mylv2 
注意:缩小空间时可能会导致数据损坏,就像下面反复报错误哈~
image
正确滴方法是:
对于lvm,如果是扩大某个lv,操作比较简单,但如果是缩小lv,则有一定的风险。我们先要缩小/dev/myvg/lv2文件系统,然后才能缩小lvm,如果在缩小lvm之前忘了缩小文件系统,这时候可以这样来挽救:
1:不要进行对该分区的任何写入操作,最好是也不read
2:用lvresize2fs重新扩大该分区,且扩大的容量是刚刚缩小的容量(数字一定要和刚刚的一致哈~)。
3:缩小文件系统
4:最后缩小逻辑卷哈。
5:确认文件系统和逻辑卷大小一致。
[root@rhel5 ~]# umount   /mnt/mylv2
[root@rhel5 ~]# lvresize   -L   150M   /dev/myvg/mylv2
  Rounding up size to full physical extent 152.00 MB
  Extending logical volume mylv2 to 152.00 MB
  Logical volume mylv2 successfully resized
[root@rhel5 ~]# e2fsck   -f   /dev/myvg/mylv2
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/myvg/mylv2: 12/38912 files (8.3% non-contiguous), 10580/155648 blocks
[root@rhel5 ~]# resize2fs   /dev/myvg/mylv2   100M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/myvg/mylv2 to 102400 (1k) blocks.
The filesystem on /dev/myvg/mylv2 is now 102400 blocks long.
[root@rhel5 ~]# lvresize   -L   100M   /dev/myvg/mylv2
  WARNING: Reducing active logical volume to 100.00 MB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mylv2? [y/n]: y
  Reducing logical volume mylv2 to 100.00 MB
  Logical volume mylv2 successfully resized
[root@rhel5 ~]# e2fsck   -f   /dev/myvg/mylv2
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/myvg/mylv2: 12/26624 files (8.3% non-contiguous), 9032/102400 blocks
[root@rhel5 ~]# mount   -t  ext3   /dev/myvg/mylv2   /mnt/mylv2
[root@rhel5 ~]#
ok,这样就缩小了LV的大小,注意要先umount哈~
使用同样的命令给mylv1加50M,这个就比较简单了哈~
#lvresize   -L  150M   /dev/myvg/mylv1 
image
确定大小,或者说是让命令生效
#resize2fs    /dev/myvg/mylv1 
image
这样就完成了LVM的扩展和减少,我们用lvdisplay查看一下哈~
image
现在我们使用的空间都是在卷组里面调用的,如果卷组的空间用完了怎么办?
那我们就需要给卷组拉升大小,给卷组拉升大小的方法
第一步、创建物理分区 
#fdisk   /dev/sda 
然后分一个分区,你想多大就多大,改变分区ID位8e。 然后保存退出
[root@rhel5 /mnt/mylv1]# fdisk    /dev/sda
The number of cylinders for this disk is set to 3916.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
First cylinder (2789-3916, default 2789):
Using default value 2789
Last cylinder or +size or +sizeM or +sizeK (2789-3916, default 3916): +500M
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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        1318    10482412+  83  Linux
/dev/sda3            1319        1971     5245222+  83  Linux
/dev/sda4            1972        3916    15623212+   5  Extended
/dev/sda5            1972        2624     5245191   83  Linux
/dev/sda6            2625        2689      522081   82  Linux swap / Solaris
/dev/sda7            2690        2751      497983+  83  Linux
/dev/sda8            2752        2788      297171   8e  Linux LVM
/dev/sda9            2789        2850      497983+  83  Linux
Command (m for help): t
Partition number (1-9): 9
Hex code (type L to list codes): 8e
Changed system type of partition 9 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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        1318    10482412+  83  Linux
/dev/sda3            1319        1971     5245222+  83  Linux
/dev/sda4            1972        3916    15623212+   5  Extended
/dev/sda5            1972        2624     5245191   83  Linux
/dev/sda6            2625        2689      522081   82  Linux swap / Solaris
/dev/sda7            2690        2751      497983+  83  Linux
/dev/sda8            2752        2788      297171   8e  Linux LVM
/dev/sda9            2789        2850      497983+  8e  Linux LVM
Command (m for help): w
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.
Syncing disks.
[root@rhel5 /mnt/mylv1]#
使用partprobe 使分区马上生效
image
第二步:创建物理卷 
#pvcreate    /dev/sda9 
image
第三步:拉升卷组,把刚建立的物理卷的空间加到以前的卷组中(重点) 
#vgextend      卷组名        物理卷
#vgedtend        myvg         /dev/sda9
image
现在你就可以使用vgdisplay 来查看新的myvg 卷组的大小了
#vgdisplay    myvg
image
给卷组增加大小后,我们就可以把新的空间分配到LVM中,这样LVM的空间就可以无限扩张
下面我们来看下删除逻辑卷
我们创建LVM是从物理分区-物理卷-卷组-逻辑卷-挂载到目录这个顺序来的
删除当然像反安装一样,反正来哈~
1)先是取消挂载
#umount   /mnt/mylv1
#umount   /mnt/mylv2
 
image
2)然后就是删除LVM 
#lvremove   /dev/myvg/mylv1 
#lvremove   /dev/myvg/mylv2
image
3)然后就删除卷组 
#vgremove   myvg 
image
4)然后删除物理卷 
#pvremove   /dev/sda8
#pvremove  /dev/sda9 
image
5)最后就是删除物理分区了
fdisk    /dev/sda 
[root@rhel5 ~]# fdisk    /dev/sda
The number of cylinders for this disk is set to 3916.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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        1318    10482412+  83  Linux
/dev/sda3            1319        1971     5245222+  83  Linux
/dev/sda4            1972        3916    15623212+   5  Extended
/dev/sda5            1972        2624     5245191   83  Linux
/dev/sda6            2625        2689      522081   82  Linux swap / Solaris
/dev/sda7            2690        2751      497983+  83  Linux
/dev/sda8            2752        2788      297171   8e  Linux LVM
/dev/sda9            2789        2850      497983+  8e  Linux LVM
Command (m for help): d
Partition number (1-9): 9
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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        1318    10482412+  83  Linux
/dev/sda3            1319        1971     5245222+  83  Linux
/dev/sda4            1972        3916    15623212+   5  Extended
/dev/sda5            1972        2624     5245191   83  Linux
/dev/sda6            2625        2689      522081   82  Linux swap / Solaris
/dev/sda7            2690        2751      497983+  83  Linux
/dev/sda8            2752        2788      297171   8e  Linux LVM
Command (m for help): d
Partition number (1-8): 8
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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        1318    10482412+  83  Linux
/dev/sda3            1319        1971     5245222+  83  Linux
/dev/sda4            1972        3916    15623212+   5  Extended
/dev/sda5            1972        2624     5245191   83  Linux
/dev/sda6            2625        2689      522081   82  Linux swap / Solaris
/dev/sda7            2690        2751      497983+  83  Linux
Command (m for help): w
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.
Syncing disks.
[root@rhel5 ~]# partprobe
[root@rhel5 ~]#
这样逻辑卷就算成功删除了
LVM就这样了。我讲的比较浅,如果大家有更深的用法,可以下来和我探讨,有什么要问的,可以问哈~
软件RAID 
这个比LVM简单多了
RAID就是廉价冗余磁盘阵列
常用的级别是:
RAID0
RAID1
RAID5
 
RAID 0又称为Stripe或Striping,中文译为集带工作方式。它是将要存取的数据以条带状形式尽量平均分配到多个硬盘上,读写时多个硬盘同时进行读 写,从而提高数据的读写速度。RAID 0另一目的是获得更大的“单个”磁盘容量从而提高数据的读写速度。这是他的优点,我觉得最重要是提高读写速度
RAID 1又称为Mirror或Mirroring,中文译为镜像方式。这种工作方式的出现完全是为了数据安全考虑的,它是把用户写入硬盘的数据百分之百地自动复 制到另外一个硬盘上或硬盘的不同地方(镜像)。当读取数据时,系统先从RAID 1的源盘读取数据,如果读取数据成功,则系统不去管备份盘上的数据;如果读取源盘数据失败,则系统自动转而读取备份盘上的数据,不会造成用户工作任务的中 断。由于对存储的数据进行百分之百的备份,在所有RAID级别中,RAID 1提供最高的数据安全保障。同样,由于数据的百分之百备份,备份数据占了总存储空间的一半,因而,Mirror的磁盘空间利用率低,存储成本高。
RAID 5是一种存储性能、数据安全和存储成本兼顾的存储解决方案,也是目前应用最广泛的RAID技术。各块独立硬盘进行条带化分割,相同的条带区进行奇偶校验 (异或运算),校验数据平均分布在每块硬盘上。以n块硬盘构建的RAID 5阵列可以有2/3块硬盘的容量,存储空间利用率非常高。RAID 5不对存储的数据进行备份,而是把数据和相对应的奇偶校验信息存储到组成RAID5的各个磁盘上,并且奇偶校验信息和相对应的数据分别存储于不同的磁盘 上。当RAID 5的任何一块硬盘上的数据丢失,均可以通过校验数据推算出来
具体算法就让学存储的技术搞吧,我们知道RAID5有这个功能就行了
下面说说,RAID设备。
RAID分为软RAID和硬件RAID 
软件RAID是基于系统的软件工作
优点:廉价
缺点:不稳定,如果系统坏了,RAID整列也就损坏,容易造成数据丢失
硬件RAID,这就是各大厂商提供的,存储解决方案。有专门的设备负责处理磁盘间的数据流。
相对于软件RAID
优点:可靠性高,易管理。稳定
缺点:成本过高
下面我们要讲的基于LINUX系统的软件RAID
在LINUX下管理RAID阵列的工具是mdadm工具
mdadm程序是一个独立的程序,能完成所有的软RAID管理功能
主要有7种使用模式:
Create 使用空闲的设备创建一个新的阵列,每个设备具有元数据块 
Assemble 将原来属于一个阵列的每个块设备组装为阵列 
Build 创建或组装不需要元数据的阵列,每个设备没有元数据块 
Manage 管理已经存储阵列中的设备,比如增加热备磁盘或者设置某个磁盘失效,然后从阵列中删除这个磁盘
Misc 报告或者修改阵列中相关设备的信息,比如查询阵列或者设备的状态信息 
Grow 改变阵列中每个设备被使用的容量或阵列中的设备的数目 
Monitor 监控一个或多个阵列,上报指定的事件 
由于这个工具太强大,不能一一为大家讲解
我们今天主要讲创建任意级别的RAID,和如何删除这个RAID
至于管理就只有您自己下来找资料研究了
往往廉价的东西,用的人都多
RAID分区的ID是 fd 请大家记住 
现在我们开始实战
题目:建立一个RAID5 级别的分区使用一个分区给这个RAID做热备份,并挂在到本地的/mnt/raid 目录,
1、创建物理分区
因为RAID5至少需要3个或者更多的硬盘,我们就要分3个分区,然后再加一个热备份的分区,就是4个分区
#fdisk   /dev/sda
然后输入n ,创建分区
使用默认的起始点
输入大小为+100M
然后重复刚才的操作4次,创建4个分区,创建完4个分区后
我们还要改变分区的ID
在分区的主菜单输入T
然后输入要改变ID的分区号,也就是最后4个分区
然后输入分区的ID:fd
四个分区都改成FD
完成后,在分区主菜单里面使用p 查看分区信息
是不是最后4个分区都是ID为fd
如果OK的话,就输入w 保存退出
保存退出后,注意提示:
the new table will  be used at the next reboot 
我们还是要使用#partprobe 使分区马上生效
系统会提示
warning: unable to open /dev/h dc read-wirte ( read-only file system) 
这个是正常的,应为光盘本来就是只读的也可以,我们也可以弹出光盘~~~
[root@rhel5 ~]# fdisk  -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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        1318    10482412+  83  Linux
/dev/sda3            1319        1971     5245222+  83  Linux
/dev/sda4            1972        3916    15623212+   5  Extended
/dev/sda5            1972        2624     5245191   83  Linux
/dev/sda6            2625        2689      522081   82  Linux swap / Solaris
[root@rhel5 ~]# fdisk  /dev/sda
The number of cylinders for this disk is set to 3916.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
First cylinder (2690-3916, default 2690):
Using default value 2690
Last cylinder or +size or +sizeM or +sizeK (2690-3916, default 3916): +100M
Command (m for help): n
First cylinder (2703-3916, default 2703):
Using default value 2703
Last cylinder or +size or +sizeM or +sizeK (2703-3916, default 3916): +100M
Command (m for help): n
First cylinder (2716-3916, default 2716):
Using default value 2716
Last cylinder or +size or +sizeM or +sizeK (2716-3916, default 3916): +100M
Command (m for help): n
First cylinder (2729-3916, default 2729):
Using default value 2729
Last cylinder or +size or +sizeM or +sizeK (2729-3916, default 3916): +100M
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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        1318    10482412+  83  Linux
/dev/sda3            1319        1971     5245222+  83  Linux
/dev/sda4            1972        3916    15623212+   5  Extended
/dev/sda5            1972        2624     5245191   83  Linux
/dev/sda6            2625        2689      522081   82  Linux swap / Solaris
/dev/sda7            2690        2702      104391   83  Linux
/dev/sda8            2703        2715      104391   83  Linux
/dev/sda9            2716        2728      104391   83  Linux
/dev/sda10           2729        2741      104391   83  Linux
Command (m for help): t
Partition number (1-10): 7
Hex code (type L to list codes): fd
Changed system type of partition 7 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-10): 8
Hex code (type L to list codes): fd
Changed system type of partition 8 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-10): 9
Hex code (type L to list codes): fd
Changed system type of partition 9 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-10): 10
Hex code (type L to list codes): fd
Changed system type of partition 10 to fd (Linux raid autodetect)
Command (m for help): p
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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        1318    10482412+  83  Linux
/dev/sda3            1319        1971     5245222+  83  Linux
/dev/sda4            1972        3916    15623212+   5  Extended
/dev/sda5            1972        2624     5245191   83  Linux
/dev/sda6            2625        2689      522081   82  Linux swap / Solaris
/dev/sda7            2690        2702      104391   fd  Linux raid autodetect
/dev/sda8            2703        2715      104391   fd  Linux raid autodetect
/dev/sda9            2716        2728      104391   fd  Linux raid autodetect
/dev/sda10           2729        2741      104391   fd  Linux raid autodetect
Command (m for help): w
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.
Syncing disks.
[root@rhel5 ~]# partprobe
Warning: Unable to open /dev/hdc read-write (Read-only file system).  /dev/hdc has been opened read-only.
[root@rhel5 ~]# partprobe
[root@rhel5 ~]#
第二步:创建阵列设备
系统默认有个md0可以给我们用,如果我要多个raid的话,就需要自己创建设备了,所以在这里我教大家怎么创建raid设备
#mknod  /dev/md1  b  9  1
创建md1这个raid设备
mknod是命令
/dev/md1 是设备名字,设备必须是/dev/md开始的
后面的b代表创建的是块设备
9是主设备号,1代表从设备号
主设备好不能改,从设备号在系统内唯一
创建好以后,可以使用ls  /dev/md1 看看有没有这个设备了
image
第三步:创建RAID阵列
使用MDADM工具
#mdadm  -C  /dev/md1  -l  5  -n  3  -x  1  /dev/sda7  /dev/sda8  /dev/sda9  /dev/sda10
OK以后,可以使用命令
#mdadm   --detail  /dev/md1 
查看RAID状态
[root@rhel5 ~]# mdadm  -C  /dev/md1  -l  5  -n  3  -x  1  /dev/sda7  /dev/sda8  /dev/sda9 /dev/sda10
mdadm: array /dev/md1 started.
[root@rhel5 ~]# mdadm  --detail  /dev/md1
/dev/md1:
        Version : 00.90.03
  Creation Time : Mon Dec 29 17:25:41 2008
     Raid Level : raid5
     Array Size : 208640 (203.78 MiB 213.65 MB)
    Device Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 3
  Total Devices : 4
Preferred Minor : 1
    Persistence : Superblock is persistent
    Update Time : Mon Dec 29 17:25:44 2008
          State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
  Spare Devices : 1
         Layout : left-symmetric
     Chunk Size : 64K
           UUID : 2f7e30d2:f3f54047:e22d6b9f:16f2b256
         Events : 0.2
    Number   Major   Minor   RaidDevice State
       0       8        7        0      active sync   /dev/sda7
       1       8        8        1      active sync   /dev/sda8
       2       8        9        2      active sync   /dev/sda9
       3       8       10        -      spare   /dev/sda10
[root@rhel5 ~]#
给大家解释下刚才的那个命令吧:
[root@rhel5 ~]# mdadm  -C  /dev/md1  -l  5  -n  3  -x  1  /dev/sda7  /dev/sda8 /dev/sda9  /dev/sda10
-C 代表创建
-l 代表创建的级别  
-n 代表活动的分区,也就是你要给这个级别多少个分区
-x 就是热备份的分区
后面就跟设备就OK了
软RAID就可以使用分区来替代硬盘,如果你有真实的硬盘,这里也可以跟上硬盘
第四步:格式化raid设备
#mkfs.ext3  /dev/md1 
image
第五步:创建目录并挂载
#mkdir  /mnt/raid
#mount  -t  ext3  /dev/md1 /mnt/raid
然后就可以进入这个目录,看是不是有一个叫lost+found的目录,如果有,就证明操作成功了
image
OK哈~~~
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值