感谢支持
我们一直在努力

RHEL5 Swap,ext3,lvm及raid5磁盘管理

一:新建一个交换分区
1:挂载上一块新的虚拟磁盘,使用fdisk -l命令查看系统是否能正确的识别磁盘
[root@server1 ~]# fdisk -l
Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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       10443    83778975   8e Linux LVM


Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn’t contain a valid partition table


2:查看当前的交换分区和挂载选项,目前为1G,所在的物理位置为LVM卷组中的:/dev/mapper/VolGroup00-LogVol01
[root@server1 ~]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/mapper/VolGroup00-LogVol01         partition       1048568 0       -1


[root@server1 ~]# grep ‘swap’ /etc/fstab
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0



3:使用fdisk命令在新添加的磁盘上划出一块500M的空间,并把格式转换为82,即swap分区格式
[root@server1 ~]# fdisk /dev/sdb
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition’s system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)


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


Command (m for help): p


Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id System
/dev/sdb1               1          62      497983+ 83 Linux



Command (m for help): t
Selected partition 1
Hex code (type L to list codes): L


……………………………………………………
……………………………………………………
……………………………………………………


Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap / Solaris)
Command (m for help): p


Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id System
/dev/sdb1               1          62      497983+ 82 Linux swap / Solaris


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


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

4:使用partprobe将新的分区表读入内存,如果提示”command not found”则安装partd rpm包
[root@server1 ~]# partprobe
-bash: partprobe: command not found
[root@server1 ~]# yum -y install parted
[root@server1 ~]# partprobe


5:卸载交换分区,并使用mkswap命令将新划出的分区格式化成swap格式
[root@server1 ~]# swapoff -a
[root@server1 ~]# swapon -s
[root@server1 ~]# mkswap /dev/sdb1
Setting up swapspace version 1, size = 509927 kB
修改/etc/fstab文件,定义挂载参数
[root@server1 ~]# grep ‘swap’ /etc/fstab
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0
/dev/sdb1               swap                    swap    defaults         0 0


6:重新挂载swap分区,并查看结果
[root@server1 ~]# mount -a
[root@server1 ~]# swapon -a
[root@server1 ~]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/mapper/VolGroup00-LogVol01         partition       1048568 0       -2
/dev/sdb1                               partition       497972 0       -3

二:新建一个ext3分区
1:划出一个5G大小的分区,这里划成主分区,默认即83,ext3分区,故无需转换分区类型
[root@server1 ~]# fdisk /dev/sdb
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (63-2610, default 63):
Using default value 63
Last cylinder or +size or +sizeM or +sizeK (63-2610, default 2610): +5000M


Command (m for help): p


Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id System
/dev/sdb1               1          62      497983+ 82 Linux swap / Solaris
/dev/sdb2              63         671     4891792+ 83 Linux


Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.


2:将新的分区表读入内存,并格式化新划出的分区
[root@server1 ~]# partprobe
[root@server1 ~]# mkfs.ext3 /dev/sdb2 这里也可以使用:mke2fs -j /dev/sdb2 来实现


3:挂载分区,并参看详细的参数
[root@server1 ~]# mkdir /data
[root@server1 ~]# mount /dev/sdb2 /data
[root@server1 ~]# tune2fs -l /dev/sdb2
tune2fs 1.39 (29-May-2006)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          6cc96c67-e0a5-4039-8b9d-9ecac3485f43
Filesystem magic number: 0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal resize_inode dir_index filetype needs_recovery
……………………………………………………
……………………………………………………
……………………………………………………



4:也可以使用标签‘LABEL’方式挂载
[root@server1 ~]# grep ‘data’ /etc/fstab
/dev/sdb2               /data                   ext3    defaults        0 0
[root@server1 ~]# e2label /dev/sdb2


