LV拡張のメモ(さくらのクラウド)

 
ルート(/)のサイズを20GBから40GBに拡張。Ubuntu Linux OS。
LVMを使用しているので、概念の把握が難しい。

多くの場合、PVがディスク装置と1対1に対応し、LVがマウントポイントに対応する。

 VG
 +-------------------------------+
 | PV        PV        PV        |
 | +-------+ +-------+ +-------+ |
 | |       | |       | |       | |
 | | +-----------------------+ | |
 | | |                       | | |
 | | | LV                    | | |
 | | |                       | | |
 | | +-----------------------+ | |
 | |       | |       | |       | |
 | +-------+ +-------+ +-------+ |
 |                               |
 +-------------------------------+
参考情報
情報確認
$ sudo pvscan
  PV /dev/vda5   VG ubuntu-vg   lvm2 [19.76 GiB / 20.00 MiB free]
  Total: 1 [19.76 GiB] / in use: 1 [19.76 GiB] / in no VG: 0 [0   ]
$ sudo vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "ubuntu-vg" using metadata type lvm2
$ sudo lvscan
  ACTIVE            '/dev/ubuntu-vg/root' [18.74 GiB] inherit
  ACTIVE            '/dev/ubuntu-vg/swap_1' [1020.00 MiB] inherit
$ sudo fdisk -l
Disk /dev/vda: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders, total 41943040 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: 0x000cffa1
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048      499711      248832   83  Linux
/dev/vda2          501758    41940991    20719617    5  Extended
/dev/vda5          501760    41940991    20719616   8e  Linux LVM
 
Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders, total 41943040 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: 0x00000000
 
Disk /dev/vdb doesn't contain a valid partition table
 
Disk /dev/mapper/ubuntu--vg-root: 20.1 GB, 20124270592 bytes
255 heads, 63 sectors/track, 2446 cylinders, total 39305216 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: 0x00000000
 
Disk /dev/mapper/ubuntu--vg-root doesn't contain a valid partition table
 
Disk /dev/mapper/ubuntu--vg-swap_1: 1069 MB, 1069547520 bytes
255 heads, 63 sectors/track, 130 cylinders, total 2088960 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: 0x00000000
 
Disk /dev/mapper/ubuntu--vg-swap_1 doesn't contain a valid partition table

 

ディスクフォーマット

$ sudo fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x4f02bed1.
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)
 
Command (m for help): t
No partition is defined yet!
 
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
 
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): L
 
 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT
1e  Hidden W95 FAT1 80  Old Minix
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
 
Command (m for help): p
 
Disk /dev/vdb: 21.5 GB, 21474836480 bytes
16 heads, 63 sectors/track, 41610 cylinders, total 41943040 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: 0x4f02bed1
 
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048    41943039    20970496   8e  Linux LVM
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.

物理ボリュームPVを作成

$ sudo pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created

作成を確認

$ sudo vgdisplay
  --- Volume group ---
  VG Name               ubuntu-vg
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               19.76 GiB
  PE Size               4.00 MiB
  Total PE              5058
  Alloc PE / Size       5053 / 19.74 GiB
  Free  PE / Size       5 / 20.00 MiB
  VG UUID               QE4bbJ-Su9O-awQ4-e2qM-QPTZ-7Frc-XU7hR7

VGに作成したPVを追加

$ sudo vgextend ubuntu-vg /dev/vdb1
  Volume group "ubuntu-vg" successfully extended

確認

 
$ sudo vgdisplay -v ubuntu-vg
    Using volume group(s) on command line
    Finding volume group "ubuntu-vg"
  --- Volume group ---
  VG Name               ubuntu-vg
  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               39.75 GiB
  PE Size               4.00 MiB
  Total PE              10177
  Alloc PE / Size       5053 / 19.74 GiB
  Free  PE / Size       5124 / 20.02 GiB
  VG UUID               QE4bbJ-Su9O-awQ4-e2qM-QPTZ-7Frc-XU7hR7
 
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/root
  LV Name                root
  VG Name                ubuntu-vg
  LV UUID                zxv7dF-3xLh-Leda-l1AV-0w0Y-tVbR-UfPnMx
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2014-04-25 00:49:40 +0900
  LV Status              available
  # open                 1
  LV Size                18.74 GiB
  Current LE             4798
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
 
  --- Logical volume ---
  LV Path                /dev/ubuntu-vg/swap_1
  LV Name                swap_1
  VG Name                ubuntu-vg
  LV UUID                aL7YyM-AVtB-QsMR-lkRf-d6Dz-cX7h-MfHEvZ
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2014-04-25 00:49:40 +0900
  LV Status              available
  # open                 2
  LV Size                1020.00 MiB
  Current LE             255
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1
 
  --- Physical volumes ---
  PV Name               /dev/vda5
  PV UUID               sKd1AJ-nq6b-xBa1-ZHky-8q9N-Lvpy-xWcdVy
  PV Status             allocatable
  Total PE / Free PE    5058 / 5
 
  PV Name               /dev/vdb1
  PV UUID               CdjnbP-ltbz-VJCf-Zmew-38bM-z8vx-PZ4p1y
  PV Status             allocatable
  Total PE / Free PE    5119 / 5119

論理ボリュームLVの拡張

$ sudo lvextend -l +100%FREE /dev/ubuntu-vg/root
  Extending logical volume root to 38.76 GiB
  Logical volume root successfully resized

ファイルシステムの拡張

$ sudo resize2fs /dev/ubuntu-vg/root
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/ubuntu-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/ubuntu-vg/root is now 10160128 blocks long. 

確認

$ sudo vgdisplay
  --- Volume group ---
  VG Name               ubuntu-vg
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  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               39.75 GiB
  PE Size               4.00 MiB
  Total PE              10177
  Alloc PE / Size       5375 / 21.00 GiB
  Free  PE / Size       4802 / 18.76 GiB
  VG UUID               QE4bbJ-Su9O-awQ4-e2qM-QPTZ-7Frc-XU7hR7
 
$ sudo vgdisplay | grep PE
  PE Size               4.00 MiB
  Total PE              10177
  Alloc PE / Size       10177 / 39.75 GiB
  Free  PE / Size       0 / 0

$ df -h
Filesystem                  Type        Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-root ext4         39G   17G   21G  45% /
proc                        proc           0     0     0    - /proc
sysfs                       sysfs          0     0     0    - /sys
none                        tmpfs       4.0K     0  4.0K   0% /sys/fs/cgroup
none                        fusectl        0     0     0    - /sys/fs/fuse/connections
none                        debugfs        0     0     0    - /sys/kernel/debug
none                        securityfs     0     0     0    - /sys/kernel/security
udev                        devtmpfs    1.5G  4.0K  1.5G   1% /dev
devpts                      devpts         0     0     0    - /dev/pts
tmpfs                       tmpfs       302M  376K  301M   1% /run
none                        tmpfs       5.0M     0  5.0M   0% /run/lock
none                        tmpfs       1.5G     0  1.5G   0% /run/shm
none                        tmpfs       100M     0  100M   0% /run/user
none                        pstore         0     0     0    - /sys/fs/pstore
/dev/vda1                   ext2        236M   66M  158M  30% /boot
systemd                     cgroup         0     0     0    - /sys/fs/cgroup/systemd