为邮箱空间设置LVM逻辑卷管理的实验过程

1、关闭服务器,打开机箱,挂接2快SCSI新硬盘。

2、开启服务器,执行“fdisk -l” 命令进行检查,确认已识别新增的硬盘(sdb、sdc)

[root@localhost ~]# 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          38      305203+  83  Linux
/dev/sda2              39        1950    15358140   83  Linux
/dev/sda3            1951        3225    10241437+  83  Linux
/dev/sda4            3226       10443    57978585    5  Extended
/dev/sda5            3226        3862     5116671   83  Linux
/dev/sda6            3863        4499     5116671   83  Linux
/dev/sda7            4500        4630     1052226   82  Linux swap / Solaris

Disk /dev/sdb: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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

Disk /dev/sdc: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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

3、在新磁盘进行分区,将每块硬盘所有空间划分为一个独立的主分区,并将分区类型更改为“8e”。分好区后使用“fdisk -l”命令查看结果。

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

The number of cylinders for this disk is set to 10443.
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/sdb: 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

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p

Partition number (1-4): 1
First cylinder (1-10443, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-10443, default 10443): 
Using default value 10443

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

Command (m for help): p

Disk /dev/sdb: 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/sdb1               1       10443    83883366   8e  Linux LVM

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

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

[root@localhost ~]# partprobe /dev/sdb(重新探测磁盘分区)

sdc磁盘同上!

Command (m for help): p

Disk /dev/sdc: 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/sdc1               1       10443    83883366   8e  Linux LVM


[root@localhost ~]# 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          38      305203+  83  Linux
/dev/sda2              39        1950    15358140   83  Linux
/dev/sda3            1951        3225    10241437+  83  Linux
/dev/sda4            3226       10443    57978585    5  Extended
/dev/sda5            3226        3862     5116671   83  Linux
/dev/sda6            3863        4499     5116671   83  Linux
/dev/sda7            4500        4630     1052226   82  Linux swap / Solaris

Disk /dev/sdb: 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/sdb1               1       10443    83883366   8e  Linux LVM

Disk /dev/sdc: 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/sdc1               1       10443    83883366   8e  Linux LVM

4、将“/dev/sdb1”和“/dev/sdc1”分区转换为物理卷

[root@localhost ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

[root@localhost ~]# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created

5、将上述两个物理卷整合,创建名为“mail_store”的卷组

[root@localhost ~]# pvscan
  PV /dev/sdb1                      lvm2 [80.00 GB]
  PV /dev/sdc1                      lvm2 [80.00 GB]
  Total: 2 [159.99 GB] / in use: 0 [0   ] / in no VG: 2 [159.99 GB]

[root@localhost ~]# vgcreate mail_store /dev/sdb1 /dev/sdc1
  Volume group "mail_store" successfully created

6、在“mail_store”卷组中创建一个名为“mail”的逻辑卷,容量大小设置为60G

[root@localhost ~]# vgscan | grep "mail_store"
  Found volume group "mail_store" using metadata type lvm2

[root@localhost ~]# lvcreate -L 60G -n mail mail_store
  Logical volume "mail" created

7、使用mkfs命令为在“mail”逻辑卷中创建EXT3文件系统,并挂载到“/mail”目录下

[root@localhost ~]# mkfs -t ext3 /dev/mail_store/mail 
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
7864320 inodes, 15728640 blocks
786432 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
480 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424

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

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

[root@localhost ~]# mkdir /mail

[root@localhost ~]# mount /dev/mail_store/mail /mail

[root@localhost ~]# df -hT /mail/
文件系统      类型    容量  已用 可用 已用% 挂载点
/dev/mapper/mail_store-mail
              ext3     60G  180M   56G   1% /mail

8、动态扩展“mail”逻辑卷的容量(增加20G),并更新系统识别的文件系统大小

[root@localhost ~]# lvextend -L +20G /dev/mail_store/mail 
  Extending logical volume mail to 80.00 GB
  Logical volume mail successfully resized

[root@localhost ~]# resize2fs /dev/mail_store/mail 
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mail_store/mail is mounted on /mail; on-line resizing required
Performing an on-line resize of /dev/mail_store/mail to 20971520 (4k) blocks.
The filesystem on /dev/mail_store/mail is now 20971520 blocks long.

9、实验完成

10、命令总结

功能              物理卷管理        卷组管理        逻辑卷管理
scan(扫描)        pvscan            vgscan          lvscan
create(建立)      pvcreate          vgcreate        lvcreate
display(显示)     pvdisplay         vgdisplay       lvdisplay
remove(删除)      pvremove          vgremove        lvremove
extend(扩展)                        vgextend        lvextend
redace(缩减)                        vgredace        lvredace

你可能感兴趣的:(linux,lvm逻辑卷管理)