GNU/Linux >> Linux の 問題 >  >> Linux

拡張パーティション内のLVMパーティションのサイズを変更する方法

Linuxで論理ボリュームのサイズを変更することはそれほど難しくなく、非常に簡単なアプローチで実現できます。通常の手順は次のとおりです。

  1. ハードディスクに新しいパーティションを作成します。
  2. 作成したパーティションを物理ボリュームとして追加します。
  3. 新しい物理ボリュームをボリュームグループに追加します。
  4. ボリュームグループから論理ボリュームにスペースを割り当てます。
  5. ファイルシステムのサイズを変更します。

ただし、このシナリオでは、ルートファイルシステム(LVMパーティションとして)がプライマリパーティション内ではなく、拡張パーティションの下にマウントされています。 / bootにマウントされているプラ​​イマリパーティションが1つだけあり、残りのすべてのスペースはその拡張パーティションの一部です。

面倒に聞こえますか?拡張パーティション内でLVMのサイズを変更する方法を紹介します。

拡張パーティション内のLVMパーティションのサイズ変更

このチュートリアルでは、仮想マシンにインストールされているLinuxを使用しています。

ディスクパーティションの取り扱いには十分注意する必要があることに注意してください。

ステップ1:VMをシャットダウンし、ディスクサイズを増やします

まず、VMをシャットダウンし、ディスクサイズを増やします。ここでは、ディスク/ dev/sdaのサイズを20GB増やして約40GBにしました。次に、VMを起動し、コンソールに移動します。

ディスクパーティションをご覧ください。

[email protected]:~# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a975f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758    41940991    20719617    5  Extended
/dev/sda5          501760    41940991    20719616   8e  Linux LVM

dfコマンドを使用してディスク領域を分析すると、次のように表示されます。

[email protected]:~# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  989M  4.0K  989M   1% /dev
tmpfs          tmpfs     201M  716K  200M   1% /run
/dev/dm-0      ext4       19G  1.5G   16G   9% /
none           tmpfs     4.0K     0  4.0K   0% /sys/fs/cgroup
none           tmpfs     5.0M     0  5.0M   0% /run/lock
none           tmpfs    1001M     0 1001M   0% /run/shm
none           tmpfs     100M     0  100M   0% /run/user
/dev/sda1      ext2      236M   40M  184M  18% /boot

ここでの目的は、/ dev/sda5にマウントされているパーティション/dev/dm-0のサイズを大きくすることです。

物理ボリューム、ボリュームグループ、および論理ボリュームの現在のステータスも表示します。

[email protected]:~# lvs
  LV     VG          Attr      LSize    Pool Origin Data%  Move Log Copy%  Convert
  root   ubuntu14-vg -wi-ao---   18.74g                                           
  swap_1 ubuntu14-vg -wi-ao--- 1020.00m   
  
[email protected]:~# pvs
  PV         VG          Fmt  Attr PSize  PFree 
  /dev/sda5  ubuntu14-vg lvm2 a--  19.76g 20.00m
  
[email protected]:~# vgs
  VG          #PV #LV #SN Attr   VSize  VFree 
  ubuntu14-vg   1   2   0 wz--n- 19.76g 20.00m

それらはすべて、約20GBのストレージスペースが割り当てられています。

ステップ2:LVMのサイズ変更プロセスを開始します

LVMパーティションのサイズを変更する手順は次のとおりです。

fdiskユーティリティを開き、パーティションを確認します。

[email protected]:~# fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a975f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758    41940991    20719617    5  Extended
/dev/sda5          501760    41940991    20719616   8e  Linux LVM

コマンドdを使用して、拡張パーティション(/ dev / sda2)を削除します 、/ dev/sda5である基礎となるLVMパーティションを自動的に削除します。

Command (m for help): d
Partition number (1-5): 2

コマンドnを使用して、拡張された新しいパーティションを再度作成します デフォルトの開始シリンダー値と終了シリンダー値を使用します。

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e
Partition number (1-4, default 2): 
Using default value 2
First sector (499712-83886079, default 499712): 
Using default value 499712
Last sector, +sectors or +size{K,M,G} (499712-83886079, default 83886079): 
Using default value 83886079

Command (m for help): p

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a975f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          499712    83886079    41693184    5  Extended

デフォルトの開始シリンダー値と終了シリンダー値を使用して、論理パーティション(dev / sda5)を作成します。

Command (m for help): n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (501760-83886079, default 501760): 
Using default value 501760
Last sector, +sectors or +size{K,M,G} (501760-83886079, default 83886079): 
Using default value 83886079

xを押して、エキスパートモードに切り替えます 。

Command (m for help): x

エキスパートコマンドbを実行します パーティションの開始を調整します(これにより、パーティションのサイズが変更され、終了する場所は変更されません)。パーティションを削除する前の開始値を以前と同じように入力します。こちらは501760です。

Expert command (m for help): b
Partition number (1-5): 5
New beginning of data (499713-83886079, default 501760): 501760

次に、rを実行します メインメニューに戻ります。

Expert command (m for help): r

念のため、パーティション番号を確認してください。

