Okada Hiroshi の blog

typo が多いです

自宅の Linux サーバーにハードディスクを増設しました。

しばらくぶりに自宅の Linux サーバーにハードディスクを増設したので記録しておきます。

自宅サーバーでそれほど重要なデータでもないので、普通のPC用のハードディスクを増設しました。

ハードディスクの増設は何回もやったことがあるのですが、 最近はGUIで設定してばかりだったので、コマンドラインでやるのは久しぶりです。

増設前の /etc/fstab は以下のようなものでした。

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=9a65b311-ec87-47ae-9a45-5d1c0636d912 /               ext4    errors=remount-ro 0       1
# /tmp was on /dev/sdb2 during installation
UUID=5550e624-abfb-49eb-8708-06c7b0df64e6 /tmp            ext4    defaults        0       2
# swap was on /dev/sdb1 during installation
UUID=95b623db-53b0-4bd4-bce3-de3dc817bceb none            swap    sw              0       0

今度増設するドライブは /dev/sdc になります。 GPT ディスクなので フォーマットには gdisk コマンドを使いました。

$ sudo gdisk /dev/sdc
GPT fdisk (gdisk) version 1.0.1

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

Creating new GPT entries.

Command (? for help): o   「新しい空の GUID partition table (GPT) を作成」
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): Y

Command (? for help): n「新しいパーティションを作成」
Partition number (1-128, default 1): 
First sector (34-3907029134, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-3907029134, default = 3907029134) or {+-}size{KMGTP}: 
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

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/sdc.

hiroshi@hp1:~$ sudo mkfs.ext4 /dev/sdc1 
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 488378385 4k blocks and 122101760 inodes
Filesystem UUID: 3627b957-fd37-4147-84e4-62ff8400d177
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000, 214990848

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

次にファイルシステムを指定してフォーマットします

$ sudo mkfs.ext4 /dev/sdc1 
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 488378385 4k blocks and 122101760 inodes
Filesystem UUID: 3627b957-fd37-4147-84e4-62ff8400d177
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000, 214990848

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

lsblk で UUID を確認します

$ lsblk -o NAME,UUID
NAME   UUID
sda    
└─sda1 9a65b311-ec87-47ae-9a45-5d1c0636d912
sdb    
├─sdb1 95b623db-53b0-4bd4-bce3-de3dc817bceb
└─sdb2 5550e624-abfb-49eb-8708-06c7b0df64e6
sdc    
└─sdc1 3627b957-fd37-4147-84e4-62ff8400d177

/etc/fstab に次の行を追記します。

UUID=3627b957-fd37-4147-84e4-62ff8400d177 /srv            ext4    defaults        0       2

$ sudo mount -a でマウントします。

以上でした。