追加したディスクをLVMシステムで使用する方法

スポンサーリンク

ディスクを追加してLVMで使用する方法です。

検証した環境

$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.6 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
$ uname -r
5.15.0-91-generic

パーティションの作成

追加したディスクが認識されているかを確認します。

$ lsblk /dev/sdp ・・・ デバイスが分からない場合は、単に「lsblk」と実行する。
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdp      8:240  0  7.3T  0 disk

パーティションを作成します。

$ sudo gdisk /dev/sdp
GPT fdisk (gdisk) version 1.0.5

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries in memory.

Command (? for help): p ・・・ パーティションテーブルの出力
Disk /dev/sdp: 15628053168 sectors, 7.3 TiB
Model: 004-2CX188      
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 1F0F509C-650E-4802-B74D-1E923115C0FC
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 15628053134
Partitions will be aligned on 2048-sector boundaries
Total free space is 15628053101 sectors (7.3 TiB)

Number  Start (sector)    End (sector)  Size       Code  Name

Command (? for help): n ・・・ 新規でパーティション作成
Partition number (1-128, default 1): ・・・ Enterキーを押下
First sector (34-15628053134, default = 2048) or {+-}size{KMGTP}: ・・・ Enterキーを押下
Last sector (2048-15628053134, default = 15628053134) or {+-}size{KMGTP}: ・・・ Enterキーを押下
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 8e00 ・・・ LinuxLVM
Changed type of partition to 'Linux LVM'

Command (? for help): p ・・・ パーティションテーブルの出力
Disk /dev/sdp: 15628053168 sectors, 7.3 TiB
Model: 004-2CX188      
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 1F0F509C-650E-4802-B74D-1E923115C0FC
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 15628053134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048     15628053134   7.3 TiB     8E00  Linux LVM

Command (? for help): w ・・・ パーティションテーブルの書き込み

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y ・・・ 書き込んでよいかの確認
OK; writing new GUID partition table (GPT) to /dev/sdp.
The operation has completed successfully.

パーティションが出来ているかを確認します。

$ lsblk /dev/sdp
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdp      8:240  0  7.3T  0 disk 
`-sdp1   8:241  0  7.3T  0 part

LVMの作成

作成したパーティションにLVMを使用して論理ボリュームを作成します。

物理ボリュームの作成

$ sudo pvcreate /dev/sdp1
  Physical volume "/dev/sdp1" successfully created.
$ sudo pvdisplay /dev/sdp1
  "/dev/sdp1" is a new physical volume of "<7.28 TiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdp1
  VG Name               
  PV Size               <7.28 TiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               ibXsSu-izNx-x5nc-STqL-K1fm-eCPz-0gRtVA

ボリュームグループの作成

$ sudo vgcreate data15vg /dev/sdp1
  Volume group "data15vg" successfully created
$ sudo vgdisplay data15vg
  --- Volume group ---
  VG Name               data15vg
  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               <7.28 TiB
  PE Size               4.00 MiB
  Total PE              1907720
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1907720 / <7.28 TiB
  VG UUID               6qI4rC-Zxt9-izYq-2f93-g5TJ-ErId-bUUsaF

論理ボリュームの作成

$ sudo lvcreate -l +1900040 -n chia15lv data15vg
  Logical volume "chia15lv" created.
$ sudo lvdisplay /dev/data15vg/chia15lv         
  --- Logical volume ---
  LV Path                /dev/data15vg/chia15lv
  LV Name                chia15lv
  VG Name                data15vg
  LV UUID                8G3GsC-vcrL-AHTs-fWBi-eQBt-s6cB-FLUrVH
  LV Write Access        read/write
  LV Creation host, time tka3pc01, 2024-01-10 11:45:24 +0900
  LV Status              available
  # open                 0
  LV Size                <7.25 TiB
  Current LE             1900040
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:21

ファイルシステムの作成

作成した論理ボリュームに、ext4ファイルシステムを作成します。

標準はxfsのファイルシステムですが、ここでは、ext4のファイルシステムで作成しています。

$ sudo mkfs -t ext4 /dev/data15vg/chia15lv ・・・ xfsファイルシステムは「-t」オプションでxfsと指定
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 1945640960 4k blocks and 243208192 inodes
Filesystem UUID: 15bcd4c9-d903-45af-83d3-1d78664770da
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848, 512000000, 550731776, 644972544, 1934917632

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done       

マウントポイント作成と自動マウントの設定

マウントポイント用のディレクトリーを作成してマウントします。

$ sudo mkdir /chia15
$ sudo mount /dev/data15vg/chia15lv /chia15
$ df -h -T /chia15
Filesystem                    Type  Size  Used Avail Use% Mounted on
/dev/mapper/data15vg-chia15lv ext4  7.2T   28K  6.9T   1% /chia15

UUIDを確認します。

$ sudo blkid /dev/data15vg/chia15lv
/dev/data15vg/chia15lv: UUID="15bcd4c9-d903-45af-83d3-1d78664770da" TYPE="ext4"

起動時の自動マウントを設定します。

$ sudo cp -p /etc/fstab /etc/BK-fstab.20240110
$ ls -l /etc/fstab /etc/BK-fstab.20240110
-rw-r--r-- 1 root root 3469 Dec 17 23:21 /etc/BK-fstab.20240110
-rw-r--r-- 1 root root 3469 Dec 17 23:21 /etc/fstab
$ sudo vi /etc/fstab
   :
UUID=15bcd4c9-d903-45af-83d3-1d78664770da /chia15        ext4  defaults    0       2
   :

マシンのリブートをします。

$ sudo systemctl reboot