linux扩容(根分区 与 普通分区)

根分区

[root@localhost ~]# cd /sys/class/scsi_host
[root@localhost scsi_host]# ls
host0  host1  host2
[root@localhost scsi_host]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@localhost scsi_host]# echo "- - -" > /sys/class/scsi_host/host1/scan
[root@localhost scsi_host]# echo "- - -" > /sys/class/scsi_host/host2/scan

找到新加的盘 /dev/sdg

[root@localhost scsi_host]# pvs
  PV         VG     Fmt  Attr PSize   PFree
  /dev/sda3  rootvg lvm2 a--  291.88G    0 
  /dev/sdb   rootvg lvm2 a--  299.97G    0 
  /dev/sdd   rootvg lvm2 a--  303.97G    0 
  /dev/sde1  rootvg lvm2 a--  500.97G    0 
  /dev/sdf1  rootvg lvm2 a--  501.97G    0 


[root@localhost scsi_host]# vgs
  VG     #PV #LV #SN Attr   VSize VFree
  rootvg   5   1   0 wz--n- 1.85T    0 


[root@localhost scsi_host]# df -Th
文件系统      类型    容量  已用 可用 已用% 挂载点
/dev/mapper/rootvg-rootlv01
              ext3    1.8T  1.5T  215G  88% /
/dev/sda1     ext3    190M   25M  156M  14% /boot
tmpfs        tmpfs    7.9G  4.7G  3.3G  59% /dev/shm


[root@localhost scsi_host]# lvs
  LV       VG     Attr   LSize Origin Snap%  Move Log Copy%  Convert
  rootlv01 rootvg -wi-ao 1.85T                                      
[root@localhost scsi_host]# fdisk /dev/sdg
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.
The number of cylinders for this disk is set to 26108.
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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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

Command (m for help): p

Disk /dev/sdg: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdg1               1       26108   209712478+  83  Linux

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): w
The partition table has been altered!

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


[root@localhost scsi_host]# fdisk -l /dev/sdg

Disk /dev/sdg: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdg1               1       26108   209712478+  8e  Linux LVM


[root@localhost scsi_host]# pvcreate /dev/sdg1
  Writing physical volume data to disk "/dev/sdg1"
  Physical volume "/dev/sdg1" successfully created


[root@localhost scsi_host]# pvs
  PV         VG     Fmt  Attr PSize   PFree  
  /dev/sda3  rootvg lvm2 a--  291.88G      0 
  /dev/sdb   rootvg lvm2 a--  299.97G      0 
  /dev/sdd   rootvg lvm2 a--  303.97G      0 
  /dev/sde1  rootvg lvm2 a--  500.97G      0 
  /dev/sdf1  rootvg lvm2 a--  501.97G      0 
  /dev/sdg1         lvm2 a--  200.00G 200.00G


[root@localhost scsi_host]# vgextend rootvg /dev/sdg1
  Volume group "rootvg" successfully extended


[root@localhost scsi_host]# vgs
  VG     #PV #LV #SN Attr   VSize VFree  
  rootvg   6   1   0 wz--n- 2.05T 199.97G


[root@localhost scsi_host]# lvs
  LV       VG     Attr   LSize Origin Snap%  Move Log Copy%  Convert
  rootlv01 rootvg -wi-ao 1.85T                                      

[root@localhost scsi_host]# lvextend -L +200G /dev/rootvg/rootlv01       (/dev/VG名/LV名)
  Extending logical volume rootlv01 to 2.05 TB
  Insufficient free space: 6400 extents needed, but only 6399 available


[root@localhost scsi_host]# lvextend -l +6399 /dev/rootvg/rootlv01      
  Extending logical volume rootlv01 to 2.05 TB
  Logical volume rootlv01 successfully resized


[root@localhost scsi_host]# lvs
  LV       VG     Attr   LSize Origin Snap%  Move Log Copy%  Convert
  rootlv01 rootvg -wi-ao 2.05T                                     


[root@localhost scsi_host]# df -Th
文件系统      类型    容量  已用 可用 已用% 挂载点
/dev/mapper/rootvg-rootlv01
              ext3    1.8T  1.5T  215G  88% /
/dev/sda1     ext3    190M   25M  156M  14% /boot
tmpfs        tmpfs    7.9G  4.7G  3.3G  59% /dev/shm


[root@localhost scsi_host]# resize2fs /dev/rootvg/rootlv01 
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/rootvg/rootlv01 is mounted on /; on-line resizing required
hyPerforming an on-line resize of /dev/rootvg/rootlv01 to 550166528 (4k) blocks.
hyThe filesystem on /dev/rootvg/rootlv01 is now 550166528 blocks long.

[root@localhost scsi_host]# df -Th
文件系统      类型    容量  已用 可用 已用% 挂载点
/dev/mapper/rootvg-rootlv01
              ext3    2.0T  1.5T  399G  80% /
/dev/sda1     ext3    190M   25M  156M  14% /boot
tmpfs        tmpfs    7.9G  4.7G  3.3G  59% /dev/shm

-----------------------------------------------------------------------------------------------------------

