blog.monophile.net

コンピュータのこととかのメモ。

山本 一彰 | Takaaki Yamamoto

東京工業大学において計算機科学と応用数学を学び、 情報科学芸術大学院大学[IAMAS]においてメディア表現を専攻し修了。 2015年にコンビネータ論理を基に計算完備な計算手法 "論理珠算"を開発し、 それを含む体系である"算道"を構成した。 その成果により、 第19回 文化庁メディア芸術祭 アート部門 新人賞 (文部科学大臣賞) を2016年に受賞。 現在はインフラエンジニアとして生計をたててている。

技術

各種システムの設計/構築/運用を承ります。

Configuration Management Ansible, Terraform, cloud-init
Cloud Platform AWS, Azure, GCP, Openstack
Openstack Keystone, Glance, Cinder(Ceph), Neutron(VLAN), Nova(QEMU), Horizon
Virtualization QEMU+KVM, LXD/LXC, Docker
OS Ubuntu, Debian GNU/Linux, CentOS, ...
Storage Ceph, GlusterFS, ZFS, btrfs, ...
Networks Tunnel(IPSec, L2TP, VXLAN, GRE), WirelessAP, ...
DB MySQL, MariaDB(Galera Cluster), MongoDB
Mail postfix, dovecot
WebApps WordPress, GitLab, MatterMost, Redmine, RainLoop, ...
Monitoring Nagios, Munin
Misc certbot, dnsmasq, ...

技術(習得中)

Orchestration Kubernetes
Openstack swift, manila, trove
OS CoreOS(Container Linux), Vyatta(VyOS), ...
Networks IPv6, BGP(quagga, calico), flannel, fan, ...
DB/KVS Redis, etcd
Monitoring Prometheus, Zabbix
DNS CoreDNS, PowerDNS
Misc MAAS, Blockchain

投稿

LVMでディスクの拡張と追加をやってみる

概要

LVMのディスク追加と領域拡張の作業があったので、そのための検証のメモ。 環境はUbuntu18.04。 /dev/sda がLVM用のディスクで、/dev/sdbがブートディスク。

ツールのインストール

$ sudo apt install lvm2 thin-provisioning-tools

パーティション /dev/sda1 作成

$ sudo parted -s /dev/sda mklabel gpt
$ sudo parted -s /dev/sda mkpart "pv0" "" 0% 20GiB
$ sudo parted -s /dev/sda set 1 lvm on
$ sudo parted -s /dev/sda p
Model: ATA SanDisk SDSSDH32 (scsi)
Disk /dev/sda: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  21.5GB  21.5GB               pv0   lvm

PV /dev/sda1 の作成

$ sudo pvcreate /dev/sda1
  Physical volume "/dev/sda1" successfully created.
$ sudo pvdisplay
  "/dev/sda1" is a new physical volume of "<20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda1
  VG Name
  PV Size               <20.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               wLhaUz-JLey-L2hO-SgtX-lm8y-sioj-hEXELy

VG /dev/vg00 の作成

$ sudo vgcreate vg00 /dev/sda1
  Volume group "vg00" successfully created
$ sudo vgdisplay
  --- Volume group ---
  VG Name               vg00
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <20.00 GiB
  PE Size               4.00 MiB
  Total PE              5119
  Alloc PE / Size       0 / 0
  Free  PE / Size       5119 / <20.00 GiB
  VG UUID               t34tOI-eXcM-RL2C-FsiG-jk0n-Lxw2-pyXuSb

LV /dev/vg00/vol00 の作成

今回はシンプロビジョニングをしたかったので、 vg00/tp というシンプールをまず作成。

$ lvcreate --thinpool tp -L 10G vg00
  Using default stripesize 64.00 KiB.
  Thin pool volume with chunk size 64.00 KiB can address at most 15.81 TiB of data.
  Logical volume "tp" created.

次にvol00を作成する。 シンプロビジョニングなので、物理パーティション20GiBよりも大きく100GiBで作成した。

$ sudo lvcreate --thin -V 100G -n vol00 vg00/tp
  Using default stripesize 64.00 KiB.
  WARNING: Sum of all thin volume sizes (100.00 GiB) exceeds the size of thin pool vg00/tp and the size of whole volume group (<20.00 GiB).
  WARNING: You have not turned on protection against thin pools running out of space.
  WARNING: Set activation/thin_pool_autoextend_threshold below 100 to trigger automatic extension of thin pools before they get full.
  Logical volume "vol00" created.
$ sudo lvs
  LV    VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  tp    vg00 twi-aotz--  10.00g             0.00   0.65
  vol00 vg00 Vwi-a-tz-- 100.00g tp          0.00

lsblkをすると↓のようになった。

$ lsblk /dev/sda
NAME                MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                   8:0    0 232.9G  0 disk
└─sda1                8:1    0    20G  0 part
  ├─vg00-tp_tmeta   253:0    0    12M  0 lvm
  │ └─vg00-tp-tpool 253:2    0    10G  0 lvm
  │   ├─vg00-tp     253:3    0    10G  0 lvm
  │   └─vg00-vol00  253:4    0   100G  0 lvm
  └─vg00-tp_tdata   253:1    0    10G  0 lvm
    └─vg00-tp-tpool 253:2    0    10G  0 lvm
      ├─vg00-tp     253:3    0    10G  0 lvm
      └─vg00-vol00  253:4    0   100G  0 lvm

LV /dev/vg00/vol00 をXFSで初期化

