0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

lvm作成手順

Posted at

新規でパーティション:lvmとファイルシステム:を作成する
ファイルシステムは、

環境情報・前提
・AWS EC2
・EBS作成しEC2へアタッチ済み
・lvm2 パッケージがインストール済み

1.デバイスファイルのフルパスを表示

[root@ip-10-0-0-31 ~]# lsblk -p
NAME           MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
├/dev/xvda      202:0    0   8G  0 disk
├/dev/xvda1   202:1    0   8G  0 part /
├/dev/xvda127 259:0    0   1M  0 part
└/dev/xvda128 259:1    0  10M  0 part /boot/efi
/dev/xvdb      202:16   0  15G  0 disk

2.パーティションの作成
Command (m for help): n
Select (default p): p
Partition number (1-4, default 1): 1

[root@ip-10-0-0-31 ~]# fdisk /dev/xvdb

Welcome to fdisk (util-linux 2.37.4).
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 0xc8d17e30.

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

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

Command (m for help):
fdiskコマンドの操作オプション
[root@ip-10-0-0-31 ~]# fdisk /dev/xvdb

Welcome to fdisk (util-linux 2.37.4).
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 0x15b834ed.

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help):

2-2.パーティションを作成
以下の順で実施する
Command (m for help): t
Hex code or alias (type L to list all): L
Hex code or alias (type L to list all): 8e
Command (m for help): w
w 入力し押下後、パーティションの設定が反映される

Command (m for help):
Command (m for help): t
Selected partition 1
Hex code or alias (type L to list all): L

