Linux 邏輯卷root分區擴展

原 : 20g 磁盤 使用centos默認分區 建立的邏輯卷信息以下

   pvshell

[root@test ~]# pvs
  PV         VG        Fmt  Attr PSize  PFree 
  /dev/sda2  vg_centos lvm2 a--  19.51g     0

  vgcentos

[root@test ~]# vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  vg_centos   1   2   0 wz--n- 19.51g    0

   lvapp

[root@test ~]# lvs
  LV      VG        Attr      LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root vg_centos -wi-ao--- 17.57g                                             
  lv_swap vg_centos -wi-ao---  1.94g


   添加一塊20g新磁盤後擴展root分區ide

   操做以下ui

查看新添磁盤

[root@test ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c3d64
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_centos-lv_root: 18.9 GB, 18865979392 bytes
255 heads, 63 sectors/track, 2293 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_centos-lv_swap: 2080 MB, 2080374784 bytes
255 heads, 63 sectors/track, 252 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


對新添磁盤分區(使用全部空間也可直接使用整個磁盤 不用分區)

[root@test ~]# fdisk /dev/sdb 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xb996e29b.
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)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
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, +cylinders or +size{K,M,G} (1-2610, default 2610): 
Using default value 2610
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

  

添加新加磁盤爲pv

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

擴展vg_centos

[root@test ~]# vgextend vg_centos /dev/sdb1
  Volume group "vg_centos" successfully extended

擴展lv_root

[root@test ~]# lvextend -l +100%FREE /dev/vg_centos/lv_root 
  Extending logical volume lv_root to 37.56 GiB
  Logical volume lv_root successfully resized

查看lv

[root@test ~]# lvs
  LV      VG        Attr      LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root vg_centos -wi-ao--- 37.56g                                             
  lv_swap vg_centos -wi-ao---  1.94g

查看根分區所剩空間

[root@test ~]# df -h
文件系統      容量  已用  可用 已用%% 掛載點
/dev/mapper/vg_centos-lv_root
                       18G  1.1G   16G   7% /
tmpfs                 932M     0  932M   0% /dev/shm
/dev/sda1             485M   32M  428M   7% /boot

  發現跟分區未變大 使用resize2fs 識別新添空間(適用於ext系統文件)spa

[root@test ~]# resize2fs /dev/mapper/vg_centos-lv_root 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_centos-lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/mapper/vg_centos-lv_root to 9846784 (4k) blocks.
The filesystem on /dev/mapper/vg_centos-lv_root is now 9846784 blocks long.
[root@test ~]# df -h
文件系統      容量  已用  可用 已用%% 掛載點
/dev/mapper/vg_centos-lv_root
                       37G  1.1G   35G   3% /
tmpfs                 932M     0  932M   0% /dev/shm
/dev/sda1             485M   32M  428M   7% /boot

錯誤解決 

 對xfs分區使用resize2fs會出現如下錯誤.net

resize2fs: Bad magic number in super-block while trying to open /dev/mapper/vg_centos-lv_root 
Couldn't find valid filesystem superblock


  xfs文件系統使用xfs_growfs 加掛載路徑 進行擴展3d

xfs_growfs  /


   lvm 縮小:http://my.oschina.net/firxiao/blog/387397 
code

相關文章
相關標籤/搜索