XFSで初期化してみた。 特にXFSである理由はなくて、手順も通常のディスクと同様。

$ sudo mkfs.xfs /dev/vg00/vol00
meta-data=/dev/vg00/vol00        isize=512    agcount=16, agsize=1638384 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=0, rmapbt=0, reflink=0
data     =                       bsize=4096   blocks=26214144, imaxpct=25
         =                       sunit=16     swidth=16 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=12800, version=2
         =                       sectsz=512   sunit=16 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

マウントも普通

$ sudo mkdir -p /mnt/vg00/vol00
$ sudo mount -t xfs /dev/vg00/vol00 /mnt/vg00/vol00

パーティション /dev/sda1 をリサイズ

/dev/sda1を 20GiB -> 40GiB にリサイズしてみる。

$ sudo parted /dev/sda -s resizepart 1 40GiB
$ sudo parted /dev/sda -s p
Model: ATA SanDisk SDSSDH32 (scsi)
Disk /dev/sda: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  42.9GB  42.9GB               pv0   lvm

PV /dev/sda1 をリサイズ

$ sudo pvresize /dev/sda1
  Physical volume "/dev/sda1" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
$ sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda1
  VG Name               vg00
  PV Size               <40.00 GiB / not usable 2.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              10239
  Free PE               7673
  Allocated PE          2566
  PV UUID               os4006-QsYX-O5wL-IsJo-DWDM-7dyr-EiPbBw

LV シンプール vg00/tp をリサイズ

$ sudo lvresize -L +20G vg00/tp
  WARNING: Sum of all thin volume sizes (100.00 GiB) exceeds the size of thin pools and the size of whole volume group (<40.00 GiB).
  WARNING: You have not turned on protection against thin pools running out of space.
  WARNING: Set activation/thin_pool_autoextend_threshold below 100 to trigger automatic extension of thin pools before they get full.
  Size of logical volume vg00/tp_tdata changed from 10.00 GiB (2560 extents) to 30.00 GiB (7680 extents).
  Logical volume vg00/tp_tdata successfully resized.
$ lvdisplay
  --- Logical volume ---
  LV Name                tp
  VG Name                vg00
  LV UUID                gJkkUJ-uO6E-st69-ElcX-UR6j-QI1b-ivNQdx
  LV Write Access        read/write
  LV Creation host, time xhost, 2018-05-21 22:58:49 +0900
  LV Pool metadata       tp_tmeta
  LV Pool data           tp_tdata
  LV Status              available
  # open                 2
  LV Size                30.00 GiB
  Allocated pool data    0.17%
  Allocated metadata     1.50%
  Current LE             7680
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/vg00/vol00
  LV Name                vol00
  VG Name                vg00
  LV UUID                dcMtdS-FlWr-bfxP-sTPW-PK6Q-lctF-VdFfBd
  LV Write Access        read/write
  LV Creation host, time xhost, 2018-05-21 22:59:21 +0900
  LV Pool name           tp
  LV Status              available
  # open                 0
  LV Size                100.00 GiB
  Mapped size            0.05%
  Current LE             25600
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:4

LV /dev/vg00/vol00 のファイルシステムをリサイズ

$ sudo xfs_growfs /dev/vg00/vol00
meta-data=/dev/mapper/vg00-vol00 isize=512    agcount=16, agsize=1638384 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1 spinodes=0 rmapbt=0
         =                       reflink=0
data     =                       bsize=4096   blocks=26214144, imaxpct=25
         =                       sunit=16     swidth=16 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=12800, version=2
         =                       sectsz=512   sunit=16 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 26214144 to 26214400

パーティション /dev/sda2 の追加

sudo parted -a optimal -s /dev/sda unit s p
Model: ATA SanDisk SDSSDH32 (scsi)
Disk /dev/sda: 488397168s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start  End        Size       File system  Name  Flags
 1      2048s  83886080s  83884033s               pv0   lvm
$ sudo parted -s /dev/sda mkpart "pv1" "" 83886081s 60GiB
$ sudo parted -s /dev/sda set 2 lvm on
$ sudo parted -s /dev/sda p
Model: ATA SanDisk SDSSDH32 (scsi)
Disk /dev/sda: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  42.9GB  42.9GB               pv0   lvm
 2      42.9GB  64.4GB  21.5GB               pv1   lvm

PV /dev/sda2 を追加

$ pvcreate /dev/sda2
  Physical volume "/dev/sda2" successfully created.
$ sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda1
  VG Name               vg00
  PV Size               <40.00 GiB / not usable 2.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              10239
  Free PE               2553
  Allocated PE          7686
  PV UUID               os4006-QsYX-O5wL-IsJo-DWDM-7dyr-EiPbBw

  "/dev/sda2" is a new physical volume of "<20.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda2
  VG Name
  PV Size               <20.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               xOAb5N-WZxA-y0Uk-mdJY-2e2u-Qgb8-6y0W9r

VG vg00に PV /dev/sda2 を追加

$ sudo vgextend vg00 /dev/sda2
  Volume group "vg00" successfully extended
$ sudo vgdisplay
  --- Volume group ---
  VG Name               vg00
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  7
  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               59.99 GiB
  PE Size               4.00 MiB
  Total PE              15358
  Alloc PE / Size       7686 / 30.02 GiB
  Free  PE / Size       7672 / <29.97 GiB
  VG UUID               t34tOI-eXcM-RL2C-FsiG-jk0n-Lxw2-pyXuSb

参考