Command (m for help): p

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000a975f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          499712    83886079    41693184    5  Extended
/dev/sda5          501760    83886079    41692160   83  Linux

次に、tを押して、パーティションタイプをLVMに変更します。 コマンドを選択し、タイプ8eを選択しました 。

Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)

wを押します すべての変更をディスクに書き込みます。

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

ステップ3:物理ボリュームと論理ボリュームを手動で変更する

partprobeコマンドを実行して、パーティションテーブルの変更についてOSに通知します。

[email protected]:~# partprobe /dev/sda

lsblkコマンドを実行して、/ dev /sda5のサイズが約40GBになったことを確認します(私にとって)。

[email protected]:~# lsblk 
NAME                           MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                              8:0    0    40G  0 disk 
├─sda1                           8:1    0   243M  0 part /boot
├─sda2                           8:2    0     1K  0 part 
└─sda5                           8:5    0  39.8G  0 part 
  ├─ubuntu14--vg-root (dm-0)   252:0    0  18.8G  0 lvm  /
  └─ubuntu14--vg-swap_1 (dm-1) 252:1    0  1020M  0 lvm  [SWAP]
sr0                             11:0    1  1024M  0 rom  

dfコマンドを実行すると、/ dev/dm-0に古いサイズの詳細が引き続き表示されます。

[email protected]:~# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  989M  4.0K  989M   1% /dev
tmpfs          tmpfs     201M  716K  200M   1% /run
/dev/dm-0      ext4       19G  1.5G   16G   9% /
none           tmpfs     4.0K     0  4.0K   0% /sys/fs/cgroup
none           tmpfs     5.0M     0  5.0M   0% /run/lock
none           tmpfs    1001M     0 1001M   0% /run/shm
none           tmpfs     100M     0  100M   0% /run/user
/dev/sda1      ext2      236M   40M  184M  18% /boot

物理ボリューム、ボリュームグループ、および論理ボリュームの場合も同様です。

[email protected]:~# lvs
  LV     VG          Attr      LSize    Pool Origin Data%  Move Log Copy%  Convert
  root   ubuntu14-vg -wi-ao---   18.74g                                           
  swap_1 ubuntu14-vg -wi-ao--- 1020.00m   
  
[email protected]:~# pvs
  PV         VG          Fmt  Attr PSize  PFree 
  /dev/sda5  ubuntu14-vg lvm2 a--  19.76g 20.00m
  
[email protected]:~# vgs
  VG          #PV #LV #SN Attr   VSize  VFree 
  ubuntu14-vg   1   2   0 wz--n- 19.76g 20.00m

ここでは手動で作業する必要があります。

物理ボリュームのサイズを変更します:

[email protected]:~# pvresize /dev/sda5 
Physical volume "/dev/sda5" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

次に、物理ボリュームとボリュームグループのステータスを確認し、新しいサイズが正しく表示されていることを確認します。

[email protected]:~# pvs
PV         VG          Fmt  Attr PSize  PFree 
/dev/sda5  ubuntu14-vg lvm2 a--  39.76g 20.02g

[email protected]:~# vgs
VG          #PV #LV #SN Attr   VSize  VFree 
ubuntu14-vg   1   2   0 wz--n- 39.76g 20.02g

同様に、論理ボリュームのサイズを変更します:

[email protected]:~# lvextend -l +100%FREE /dev/ubuntu14-vg/root
  Extending logical volume root to 38.76 GiB
  Logical volume root successfully resized

最後に、ファイルシステムのサイズを変更します:

[email protected]:~# resize2fs /dev/ubuntu14-vg/root
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/ubuntu14-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/ubuntu14-vg/root is now 10161152 blocks long.

ディスクのステータスを確認し、LVMのサイズが適切に変更されていることを確認します。

[email protected]:~# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  989M  4.0K  989M   1% /dev
tmpfs          tmpfs     201M  716K  200M   1% /run
/dev/dm-0      ext4       39G  1.5G   35G   4% /
none           tmpfs     4.0K     0  4.0K   0% /sys/fs/cgroup
none           tmpfs     5.0M     0  5.0M   0% /run/lock
none           tmpfs    1001M     0 1001M   0% /run/shm
none           tmpfs     100M     0  100M   0% /run/user
/dev/sda1      ext2      236M   40M  184M  18% /boot

それで全部です!拡張パーティション内のLVMパーティションのサイズが正常に変更されました。

質問や提案?以下にコメントを残してください。


Linux
  1. Linuxでディスクをパーティション分割する方法

  2. GPartedを使用してパーティションを簡単に作成およびサイズ変更する方法

  3. Lvmパーティション/物理ボリューム>2tbを作成する方法は?

  1. 未割り当てから拡張にスペースを追加するにはどうすればよいですか?

  2. Linux で fdisk を使用してディスクをパーティション分割する方法

  3. Linux で LVM スワップ パーティションを拡張する方法

  1. ループバック デバイス内にパーティションを作成する方法

  2. CentOS / RHEL :LVM のボリューム グループ (VG) に物理ボリューム (PV) を追加する方法

  3. Linux / UNIX :fdisk を使用して拡張パーティションを作成する方法