普通分区

在线扫磁盘

[root@localhost-in ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@localhost-in ~]# echo "- - -" > /sys/class/scsi_host/host1/scan
[root@localhost-in ~]# echo "- - -" > /sys/class/scsi_host/host2/scan

fdisk -l 找到新加盘为/dev/sdh

[root@localhost-in ~]# pvs
  PV         VG      Fmt  Attr PSize   PFree
  /dev/sda3  rootvg  lvm2 a--  291.88G    0 
  /dev/sdb   vg_data lvm2 a--  300.00G    0 
  /dev/sdd   vg_data lvm2 a--  304.00G    0 
  /dev/sde1  vg_data lvm2 a--  499.99G    0 
  /dev/sdf1  rootvg  lvm2 a--  100.97G    0 
  /dev/sdg1  vg_data lvm2 a--  501.99G    0 


[root@localhost-in ~]# fdisk /dev/sdh
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.
The number of cylinders for this disk is set to 26108.
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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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

Command (m for help): p

Disk /dev/sdh: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdh1               1       26108   209712478+  83  Linux

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): w
The partition table has been altered!

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


[root@localhost-in ~]# pvs
  PV         VG      Fmt  Attr PSize   PFree
  /dev/sda3  rootvg  lvm2 a--  291.88G    0 
  /dev/sdb   vg_data lvm2 a--  300.00G    0 
  /dev/sdd   vg_data lvm2 a--  304.00G    0 
  /dev/sde1  vg_data lvm2 a--  499.99G    0 
  /dev/sdf1  rootvg  lvm2 a--  100.97G    0 
  /dev/sdg1  vg_data lvm2 a--  501.99G    0 


[root@localhost-in ~]# pvcreate /dev/sdh1
  Writing physical volume data to disk "/dev/sdh1"
  Physical volume "/dev/sdh1" successfully created


[root@localhost-in ~]# pvs
  PV         VG      Fmt  Attr PSize   PFree  
  /dev/sda3  rootvg  lvm2 a--  291.88G      0 
  /dev/sdb   vg_data lvm2 a--  300.00G      0 
  /dev/sdd   vg_data lvm2 a--  304.00G      0 
  /dev/sde1  vg_data lvm2 a--  499.99G      0 
  /dev/sdf1  rootvg  lvm2 a--  100.97G      0 
  /dev/sdg1  vg_data lvm2 a--  501.99G      0 
  /dev/sdh1          lvm2 a--  200.00G 200.00G


[root@localhost-in ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  rootvg    2   1   0 wz--n- 392.84G    0 
  vg_data   4   1   0 wz--n-   1.57T    0 


[root@localhost-in ~]# df -Th
文件系统      类型    容量  已用 可用 已用% 挂载点
/dev/mapper/rootvg-rootlv01
              ext3    381G  250G  112G  70% /
/dev/sda1     ext3    190M   25M  156M  14% /boot
tmpfs        tmpfs    7.9G  4.9G  3.0G  62% /dev/shm
/dev/mapper/vg_data-lv_data
              ext4    1.6T  1.3T  252G  84% /data
/dev/sr0   iso9660    2.8G  2.8G     0 100% /mnt/cdrom


[root@localhost-in ~]# vgextend vg_data /dev/sdh1
  Volume group "vg_data" successfully extended


[root@localhost-in ~]# lvs
  LV       VG      Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  rootlv01 rootvg  -wi-ao 392.84G                                      
  lv_data  vg_data -wi-ao   1.57T                            

         
[root@localhost-in ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree  
  rootvg    2   1   0 wz--n- 392.84G      0 
  vg_data   5   1   0 wz--n-   1.76T 200.00G


[root@localhost-in ~]# lvextend -l +6399 /dev/vg_data/lv_data 
  Extending logical volume lv_data to 1.59 TB
  Logical volume lv_data successfully resized


[root@localhost-in ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree  
  rootvg    2   1   0 wz--n- 392.84G      0 
  vg_data   5   1   0 wz--n-   1.76T 175.00G


[root@localhost-in ~]# lvextend -L +175G /dev/vg_data/lv_data         
  Extending logical volume lv_data to 1.76 TB
  Logical volume lv_data successfully resized


[root@localhost-in ~]# vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  rootvg    2   1   0 wz--n- 392.84G    0 
  vg_data   5   1   0 wz--n-   1.76T    0 


[root@localhost-in ~]# lvs
  LV       VG      Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  rootlv01 rootvg  -wi-ao 392.84G                                      
  lv_data  vg_data -wi-ao   1.76T                                  

   
[root@localhost-in ~]# resize2fs /dev/vg_data/lv_data 
resize2fs 1.39 (29-May-2006)
resize2fs: Filesystem has unsupported feature(s) while trying to open /dev/vg_data/lv_data
Couldn't find valid filesystem superblock.


[root@localhost-in ~]# resize4fs /dev/vg_data/lv_data 
resize4fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_data/lv_data is mounted on /data; on-line resizing required
old desc_blocks = 101, new_desc_blocks = 113

你可能感兴趣的:(linux)