Centosパーティション拡張

今更だがconoha vpsのディスクが50G→100Gになったので対応を行った。


# cd /


# fdisk -l

Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos
Disk identifier: 0x0005dc7a

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048   104857599    51915776   8e  Linux LVM

Disk /dev/mapper/centos-root: 51.0 GB, 50964987904 bytes, 99540992 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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

# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 479M     0  479M   0% /dev
tmpfs                    496M   12K  496M   1% /dev/shm
tmpfs                    496M   14M  483M   3% /run
tmpfs                    496M     0  496M   0% /sys/fs/cgroup
/dev/mapper/centos-root   48G   16G   32G  33% /
/dev/vda1                497M  397M  100M  80% /boot
tmpfs                    100M     0  100M   0% /run/user/1000
tmpfs                    100M     0  100M   0% /run/user/0

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                4ihePj-WD7H-O3J6-aSEv-kQEA-Q6UT-cerpcA
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2015-12-24 14:02:12 +0900
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                YcfoSu-M0o7-cvWK-Op2I-LxyG-0gHK-ffypmV
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2015-12-24 14:02:13 +0900
  LV Status              available
  # open                 1
  LV Size                47.46 GiB
  Current LE             12151
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   

# parted /dev/vda
GNU Parted 3.1
Using /dev/vda
Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) print                                                            
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  525MB   524MB   primary  xfs          boot
 2      525MB   53.7GB  53.2GB  primary               lvm

(parted) resizepart 2
End?  [53.7GB]? 100%                                                      
(parted) print                                                            
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  525MB  524MB  primary  xfs          boot
 2      525MB   107GB  107GB  primary               lvm

(parted) quit                                                             
Information: You may need to update /etc/fstab.

# fdisk -l                                       

Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos
Disk identifier: 0x0005dc7a

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1026047      512000   83  Linux
/dev/vda2         1026048   209715199   104344576   8e  Linux LVM

Disk /dev/mapper/centos-root: 51.0 GB, 50964987904 bytes, 99540992 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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

# pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda2
  VG Name               centos
  PV Size               49.51 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              12674
  Free PE               11
  Allocated PE          12663
  PV UUID               OQ0g7d-2BeQ-PXOr-B9lK-hfmU-8F2K-ZR4h8m
   


# pvresize -tv /dev/vda2
  TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
    Test mode: Skipping archiving of volume group.
    Resizing volume "/dev/vda2" to 208689152 sectors.
    Resizing physical volume /dev/vda2 from 12674 to 25474 extents.
    Updating physical volume "/dev/vda2"
    Test mode: Skipping backup of volume group.
  Physical volume "/dev/vda2" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized



# pvresize -v /dev/vda2
    Archiving volume group "centos" metadata (seqno 6).
    Resizing volume "/dev/vda2" to 208689152 sectors.
    Resizing physical volume /dev/vda2 from 12674 to 25474 extents.
    Updating physical volume "/dev/vda2"
    Creating volume group backup "/etc/lvm/backup/centos" (seqno 7).
  Physical volume "/dev/vda2" changed
  1 physical volume(s) resized or updated / 0 physical volume(s) not resized



# pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda2
  VG Name               centos
  PV Size               <99.51 GiB / not usable 2.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              25474
  Free PE               12811
  Allocated PE          12663
  PV UUID               OQ0g7d-2BeQ-PXOr-B9lK-hfmU-8F2K-ZR4h8m
   


# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                4ihePj-WD7H-O3J6-aSEv-kQEA-Q6UT-cerpcA
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2015-12-24 14:02:12 +0900
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                YcfoSu-M0o7-cvWK-Op2I-LxyG-0gHK-ffypmV
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2015-12-24 14:02:13 +0900
  LV Status              available
  # open                 1
  LV Size                47.46 GiB
  Current LE             12151
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   


# lvextend -trl +100%FREE /dev/centos/root
  TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
  Size of logical volume centos/root changed from 47.46 GiB (12151 extents) to <97.51 GiB (24962 extents).
  Logical volume centos/root successfully resized.

# lvextend -rl +100%FREE /dev/centos/root
  Size of logical volume centos/root changed from 47.46 GiB (12151 extents) to <97.51 GiB (24962 extents).
  Logical volume centos/root successfully resized.
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=3110656 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=12442624, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=6075, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 12442624 to 25561088



# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 479M     0  479M   0% /dev
tmpfs                    496M   12K  496M   1% /dev/shm
tmpfs                    496M   14M  483M   3% /run
tmpfs                    496M     0  496M   0% /sys/fs/cgroup
/dev/mapper/centos-root   98G   16G   82G  16% /
/dev/vda1                497M  397M  100M  80% /boot
tmpfs                    100M     0  100M   0% /run/user/1000
tmpfs                    100M     0  100M   0% /run/user/0