Linux上扩展磁盘空间

Linux上如何扩展磁盘?
有两种情况:
1、当有一个空间充足的盘时,可以直接使用fdisk -m来将磁盘分区,然后格式化,最后mount使用即可
[root@cimdb:/dev] fdisk /dev/sdb
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): 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)
   
================================================================================================
2、当每个磁盘空间较小,现在需要将这些小盘组合成一个大的空间来使用,需要使用到逻辑卷组管理来将这些小盘空间拼接在一起
假设现在有/dev/sdb  1G ,/dev/sdc 1G ,/dev/sdd 1G ,/dev/sde 2G ,/dev/sdf 10G盘已经划好,需要使用lvm 来管理。
[root@cimdb:~] fdisk -l 查看系统中有哪些盘没有分区
[root@cimdb:~] pvcreate /dev/sdb  将/dev/sdb 创建成一个物理卷
 Writing physical volume data to disk "/dev/sdb"
  Physical volume "/dev/sdb" successfully created
[root@cimdb:~] pvdisplay  查看系统中的物理卷信息
  "/dev/asm-diskb" is a new physical volume of "1.00 GB"
  --- NEW Physical volume ---
  PV Name               /dev/asm-diskb
  VG Name               
  PV Size               1.00 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               FlLxh4-PGff-Yoqd-SfKE-vKHe-iDLx-7rxQaE
   
[root@cimdb:~] vgcreate VolGroup00 /dev/sdb 创建一个物理卷组VolGroup00
  Volume group "VolGroup00" successfully created
[root@cimdb:~] vgdisplay  查看系统中的物理卷组信息
  --- Volume group ---
  VG Name               VolGroup00
  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               1024.00 MB
  PE Size               4.00 MB
  Total PE              255
  Alloc PE / Size       0 / 0   
  Free  PE / Size       255 / 1024.00 MB
  VG UUID               Ar3Ono-eb6V-6otn-SDm3-wqSR-4cif-1SS6nA
[root@cimdb:~] pvcreate /dev/sdc              将/dev/sdc 创建成一个物理卷
  Writing physical volume data to disk "/dev/asm-diskd"
  Physical volume "/dev/asm-diskd" successfully created
[root@cimdb:~] vgextend VolGroup00 /dev/sdc   对物理卷组进行扩展
  Volume group "VolGroup00" successfully extended
  
[root@cimdb:~] pvcreate /dev/sdd              将/dev/sdd 创建成一个物理卷
  Writing physical volume data to disk "/dev/asm-diskd"
  Physical volume "/dev/asm-diskd" successfully created
[root@cimdb:~] vgextend VolGroup00 /dev/sdd   对物理卷组进行扩展
  Volume group "VolGroup00" successfully extended
  
[root@cimdb:~] pvcreate /dev/sde              将/dev/sde 创建成一个物理卷
  Writing physical volume data to disk "/dev/asm-diskf"
  Physical volume "/dev/asm-diskf" successfully created
[root@cimdb:~] vgextend VolGroup00 /dev/sde   对物理卷组进行扩展
  Volume group "VolGroup00" successfully extended
  
[root@cimdb:~] pvcreate /dev/sdf              将/dev/sdf 创建成一个物理卷
  Writing physical volume data to disk "/dev/asm-diskf"
  Physical volume "/dev/asm-diskf" successfully created
[root@cimdb:~] vgextend VolGroup00 /dev/sdf   对物理卷组进行扩展
  Volume group "VolGroup00" successfully extended
  
[root@cimdb:~] vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        7
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                7
  Act PV                7
  VG Size               15.00 GB
  PE Size               4.00 MB
  Total PE              7929
  Alloc PE / Size       0 / 0   
  Free  PE / Size       7929 / 15.00 GB
  VG UUID               Ar3Ono-eb6V-6otn-SDm3-wqSR-4cif-1SS6nA
  
[root@cimdb:~] lvcreate -L 15G -n Logvol00 VolGroup00  从物理卷组VolGroup00中分配15G的容量来创建一个逻辑卷,供系统使用
  Logical volume "Logvol00" created
[root@cimdb:~] lvdisplay     查看逻辑卷的信息
  --- Logical volume --- 
  LV Name                /dev/VolGroup00/Logvol00
  VG Name                VolGroup00
  LV UUID                JxbpLG-dK3A-EvzE-cJOP-mpoD-OXEf-8cEwDq
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                15.00 GB
  Current LE             7680
  Segments               7
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  
[root@cimdb:/dev/VolGroup00] mkfs.ext2 /dev/VolGroup00/Logvol00  使用mkfs.ext来格式化逻辑卷
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
3932160 inodes, 7864320 blocks
393216 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
240 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


Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done


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


[root@cimdb:/] mount /dev/mapper/VolGroup00-Logvol00 /u01    将刚才添加的逻辑卷挂载在/u01目录下,供系统调用
[root@cimdb:/] df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             5.9G  3.6G  2.0G  66% /
/dev/sda6             2.0G   36M  1.9G   2% /tmp
/dev/sda3             9.7G  1.2G  8.0G  13% /home
/dev/sda2              30G   26G  1.8G  94% /oracle
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/mapper/VolGroup00-Logvol00      15G   44M   28G   1% /u01       ---已经挂载OK
============================================================================================================
卸载之前挂载的目录:
[root@cimdb:/] umount -l /u01 

你可能感兴趣的:(Linux)