LoginSignup
3
9

More than 5 years have passed since last update.

ディスクの増設

Posted at

対象のディスクが存在するか確認

$ sudo fdisk -l

Disk /dev/nvme0n1: 512.1 GB, 512110190592 bytes, 1000215216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x00008678

  デバイス ブート      始点        終点     ブロック   Id  システム
/dev/nvme0n1p1   *        2048     2099199     1048576   83  Linux
/dev/nvme0n1p2         2099200  1000214527   499057664   8e  Linux LVM

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes, 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
Disk label type: dos
ディスク識別子: 0xdd19b9c6

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1               1  4294967295  2147483647+  ee  GPT
パーティション 1 は物理セクタ境界で始まっていません:

Disk /dev/mapper/centos-root: 506.7 GB, 506743226368 bytes, 989732864 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト


Disk /dev/mapper/centos-swap: 4290 MB, 4290772992 bytes, 8380416 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト

今回の増設対象は /dev/sda とわかったので、パーティションを作成する。
しかし、購入時点で既にパーティション sda1 が作成されているようなので、先に削除する。

$ sudo fdisk /dev/sda

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
コマンド (m でヘルプ): m
コマンドの動作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

コマンド (m でヘルプ): d
Selected partition 1
Partition 1 is deleted
コマンド (m でヘルプ): w
パーティションテーブルは変更されました!

ioctl() を呼び出してパーティションテーブルを再読込みします。
ディスクを同期しています。

パーティション sda1 がなくなっていることを確認。

$ sudo fdisk -l

Disk /dev/nvme0n1: 512.1 GB, 512110190592 bytes, 1000215216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x00008678

  デバイス ブート      始点        終点     ブロック   Id  システム
/dev/nvme0n1p1   *        2048     2099199     1048576   83  Linux
/dev/nvme0n1p2         2099200  1000214527   499057664   8e  Linux LVM

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes, 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
Disk label type: dos
ディスク識別子: 0xdd19b9c6

デバイス ブート      始点        終点     ブロック   Id  システム

Disk /dev/mapper/centos-root: 506.7 GB, 506743226368 bytes, 989732864 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト


Disk /dev/mapper/centos-swap: 4290 MB, 4290772992 bytes, 8380416 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト

パーティションの作成

$ sudo fdisk /dev/sda

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
コマンド (m でヘルプ): p

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes, 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
Disk label type: dos
ディスク識別子: 0xdd19b9c6

デバイス ブート      始点        終点     ブロック   Id  システム
コマンド (m でヘルプ): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
パーティション番号 (1-4, default 1): 1

