#fdisk /dev/sda
D删除一个分区
#pvcreate /dev/sdax
sdax就是你刚才创建的分区
从硬盘驱动器中创建物理卷(physical volumes-PV)。
从物理卷中创建卷组(volume groups-VG)。
从卷组中创建逻辑卷(logical volumes-LV),并分派逻辑卷挂载点
其中只有逻辑卷才可以写数据
#vgcreate myvg /dev/sda8
我就从卷组里面分100M出来创建一个逻辑卷
#lvcreate -L 100M myvg -n mylv1
[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]# |
#lvresize -L 绝对大小 对象
#lvresize -L 100M /dev/myvg/mylv2
resize2fs /dev/myvg/mylv2
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 ~]# |
#resize2fs /dev/myvg/mylv1
[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]# |
#vgedtend myvg /dev/sda9
#umount /mnt/mylv1
#umount /mnt/mylv2
[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 ~]# |
RAID0
RAID1
RAID5
优点:廉价
缺点:不稳定,如果系统坏了,RAID整列也就损坏,容易造成数据丢失
相对于软件RAID
优点:可靠性高,易管理。稳定
缺点:成本过高
因为RAID5至少需要3个或者更多的硬盘,我们就要分3个分区,然后再加一个热备份的分区,就是4个分区
the new table will be used at the next reboot
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 ~]# |
#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 ~]# |
#mount -t ext3 /dev/md1 /mnt/raid