00 Empty            24 NEC DOS          81 Minix / old Lin  bf Solaris
01 FAT12            27 Hidden NTFS Win  82 Linux swap / So  c1 DRDOS/sec (FAT-
02 XENIX root       39 Plan 9           83 Linux            c4 DRDOS/sec (FAT-
03 XENIX usr        3c PartitionMagic   84 OS/2 hidden or   c6 DRDOS/sec (FAT-
04 FAT16 <32M       40 Venix 80286      85 Linux extended   c7 Syrinx
05 Extended         41 PPC PReP Boot    86 NTFS volume set  da Non-FS data
06 FAT16            42 SFS              87 NTFS volume set  db CP/M / CTOS / .
07 HPFS/NTFS/exFAT  4d QNX4.x           88 Linux plaintext  de Dell Utility
08 AIX              4e QNX4.x 2nd part  8e Linux LVM        df BootIt
09 AIX bootable     4f QNX4.x 3rd part  93 Amoeba           e1 DOS access
0a OS/2 Boot Manag  50 OnTrack DM       94 Amoeba BBT       e3 DOS R/O
0b W95 FAT32        51 OnTrack DM6 Aux  9f BSD/OS           e4 SpeedStor
0c W95 FAT32 (LBA)  52 CP/M             a0 IBM Thinkpad hi  ea Linux extended
0e W95 FAT16 (LBA)  53 OnTrack DM6 Aux  a5 FreeBSD          eb BeOS fs
0f W95 Ext'd (LBA)  54 OnTrackDM6       a6 OpenBSD          ee GPT
10 OPUS             55 EZ-Drive         a7 NeXTSTEP         ef EFI (FAT-12/16/
11 Hidden FAT12     56 Golden Bow       a8 Darwin UFS       f0 Linux/PA-RISC b
12 Compaq diagnost  5c Priam Edisk      a9 NetBSD           f1 SpeedStor
14 Hidden FAT16 <3  61 SpeedStor        ab Darwin boot      f4 SpeedStor
16 Hidden FAT16     63 GNU HURD or Sys  af HFS / HFS+       f2 DOS secondary
17 Hidden HPFS/NTF  64 Novell Netware   b7 BSDI fs          fb VMware VMFS
18 AST SmartSleep   65 Novell Netware   b8 BSDI swap        fc VMware VMKCORE
1b Hidden W95 FAT3  70 DiskSecure Mult  bb Boot Wizard hid  fd Linux raid auto
1c Hidden W95 FAT3  75 PC/IX            bc Acronis FAT32 L  fe LANstep
1e Hidden W95 FAT1  80 Old Minix        be Solaris boot     ff BBT

Aliases:
   linux          - 83
   swap           - 82
   extended       - 05
   uefi           - EF
   raid           - FD
   lvm            - 8E
   linuxex        - 85
Hex code or alias (type L to list all): 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.

[root@ip-10-0-0-31 ~]#

2-3.lvmパーティションが作成されたことを確認する

[root@ip-10-0-0-31 ~]# lsblk -p
NAME           MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
/dev/xvda      202:0    0   8G  0 disk
├/dev/xvda1   202:1    0   8G  0 part /
├/dev/xvda127 259:0    0   1M  0 part
└/dev/xvda128 259:1    0  10M  0 part /boot/efi
/dev/xvdb      202:16   0  15G  0 disk
└/dev/xvdb1   202:17   0  15G  0 part

3.物理ボリューム(PV)の作成
2-x 作成したパーミッションに対して以下コマンドを実行する

[root@ip-10-0-0-31 ~]# pvcreate /dev/xvdb1
  Physical volume "/dev/xvdb1" successfully created.

3-2.pvsが作成されたことを確認する

[root@ip-10-0-0-31 ~]# pvs
  PV         VG Fmt  Attr PSize   PFree
  /dev/sdb1     lvm2 ---  <15.00g <15.00g
[root@ip-10-0-0-31 ~]# pvdisplay
  "/dev/sdb1" is a new physical volume of "<15.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               <15.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               8JVu1o-o5ga-CpBS-pvjX-LgYs-I24T-RKx1Ex

4.ボリュームグループ(VG)の作成

[root@ip-10-0-0-31 ~]# vgcreate vg_dev /dev/xvdb1
  Volume group "vg_dev" successfully created
[root@ip-10-0-0-31 ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  vg_dev   1   0   0 wz--n- <15.00g <15.00g
[root@ip-10-0-0-31 ~]#
[root@ip-10-0-0-31 ~]#
[root@ip-10-0-0-31 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_dev
  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               <15.00 GiB
  PE Size               4.00 MiB
  Total PE              3839
  Alloc PE / Size       0 / 0
  Free  PE / Size       3839 / <15.00 GiB
  VG UUID               jPbh3i-oj7y-3yWT-Hgi4-49Wq-zLcH-lESza8

5.論理ボリューム(VG)の割り当て

[root@ip-10-0-0-31 ~]# lvcreate -l 100%FREE -n lv_dev vg_dev
  Logical volume "lv_dev" created.
[root@ip-10-0-0-31 ~]#
[root@ip-10-0-0-31 ~]#
[root@ip-10-0-0-31 ~]# lvs
  LV     VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_dev vg_dev -wi-a----- <15.00g
[root@ip-10-0-0-31 ~]#
[root@ip-10-0-0-31 ~]#
[root@ip-10-0-0-31 ~]#
[root@ip-10-0-0-31 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg_dev/lv_dev
  LV Name                lv_dev
  VG Name                vg_dev
  LV UUID                jtdShH-l0Ep-aLBI-ZGxz-Lcch-qnlU-PUfaPO
  LV Write Access        read/write
  LV Creation host, time ip-10-0-0-31.ap-northeast-1.compute.internal, 2025-03-04 20:24:27 +0000
  LV Status              available
  # open                 0
  LV Size                <15.00 GiB
  Current LE             3839
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

6.論理ボリュームが割り当てられたことを確認する

[root@ip-10-0-0-31 ~]# lsblk
NAME              MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
xvda              202:0    0   8G  0 disk
├xvda1           202:1    0   8G  0 part /
├xvda127         259:0    0   1M  0 part
├xvda128         259:1    0  10M  0 part /boot/efi
xvdb              202:16   0  15G  0 disk
└xvdb1           202:17   0  15G  0 part
  └vg_dev-lv_dev 253:0    0  15G  0 lvm
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?