linuxディスクとファイルシステム管理(三)


LinuxシステムのLVMディスクは、オンライン拡張を容易に実現できます.LVMディスクのオンライン拡張に関する具体的な手順を簡単に説明します.
物理サーバがディスク容量拡張を行うには、まずサーバの空きスロットに新しいハードディスクを挿入し、対応するraidモードを構成し、サーバを起動した後、次の手順を参照して容量拡張を行う必要があります.
ESXi仮想マシンで容量拡張が必要な場合は、Vcenterまたはvphere clientを使用して仮想マシンに適切なサイズの仮想ディスクを追加する必要があります.新しいlinuxカーネルバージョンの場合、新しいディスクはfdisk-lコマンドで直接認識できます.古いカーネルバージョンの場合、認識するにはシステムを再起動する必要があります.
次の手順は、fdisk-lが新しいディスクを認識できるようになった場合に実行します.
まずdf-hコマンドを実行し、拡張するlvmパーティションのボリュームグループと論理ボリューム情報を確認します.以下の例では、ルートパーティションを拡張する予定であり、ルートパーティションが存在するボリュームグループはVolGroup 00であり、対応する論理ボリュームはLogVol 00である.
[root@idca-wx-web2 ~]# df -h
                              %    
/dev/mapper/VolGroup00-LogVol00
                       42G   13G   28G  31% /
/dev/sda1              99M   17M   78M  18% /boot
tmpfs                 7.9G     0  7.9G   0% /dev/shm

次に、新しいディスクの識別子を確認します.たとえば、/dev/sdcです.一般的に、新しいディスクはフォーマットされておらず、/dev/sdc 1のような物理パーティションは存在しません.もちろん、新しいディスクを追加する前にfdisk-lでチェックし、ディスクを追加してから比較すると信頼性が高くなります.また、oracleデータベースサーバでは、ASMデータディスクとして裸ディスクが使用されているディスクもあり、/dev/sdc 1のような物理パーティションもありません.フォーマットを行う前に、誤操作を避けるために、必ず確認してください.
[root@idca-wx-web2 ~]# fdisk -l
 
Disk /dev/sda: 108 MB, 108134400 bytes
4 heads, 32 sectors/track, 1650 cylinders
Units = cylinders of 128 * 512 = 65536 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           2        1633      104448   83  Linux
 
Disk /dev/sdb: 57.9 GB, 57987432448 bytes
196 heads, 58 sectors/track, 9962 cylinders
Units = cylinders of 11368 * 512 = 5820416 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        9963    56627200   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
 
Disk /dev/sdc doesn't contain a valid partition table

/dev/sdcがルートパーティションを拡張するために新しく追加されたディスクであることを確認したら、まずディスクをフォーマットし、物理ボリュームを作成することをお勧めします.物理ボリュームを直接作成することもできますが、後で使用中に問題が発生する可能性があります.
[root@idca-wx-web2 ~]# fdisk /dev/sdc
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 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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
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
 
Command (m for help): n           # :     
Command action
   e   extended
   p   primary partition (1-4)
p                               # :       
Partition number (1-4): 1            # :     ,      ,                   ,       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): p        # :       ,       ,       /dev/sdc1      。   Id  83,   Linux    
 
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   83  Linux
 
Command (m for help): t         # :    Id
Selected partition 1            
Hex code (type L to list codes): 8e   # :   LVM   Id,    L    Id  
Changed system type of partition 1 to 8e (Linux LVM)
 
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
 
Command (m for help): w        # :     ,       ,           ,      ,      
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.

フォーマットが完了したら、以下でLVM関連操作を開始します.まず、先ほどフォーマットされた物理パーティション/dev/sdc 1に物理ボリュームを作成します.物理ボリュームの作成前後にpvsコマンドを実行すると、物理ボリュームの作成前後の変化を確認できます.
[root@idca-wx-web2 ~]# pvcreate /dev/sdc1
  dev_is_mpath: failed to get device for 8:33
  Writing physical volume data to disk "/dev/sdc1"
  Physical volume "/dev/sdc1" successfully created
[root@idca-wx-web2 ~]# pvs
  PV         VG         Fmt  Attr PSize  PFree
  /dev/sdb1  VolGroup00 lvm2 a--  54.00G     0
  /dev/sdc1             lvm2 a--  80.00G 80.00G

作成した物理ボリュームを既存のボリュームグループに追加し、ボリュームグループの容量を拡張します.複数のボリュームグループがある場合は、df-hコマンドの結果を参照して特定のボリュームグループ名を決定します.拡張ボリュームグループの前後にvgsコマンドを実行し、ボリュームグループの拡張前後の変化を比較します.
[root@idca-wx-web2 ~]# vgs
  VG         #PV #LV #SN Attr   VSize  VFree
  VolGroup00   1   2   0 wz--n- 54.00G    0
[root@idca-wx-web2 ~]# vgextend VolGroup00 /dev/sdc1
  Volume group "VolGroup00" successfully extended
[root@idca-wx-web2 ~]# vgs
  VG         #PV #LV #SN Attr   VSize   VFree
  VolGroup00   2   2   0 wz--n- 134.00G 80.00G

拡張ボリュームグループ内の論理ボリューム.ボリュームグループ内に複数の論理ボリュームがある場合は、df-hコマンドの結果を参照して特定の論理ボリューム名を決定します.拡張論理ボリュームの前後にlvsコマンドを実行し、論理ボリュームの拡張前後の変化を比較する.
[root@idca-wx-web2 ~]# lvs
  LV       VG         Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  LogVol00 VolGroup00 -wi-ao 50.00G
  LogVol01 VolGroup00 -wi-ao  4.00G
[root@idca-wx-web2 ~]# lvextend -l +100%FREE /dev/mapper/VolGroup00-LogVol00
  Extending logical volume LogVol00 to 130.00 GB
  Logical volume LogVol00 successfully resized
[root@idca-wx-web2 ~]# lvs
  LV       VG         Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  LogVol00 VolGroup00 -wi-ao 130.00G
  LogVol01 VolGroup00 -wi-ao   4.00G

論理ボリュームが拡張されると、論理ボリュームの容量は変化しません.resize 2 fsコマンドを実行して、ファイルシステムの容量と論理ボリュームの容量を一致させる必要があります.コマンドの実行前後にdf-hコマンドを実行し、ファイルシステムの容量の変化を比較することが望ましい.
[root@idca-wx-web2 ~]# resize2fs /dev/VolGroup00/LogVol00  #       xfs  ,   xfs_growfs  
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing require                                  d
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 34077696 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 34077696 blocks long.
 
[root@idca-wx-web2 ~]# df -h
                              %    
/dev/mapper/VolGroup00-LogVol00
                      109G   13G   91G  12% /
/dev/sda1              99M   17M   78M  18% /boot
tmpfs                 7.9G     0  7.9G   0% /dev/shm