[root@server1 ~]# e2label /dev/sdb2 mydata
[root@server1 ~]# e2label /dev/sdb2
mydata
[root@server1 ~]# umount /data/
[root@server1 ~]# mount -a
[root@server1 ~]# grep ‘data’ /etc/fstab
LABEL=mydata            /data                   ext3    defaults        0 0
[root@server1 ~]# stat /data/
File: `/data/’
Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: 812h/2066d      Inode: 2           Links: 3
Access: (0755/drwxr-xr-x) Uid: (    0/    root)   Gid: (    0/    root)
Access: 2010-01-25 08:15:52.000000000 -0500
Modify: 2010-01-25 08:04:30.000000000 -0500
Change: 2010-01-25 08:04:30.000000000 -0500


三:新建扩展分区,并在扩展分区内新建lvm卷组
1:划出10G大小的分区,这里的分区类型选择扩展分区,主分区也是可以的
[root@server1 ~]# fdisk /dev/sdb
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 3
First cylinder (672-2610, default 672):
Using default value 672
Last cylinder or +size or +sizeM or +sizeK (672-2610, default 2610): +10000M


Command (m for help): p


Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id System
/dev/sdb1               1          62      497983+ 82 Linux swap / Solaris
/dev/sdb2              63         671     4891792+ 83 Linux
/dev/sdb3             672        1888     9775552+   5 Extended
Command (m for help): w
The partition table has been altered!
[root@server1 ~]# partprobe


2:在扩展分区内划出5G大小的逻辑分区,并将此逻辑分区的类型改为8e
[root@server1 ~]# fdisk /dev/sdb
Command (m for help): p


Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id System
/dev/sdb1               1          62      497983+ 82 Linux swap / Solaris
/dev/sdb2              63         671     4891792+ 83 Linux
/dev/sdb3             672        1888     9775552+   5 Extended


Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (672-1888, default 672):
Using default value 672
Last cylinder or +size or +sizeM or +sizeK (672-1888, default 1888): +5000M


Command (m for help): p


Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id System
/dev/sdb1               1          62      497983+ 82 Linux swap / Solaris
/dev/sdb2              63         671     4891792+ 83 Linux
/dev/sdb3             672        1888     9775552+   5 Extended
/dev/sdb5             672        1280     4891761   83 Linux


Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)


Command (m for help): w
The partition table has been altered!
[root@server1 ~]# partprobe


[root@server1 ~]# fdisk -l /dev/sdb


Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id System
/dev/sdb1               1          62      497983+ 82 Linux swap / Solaris
/dev/sdb2              63         671     4891792+ 83 Linux
/dev/sdb3             672        1888     9775552+   5 Extended
/dev/sdb5             672        1280     4891761   8e Linux LVM


3:创建逻辑卷
[root@server1 ~]# pvcreate /dev/sdb5
Physical volume “/dev/sdb5” successfully created


[root@server1 ~]# pvdisplay
……………………………………………………
……………………………………………………
— NEW Physical volume —
PV Name               /dev/sdb5
VG Name              
PV Size               4.67 GB
Allocatable           NO
PE Size (KByte)       0
Total PE              0
Free PE               0
Allocated PE          0
PV UUID               0Yn9GU-inkA-35y3-PuOF-zocp-egv7-xve86R



4:将逻辑卷加入到卷组
[root@server1 ~]# vgcreate yang /dev/sdb5
Volume group “yang” successfully created


[root@server1 ~]# vgdisplay yang
— Volume group —
VG Name               yang
System ID            
Format                lvm2
Metadata Areas        1
Metadata Sequence No 1
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                0
Open LV               0
Max PV                0
Cur PV                1
Act PV                1
VG Size               4.66 GB
PE Size               4.00 MB
Total PE              1194
Alloc PE / Size       0 / 0  
Free PE / Size       1194 / 4.66 GB
VG UUID               9xieZt-A8Wv-iWly-5WOd-Zzzp-oVNU-Be8WlK
  


5:在卷组中新建LVM分区
[root@server1 ~]# lvcreate -L 1000M yang -n lv01
Logical volume “lv01” created


[root@server1 ~]# lvdisplay
— Logical volume —
LV Name                /dev/yang/lv01
VG Name                yang
LV UUID                BrKr62-pBx9-msvS-fK1c-0EEo-skZT-9WkpSj
LV Write Access        read/write
LV Status              available
# open                 0
LV Size                1000.00 MB
Current LE             250
Segments               1
Allocation             inherit
Read ahead sectors     0
Block device           253:2


6:格式化新建好的分区并挂载,查看,验证
[root@server1 ~]# mke2fs -j /dev/yang/lv01
mke2fs 1.39 (29-May-2006)
Writing inode tables: done                           
Creating journal (4096 blocks): done


[root@server1 ~]# mkdir /lvo1
[root@server1 ~]# mount /dev/yang/lv01 /lvo1/
[root@server1 ~]# tune2fs -l /dev/yang/lv01
tune2fs 1.39 (29-May-2006)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          10f548ae-48a1-47e8-b21e-17d69a1aab7c
Filesystem magic number: 0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal resize_inode dir_index filetype needs_recovery
……………………………………………………
……………………………………………………
……………………………………………………



[root@server1 ~]# df -h
Filesystem            Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       77G 6.0G   67G   9% /
/dev/sda1              99M   18M   77M 19% /boot
tmpfs                  28M     0   28M   0% /dev/shm
/dev/sdb2             4.6G 138M 4.3G   4% /data
/dev/mapper/yang-lv01
                      985M   18M 928M   2% /lvo1


7:增大分区容量,验证
[root@server1 ~]# umount /lvo1/
[root@server1 ~]# lvresize -L 3000M /dev/yang/lv01
Extending logical volume lv01 to 2.93 GB
Logical volume lv01 successfully resized


[root@server1 ~]# e2fsck -f /dev/yang/lv01


[root@server1 ~]# mount /dev/yang/lv01 /lvo1/
[root@server1 ~]# df -h |tail -n 1
/dev/mapper/yang-lv01 2.9G   18M 2.8G   1% /lvo1


8:缩小分区容量,验证
[root@server1 ~]# umount /lvo1/
[root@server1 ~]# resize2fs /dev/yang/lv01 2000M
resize2fs 1.39 (29-May-2006)
Please run ‘e2fsck -f /dev/yang/lv01’ first.
[root@server1 ~]# e2fsck -f /dev/yang/lv01
[root@server1 ~]# lvresize -L 2000M /dev/yang/lv01
WARNING: Reducing active logical volume to 1.95 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv01? [y/n]: y
Reducing logical volume lv01 to 1.95 GB
Logical volume lv01 successfully resized


[root@server1 ~]# e2fsck -f /dev/yang/lv01
[root@server1 ~]# mount /dev/yang/lv01 /lvo1/
[root@server1 ~]#df -h |tail -n 1
/dev/mapper/yang-lv01    2.0G   18M 1.9G   1% /lvo1

三:磁盘冗余阵列管理,raid5
1:按照前面的步骤,新建4个300M的分区,并将他们的分区类型改为fd,保存退出,并使其生效
Command (m for help): p

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id System
/dev/sdb1               1          62      497983+ 82 Linux swap / Solaris
/dev/sdb2              63         671     4891792+ 83 Linux
/dev/sdb3             672        1888     9775552+   5 Extended
/dev/sdb5             672        1280     4891761   8e Linux LVM
/dev/sdb6            1281        1317      297171   fd Linux raid autodetect
/dev/sdb7            1318        1354      297171   fd Linux raid autodetect
/dev/sdb8            1355        1391      297171   fd Linux raid autodetect
/dev/sdb9            1392        1428      297171   fd Linux raid autodetect


Command (m for help): w
The partition table has been altered!
[root@server1 ~]# partprobe


2:创建挂载点/dev/md1,也可以使用默认的md0
[root@server1 ~]# ll -i /dev/md0
5536 brw-r—– 1 root disk 9, 0 Jan 25 06:10 /dev/md0
[root@server1 ~]# mknod /dev/md1 b 9 1
[root@server1 ~]# ll -i /dev/md1
12338 brw-r–r– 1 root root 9, 1 Jan 25 12:06 /dev/md1


3:将分区加入到md5阵列,若出现”command not found”则安装mdadm rpm包
[root@server1 ~]# mdadm -h
-bash: mdadm: command not found
[root@server1 ~]# yum -y install mdadm
[root@server1 ~]# mdadm -C /dev/md1 -l 5 -n 3 -x 1 /dev/sdb6 /dev/sdb7 /dev/sdb8 /dev/sdb9
mdadm: array /dev/md1 started.
-C 代表创建
-l 代表创建的级别
-n 代表活动的分区,也就是你要给这个级别多少个分区
-x 就是热备份的分区
后面就跟设备就OK了


4:挂载并验证
[root@server1 ~]# mkfs.ext3 /dev/md1
[root@server1 ~]# mkdir /fd
[root@server1 ~]# mount /dev/md
[root@server1 ~]# df -h |tail -n 1
/dev/md1              572M   17M 526M   4% /fd


[root@server1 ~]# tune2fs -l /dev/md1
tune2fs 1.39 (29-May-2006)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          2562dfa7-e3b6-4086-8755-aa0350e770de
Filesystem magic number: 0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal resize_inode dir_index filetype needs_recovery sparse_super large_file


[root@server1 ~]# mdadm –detail /dev/md1
/dev/md1:
        Version : 00.90.03
    Number   Major   Minor   RaidDevice State
       0       8       22        0      active sync   /dev/sdb6
       1       8       23        1      active sync   /dev/sdb7
       2       8       24        2      active sync   /dev/sdb8


       3       8       25        –      spare   /dev/sdb9

赞(0) 打赏
转载请注明出处:服务器评测 » RHEL5 Swap,ext3,lvm及raid5磁盘管理
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏

登录

注册