LVMに空きパーティション追加


目的

  • CloudAtCostのDebianがLVMでインストールされていた。
    • /dev/sda3が既存のLVM(8.6G)
    • /dev/sda1(237M)と/dev/sda2(954M)を削除し、
    • /dev/sda1(1.3G)を作成し既存のLVMに追加したい(8.6G+1.3G=>9.8G)

参考

現状確認

# df -h /dev/dm-0
Filesystem      Size  Used Avail Use% Mounted on
/dev/dm-0       8.6G  1.4G  6.8G  18% /
# fdisk -l /dev/sda

Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 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
Disklabel type: dos
Disk identifier: 0x0001cb21

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048   487423   485376  237M 83 Linux
/dev/sda2         487424  2441215  1953792  954M 82 Linux swap / Solaris
/dev/sda3        2441216 20969471 18528256  8.9G 8e Linux LVM
/dev/sda4       20969472 20971519     2048    1M 8e Linux LVM

swap off

# swapoff /dev/sda2
  • /etc/fstabのswap削除

/dev/sda1,2を削除

# fdisk /dev/sda

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 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
Disklabel type: dos
Disk identifier: 0x0001cb21

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048   487423   485376  237M 83 Linux
/dev/sda2         487424  2441215  1953792  954M 82 Linux swap / Solaris
/dev/sda3        2441216 20969471 18528256  8.9G 8e Linux LVM
/dev/sda4       20969472 20971519     2048    1M 8e Linux LVM


Command (m for help): d
Partition number (1-4, default 4): 1

Partition 1 has been deleted.

Command (m for help): d
Partition number (2-4, default 4): 2

Partition 2 has been deleted.

Command (m for help): p
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 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
Disklabel type: dos
Disk identifier: 0x0001cb21

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda3        2441216 20969471 18528256  8.9G 8e Linux LVM
/dev/sda4       20969472 20971519     2048    1M 8e Linux LVM


Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 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).

# reboot

/dev/sda1作成

/dev/sda1作成
# fdisk /dev/sda

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1,2, default 1): 
First sector (2048-20971519, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-2441215, default 2441215): 

Created a new partition 1 of type 'Linux' and of size 1.2 GiB.

Command (m for help): t
Partition number (1,3,4, default 4): 1
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): p
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 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
Disklabel type: dos
Disk identifier: 0x0001cb21

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1           2048  2441215  2439168  1.2G 8e Linux LVM
/dev/sda3        2441216 20969471 18528256  8.9G 8e Linux LVM
/dev/sda4       20969472 20971519     2048    1M 8e Linux LVM


Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 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).

# reboot

pvcreate

# fdisk -l /dev/sda

Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 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
Disklabel type: dos
Disk identifier: 0x0001cb21

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1           2048  2441215  2439168  1.2G 8e Linux LVM
/dev/sda3        2441216 20969471 18528256  8.9G 8e Linux LVM
/dev/sda4       20969472 20971519     2048    1M 8e Linux LVM

# pvdisplay -v
    DEGRADED MODE. Incomplete RAID LVs will be processed.
    Scanning for physical volume names
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               vg_cac
  PV Size               8.83 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2261
  Free PE               0
  Allocated PE          2261
  PV UUID               gjBdEp-9uoK-Hnxo-9isu-Hi30-3ZZ3-lzdY3b

# pvscan
  PV /dev/sda3   VG vg_cac   lvm2 [8.83 GiB / 0    free]
  Total: 1 [8.83 GiB] / in use: 1 [8.83 GiB] / in no VG: 0 [0   ]
# pvcreate /dev/sda1
  Physical volume "/dev/sda1" successfully created
# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "vg_cac" using metadata type lvm2
# vgextend vg_cac /dev/sda1
  Volume group "vg_cac" successfully extended
# df -h /dev/dm-0
Filesystem      Size  Used Avail Use% Mounted on
/dev/dm-0       8.6G  1.3G  6.9G  16% /
# vgdisplay 
  --- Volume group ---
  VG Name               vg_cac
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               9.99 GiB
  PE Size               4.00 MiB
  Total PE              2558
  Alloc PE / Size       2261 / 8.83 GiB
  Free  PE / Size       297 / 1.16 GiB
  VG UUID               AlBirr-duAr-Mwzy-JYtP-rhgG-T7y4-C6LR09

lvextend

# lvextend -l +297 /dev/vg_cac/root_cac
  Size of logical volume vg_cac/root_cac changed from 8.83 GiB (2261 extents) to 9.99 GiB (2558 extents).
  Logical volume root_cac successfully resized
# df -h /dev/dm-0
Filesystem      Size  Used Avail Use% Mounted on
/dev/dm-0       8.6G  1.3G  6.9G  16% /

resize2fs

# resize2fs /dev/vg_cac/root_cac
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/vg_cac/root_cac is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vg_cac/root_cac is now 2619392 (4k) blocks long.

# df -h /dev/dm-0
Filesystem      Size  Used Avail Use% Mounted on
/dev/dm-0       9.8G  1.3G  8.0G  14% /

完成