LVM で論理ボリュームを作成する
Vagrantfile
検証に Vagrant を使います。
1GB のディスクを 2 つ追加しています。
この 2 つのディスクを使い、論理ボリュームを作成します。
# -*- mode: ruby -*- # vi: set ft=ruby : ENV["VAGRANT_EXPERIMENTAL"] = "disks" Vagrant.configure("2") do |config| config.vm.box = "bento/ubuntu-18.04" config.vm.disk :disk, size: "1GB", name: "disk-0" config.vm.disk :disk, size: "1GB", name: "disk-1" end
ディスクの確認
vagrant@vagrant:~$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 64G 0 disk └─sda1 8:1 0 64G 0 part ├─vagrant--vg-root 253:0 0 63G 0 lvm / └─vagrant--vg-swap_1 253:1 0 980M 0 lvm [SWAP] sdb 8:16 0 1G 0 disk sdc 8:32 0 1G 0 disk
sdb にパーティションを作成
vagrant@vagrant:~$ sudo fdisk /dev/sdb Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0x27a74be3. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): Using default response p. Partition number (1-4, default 1): First sector (2048-2097151, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-2097151, default 2097151): Created a new partition 1 of type 'Linux' and of size 1023 MiB. Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
sdc にパーティションを作成
vagrant@vagrant:~$ sudo fdisk /dev/sdc Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0xb7872d57. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): Using default response p. Partition number (1-4, default 1): First sector (2048-2097151, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-2097151, default 2097151): Created a new partition 1 of type 'Linux' and of size 1023 MiB. Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'. Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
パーティションの確認
vagrant@vagrant:~$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 64G 0 disk └─sda1 8:1 0 64G 0 part ├─vagrant--vg-root 253:0 0 63G 0 lvm / └─vagrant--vg-swap_1 253:1 0 980M 0 lvm [SWAP] sdb 8:16 0 1G 0 disk └─sdb1 8:17 0 1023M 0 part sdc 8:32 0 1G 0 disk └─sdc1 8:33 0 1023M 0 part
物理ボリュームを作成する
vagrant@vagrant:~$ sudo pvcreate /dev/sdb1 /dev/sdc1 Physical volume "/dev/sdb1" successfully created. Physical volume "/dev/sdc1" successfully created.
ボリュームグループを作成する
vagrant@vagrant:~$ sudo vgcreate lvg-test /dev/sdb1 /dev/sdc1 Volume group "lvg-test" successfully created
作成したボリュームグループの確認する
vagrant@vagrant:~$ sudo vgdisplay --- Volume group --- VG Name lvg-test System ID Format lvm2 Metadata Areas 2 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 2 Act PV 2 VG Size 1.99 GiB PE Size 4.00 MiB Total PE 510 Alloc PE / Size 0 / 0 Free PE / Size 510 / 1.99 GiB VG UUID zMcDi1-xfrc-y6ae-KFgL-ZN90-moNz-cteZdu --- Volume group --- VG Name vagrant-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 <64.00 GiB PE Size 4.00 MiB Total PE 16383 Alloc PE / Size 16383 / <64.00 GiB Free PE / Size 0 / 0 VG UUID 0hdOem-2LyY-XIrh-cxIR-bYG4-6LXM-WMZjo5
論理ボリュームを作成する
vagrant@vagrant:~$ sudo lvcreate -n lv-test -L 1.99g lvg-test Rounding up size to full physical extent 1.99 GiB Logical volume "lv-test" created.
論理ボリュームにファイルシステムを作成する
vagrant@vagrant:~$ sudo mkfs.ext4 /dev/lvg-test/lv-test mke2fs 1.44.1 (24-Mar-2018) Creating filesystem with 522240 4k blocks and 130560 inodes Filesystem UUID: 24bbc802-618d-4b4e-9542-603ddd573de9 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done
論理ボリュームをマウントする
vagrant@vagrant:~$ sudo mount /dev/lvg-test/lv-test /mnt vagrant@vagrant:~$ ls /mnt/ lost+found vagrant@vagrant:~$ df -hT Filesystem Type Size Used Avail Use% Mounted on udev devtmpfs 461M 0 461M 0% /dev tmpfs tmpfs 99M 5.1M 94M 6% /run /dev/mapper/vagrant--vg-root ext4 62G 1.6G 58G 3% / tmpfs tmpfs 493M 0 493M 0% /dev/shm tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs tmpfs 493M 0 493M 0% /sys/fs/cgroup vagrant vboxsf 457G 121G 337G 27% /vagrant tmpfs tmpfs 99M 0 99M 0% /run/user/1000 /dev/mapper/lvg--test-lv--test ext4 2.0G 6.0M 1.9G 1% /mnt