最初 sector (2048-3907029167, 初期値 2048): 
初期値 2048 を使います
Last sector, +sectors or +size{K,M,G} (2048-3907029167, 初期値 3907029167): 
初期値 3907029167 を使います
Partition 1 of type Linux and of size 1.8 TiB is set
コマンド (m でヘルプ): t
Selected partition 1
Hex code (type L to list all codes): L

 0  空              24  NEC DOS         81  Minix / 古い Li bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux スワップ  c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 隠し C: ド c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux 拡張領域  c7  Syrinx         
 5  拡張領域        41  PPC PReP Boot   86  NTFS ボリューム da  非 FS データ   
 6  FAT16           42  SFS             87  NTFS ボリューム db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux プレーン  de  Dell ユーティリ
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX ブート可能  4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 ブートマネ 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad ハ eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 拡張領域 (L 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC  
11  隠し FAT12      56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq 診断     5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  隠し FAT16 <32M 61  SpeedStor       ab  Darwin ブート   f2  DOS セカンダリ 
16  隠し FAT16      63  GNU HURD または af  HFS / HFS+      fb  VMware VMFS    
17  隠し HPFS/NTFS  64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI スワップ   fd  Linux raid 自動
1b  隠し W95 FAT32  70  DiskSecure Mult bb  隠し Boot Wizar fe  LANstep        
1c  隠し W95 FAT32  75  PC/IX           be  Solaris ブート  ff  BBT            
1e  隠し W95 FAT16  80  古い Minix     
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
コマンド (m でヘルプ): p

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes, 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
Disk label type: dos
ディスク識別子: 0xdd19b9c6

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1            2048  3907029167  1953513560   8e  Linux LVM
コマンド (m でヘルプ): w
パーティションテーブルは変更されました!

ioctl() を呼び出してパーティションテーブルを再読込みします。
ディスクを同期しています。

パーティションが正しく作成されているか確認。

$ sudo fdisk -l

Disk /dev/nvme0n1: 512.1 GB, 512110190592 bytes, 1000215216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x00008678

  デバイス ブート      始点        終点     ブロック   Id  システム
/dev/nvme0n1p1   *        2048     2099199     1048576   83  Linux
/dev/nvme0n1p2         2099200  1000214527   499057664   8e  Linux LVM

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes, 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
Disk label type: dos
ディスク識別子: 0xdd19b9c6

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1            2048  3907029167  1953513560   8e  Linux LVM

Disk /dev/mapper/centos-root: 506.7 GB, 506743226368 bytes, 989732864 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト


Disk /dev/mapper/centos-swap: 4290 MB, 4290772992 bytes, 8380416 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト

PVを作成。

$ sudo pvcreate /dev/sda1
WARNING: ntfs signature detected on /dev/sda1 at offset 3. Wipe it? [y/n]: y
  Wiping ntfs signature on /dev/sda1.
  Physical volume "/dev/sda1" successfully created.
$ sudo pvscan
  PV /dev/nvme0n1p2   VG centos          lvm2 [<475.94 GiB / 0    free]
  PV /dev/sda1                           lvm2 [<1.82 TiB]
  Total: 2 [2.28 TiB] / in use: 1 [<475.94 GiB] / in no VG: 1 [<1.82 TiB]
$ sudo pvdisplay
  --- Physical volume ---
  PV Name               /dev/nvme0n1p2
  VG Name               centos
  PV Size               <475.94 GiB / not usable 0   
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              121840
  Free PE               0
  Allocated PE          121840
  PV UUID               AzSas0-9qpN-PXj5-wTfy-KQeY-Vu2P-3zhFiu

  "/dev/sda1" is a new physical volume of "<1.82 TiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda1
  VG Name               
  PV Size               <1.82 TiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               cDSHH1-3uuX-ANtK-B09R-kYYp-28nn-nqABOc

VGを確認。

$ sudo vgdisplay
  --- Volume group ---
  VG Name               centos
  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               <475.94 GiB
  PE Size               4.00 MiB
  Total PE              121840
  Alloc PE / Size       121840 / <475.94 GiB
  Free  PE / Size       0 / 0   
  VG UUID               8mobB3-MXpT-7LQY-aeur-ZX1C-ZYoq-BJ2J2X

すでに centos というVGが存在するが、このVGはSSDで今回追加分はHDDなので、これとは別にVGを用意する。

$ sudo vgcreate data /dev/sda1
  Volume group "data" successfully created
$ sudo vgdisplay
  --- Volume group ---
  VG Name               data
  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               <1.82 TiB
  PE Size               4.00 MiB
  Total PE              476931
  Alloc PE / Size       0 / 0   
  Free  PE / Size       476931 / <1.82 TiB
  VG UUID               xhoze4-5aJ9-zDMl-GCCu-YEtu-qxpv-wZ4cUY

  --- Volume group ---
  VG Name               centos
  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               <475.94 GiB
  PE Size               4.00 MiB
  Total PE              121840
  Alloc PE / Size       121840 / <475.94 GiB
  Free  PE / Size       0 / 0   
  VG UUID               8mobB3-MXpT-7LQY-aeur-ZX1C-ZYoq-BJ2J2X

/dev/sda1 が VG data に割り当てられたことがわかる。

$ sudo pvscan
  PV /dev/sda1        VG data            lvm2 [<1.82 TiB / <1.82 TiB free]
  PV /dev/nvme0n1p2   VG centos          lvm2 [<475.94 GiB / 0    free]
  Total: 2 [2.28 TiB] / in use: 2 [2.28 TiB] / in no VG: 0 [0   ]

LVを確認。

$ sudo lvscan
  ACTIVE            '/dev/centos/root' [471.94 GiB] inherit
  ACTIVE            '/dev/centos/swap' [<4.00 GiB] inherit
$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                2uMek5-8A0N-3rwz-5Lxl-lmyS-I304-YOEDbL
  LV Write Access        read/write
  LV Creation host, time localhost, 2017-11-17 23:11:52 +0900
  LV Status              available
  # open                 1
  LV Size                471.94 GiB
  Current LE             120817
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                xZumXZ-vRtK-w8yO-Pt2B-kvAw-7U2o-G7t9MT
  LV Write Access        read/write
  LV Creation host, time localhost, 2017-11-17 23:11:54 +0900
  LV Status              available
  # open                 2
  LV Size                <4.00 GiB
  Current LE             1023
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

LVを作成。

$ sudo lvcreate -l 100%FREE -n /dev/data/data0 data
  Logical volume "data0" created.
$ sudo lvscan
  ACTIVE            '/dev/data/data0' [<1.82 TiB] inherit
  ACTIVE            '/dev/centos/root' [471.94 GiB] inherit
  ACTIVE            '/dev/centos/swap' [<4.00 GiB] inherit
$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/data/data0
  LV Name                data0
  VG Name                data
  LV UUID                9eAFHi-vsf9-MyY7-91P7-hjyw-E1VO-51QeyZ
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2018-01-14 14:48:06 +0900
  LV Status              available
  # open                 0
  LV Size                <1.82 TiB
  Current LE             476931
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                2uMek5-8A0N-3rwz-5Lxl-lmyS-I304-YOEDbL
  LV Write Access        read/write
  LV Creation host, time localhost, 2017-11-17 23:11:52 +0900
  LV Status              available
  # open                 1
  LV Size                471.94 GiB
  Current LE             120817
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                xZumXZ-vRtK-w8yO-Pt2B-kvAw-7U2o-G7t9MT
  LV Write Access        read/write
  LV Creation host, time localhost, 2017-11-17 23:11:54 +0900
  LV Status              available
  # open                 2
  LV Size                <4.00 GiB
  Current LE             1023
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

ファイルシステムを作成してマウント

$ sudo mkfs.xfs /dev/mapper/data-data0 
meta-data=/dev/mapper/data-data0 isize=512    agcount=4, agsize=122094336 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=488377344, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=238465, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
$ sudo mkdir /data
$ sudo mount /dev/mapper/data-data0 /data
$ df -h
ファイルシス            サイズ  使用  残り 使用% マウント位置
/dev/mapper/centos-root   472G   34G  439G    8% /
devtmpfs                   16G     0   16G    0% /dev
tmpfs                      16G   20M   16G    1% /dev/shm
tmpfs                      16G  9.1M   16G    1% /run
tmpfs                      16G     0   16G    0% /sys/fs/cgroup
/dev/nvme0n1p1           1014M  415M  600M   41% /boot
tmpfs                     3.2G   40K  3.2G    1% /run/user/1000
/dev/mapper/data-data0    1.9T   33M  1.9T    1% /data

fstab に設定

$ sudo vi /etc/fstab

#
# /etc/fstab
# Created by anaconda on Fri Nov 17 23:11:54 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=1408180d-f0c0-47ba-85b8-050892aa729f /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/mapper/data-data0  /data                   xfs     defaults        0 0

マシンをリブートして /data がマウントされていたら完了。

3
9
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
3
9