首页 > 代码库 > linux根目录扩容

linux根目录扩容

1、查看新添加的磁盘,如下: /dev/sde为新添加磁盘
 
可用如下脚本进行扫描
echo ‘ - - - ‘ > /sys/class/scsi_host/host0/scan
 
[root@rac01 ~]# 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: 0x00028c6a
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        2611    20765696   8e  Linux LVM
 
Disk /dev/sde: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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_rac01-LogVol01: 12.7 GB, 12670992384 bytes
255 heads, 63 sectors/track, 1540 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_rac01-LogVol00: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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
 
2、对磁盘进行分区,将其划分为一个主分区,并创建PV
[root@rac01 ~]# fdisk /dev/sde
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x6751fd38.
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 #n为新建一个分区
Command action
   e   extended
   p   primary partition (1-4)
p #p为新建一个primary partition,即主分区
Partition number (1-4):
Value out of range.
Partition number (1-4): 1 #分区序号为1
First cylinder (1-1044, default 1): #默认从第一个柱面开始
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): #默认到最后一个柱面结束
Using default value 1044
 
Command (m for help): t #改变分区格式为8e 即Linux LVM逻辑卷格式
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.
 
3、查看创建情况
[root@rac01 ~]# 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: 0x00028c6a
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        2611    20765696   8e  Linux LVM
 
Disk /dev/sde: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x6751fd38
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1        1044     8385898+  8e  Linux LVM
 
Disk /dev/mapper/vg_rac01-LogVol01: 12.7 GB, 12670992384 bytes
255 heads, 63 sectors/track, 1540 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_rac01-LogVol00: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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
 
4、创建物理卷组
[root@rac01 ~]# pvcreate /dev/sde1
  Physical volume "/dev/sde1" successfully created
[root@rac01 ~]# pvdisplay #查看物理卷组情况
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_rac01
  PV Size                  19.80 GiB / not usable 3.00 MiB
  Allocatable             yes (but full)
  PE Size                   4.00 MiB
  Total PE                 5069
  Free PE                  0
  Allocated PE          5069
  PV UUID               vHMLej-bAqh-yugI-UbFf-OyTC-31Yt-xouKeY
 
  "/dev/sde1" is a new physical volume of "8.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sde1
  VG Name               
  PV Size                  8.00 GiB
  Allocatable            NO
  PE Size                  0   
  Total PE                0
  Free PE                 0
  Allocated PE          0
  PV UUID               7axfPk-Xxfg-HWQS-gBjj-GD0Q-xFgU-e9apR7
 
5、查看物理卷组
[root@rac01 ~]# pvscan
  PV /dev/sda2   VG vg_rac01   lvm2 [19.80 GiB / 0    free]
  PV /dev/sde1                 lvm2 [8.00 GiB]
  Total: 2 [27.80 GiB] / in use: 1 [19.80 GiB] / in no VG: 1 [8.00 GiB]
 
6、扩展物理卷
[root@rac01 ~]# vgextend vg_rac01 /dev/sde1
  Volume group "vg_rac01" successfully extended
[root@rac01 ~]# vgdisplay
  --- Volume group ---
  VG Name                  vg_rac01
  System ID             
  Format                      lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access                read/write
  VG Status                 resizable
  MAX LV                    0
  Cur LV                      2
  Open LV                   2
  Max PV                    0
  Cur PV                     2
  Act PV                     2
  VG Size                    27.80 GiB
  PE Size                    4.00 MiB
  Total PE                   7116
  Alloc PE / Size        5069 / 19.80 GiB
  Free  PE / Size        2047 / 8.00 GiB
  VG UUID                z1Fila-7Cwx-8m9K-XQMG-UK4a-4iLq-kibPv2
 
7、查看逻辑卷
[root@rac01 ~]# lvdisplay 
  --- Logical volume ---
  LV Path                  /dev/vg_rac01/LogVol01
  LV Name                LogVol01
  VG Name               vg_rac01
  LV UUID                mnT2Gu-OfUY-sBvc-mbU3-P1gZ-BJcC-S1QXcl
  LV Write Access        read/write
  LV Creation host, time rac01, 2017-03-07 14:40:50 +0800
  LV Status               available
  # open                   1
  LV Size                   11.80 GiB
  Current LE             3021
  Segments               1
  Allocation                inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
 
  --- Logical volume ---
  LV Path                  /dev/vg_rac01/LogVol00
  LV Name                LogVol00
  VG Name                vg_rac01
  LV UUID                 OJGG6E-dGBl-RBWB-pWcH-Utu2-sT3i-kvVt9k
  LV Write Access        read/write
  LV Creation host, time rac01, 2017-03-07 14:40:55 +0800
  LV Status               available
  # open                   1
  LV Size                   8.00 GiB
  Current LE              2048
  Segments                1
  Allocation                inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
 
9、查看情况
[root@rac01 ~]# vgs
  VG       #PV #LV #SN Attr   VSize  VFree
  vg_rac01   2   2   0 wz--n- 27.80g 8.00g
[root@rac01 ~]# lvs
  LV       VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  LogVol00 vg_rac01 -wi-ao----  8.00g                                                   
  LogVol01 vg_rac01 -wi-ao---- 11.80g    
 
10、扩展逻辑卷 全部扩展                                             
[root@rac01 ~]# lvextend -l +100%FREE /dev/mapper/vg_rac01-LogVol01
  Size of logical volume vg_rac01/LogVol01 changed from 11.80 GiB (3021 extents) to 19.80 GiB (5068 extents).
  Logical volume LogVol01 successfully resized
 
 
[root@rac01 ~]# vgs
  VG       #PV #LV #SN Attr   VSize  VFree
  vg_rac01   2   2   0 wz--n- 27.80g    0
[root@rac01 ~]# lvs
  LV       VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  LogVol00 vg_rac01 -wi-ao----  8.00g                                                   
  LogVol01 vg_rac01 -wi-ao---- 19.80g                                                   
 
[root@rac01 ~]# resize2fs /dev/mapper/vg_rac01-LogVol01
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_rac01-LogVol01 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/mapper/vg_rac01-LogVol01 to 5189632 (4k) blocks.
The filesystem on /dev/mapper/vg_rac01-LogVol01 is now 5189632 blocks long.

linux根目录扩容