エロサイトの作り方

2013年11月から勉強しながらエロサイトを作っています。

UbuntuにHDDを追加する方法(3TB超版)

以前書いたものの3TB超版です。

fdiskではなくpartedを使います。

ディスクの確認

$ sudo fdisk -l 
...
WARNING: GPT (GUID Partition Table) detected on '/dev/sdc'! The util fdisk doesn't support GPT. Use GNU Parted.

Disk /dev/sdc: 3000.6 GB, 3000592982016 bytes
255 heads, 63 sectors/track, 364801 cylinders, total 5860533168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1  4294967294  2147483647   ee  GPT

/dev/sdcに追加されたみたい。

partedを起動

$ sudo parted /dev/sdc

GNU Parted 2.3
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.

パーティションの確認

(parted) print
Model: WDC WD30 EZRX-00D8PB0 (scsi)
Disk /dev/sdc: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name                  Flags
 1      20.5kB  210MB   210MB   fat32        EFI System Partition  boot
 2      210MB   3000GB  3000GB  hfs+         images

Macで使っていたのでHFS+になっている。

パーティションの削除

 (parted) rm 2
(parted) print
Model: WDC WD30 EZRX-00D8PB0 (scsi)
Disk /dev/sdc: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End    Size   File system  Name                  Flags
 1      20.5kB  210MB  210MB  fat32        EFI System Partition  boot

一瞬で終わるけど、削除されていた。

(parted) rm 1
(parted) print
Model: WDC WD30 EZRX-00D8PB0 (scsi)
Disk /dev/sdc: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

続いてパーティション1も削除。

2TB超えGPTラベルを付ける

(parted) mklabel gpt
Warning: The existing disk label on /dev/sdc will be destroyed and all data on this disk will be lost. Do you want to
continue?
Yes/No? Yes

削除確認をしてきた。

パーティションを削除しなくても良かったのか、あるいは元々あったGPTラベルがそのまま使えたのかも。

(parted) print
Model: WDC WD30 EZRX-00D8PB0 (scsi)
Disk /dev/sdc: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

パーティションを作る

(parted) mkpart
Partition name?  []? images
File system type?  [ext2]? ext4
Start? 0%
End? 100%

Startに0%、Endに100%とすると全領域を確保してくれるらしい。

(parted) print
Model: WDC WD30 EZRX-00D8PB0 (scsi)
Disk /dev/sdc: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name    Flags
 1      1049kB  3001GB  3001GB               images

アライメントを確認する

(parted) align-check
alignment type(min/opt)  [optimal]/minimal? opt
Partition number? 1
1 aligned

アライメントというのがいまいち分かってないのだけど、書き込み単位がHDDの物理セクタを跨がないように先頭に空白領域を置くもののようです。 Startが1049kBと半端な値になっているのはこの調整のせいだと思う。

ちなみに、Startの値をセクタで指定した場合にずれていると、以下のような警告してくれるみたい。

Warning: The resulting partition is not properly aligned for best performance.

今回は何も言われてなかったので問題なさそう。

ファイルシステムのフォーマットをかける

(parted) mkfs
WARNING: you are attempting to use parted to operate on (mkfs) a file system.
parted's file system manipulation code is not as robust as what you'll find in
dedicated, file-system-specific packages like e2fsprogs.  We recommend
you use parted only to manipulate partition tables, whenever possible.
Support for performing most operations on most types of file systems
will be removed in an upcoming release.
Warning: The existing file system will be destroyed and all data on the partition will be lost. Do you want to continue?

Yes/No? No

要約すると「できるけど、俺そういうの得意じゃないんだよね」という感じのことを言っている(ように思える)ので、partedでやるのは止めたほうがよさそう。

(parted) quit
Information: You may need to update /etc/fstab.

partedを終了させる。

mkfsでフォーマットをかける

$ sudo mkfs -t ext4 /dev/sdc1
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
183148544 inodes, 732566272 blocks
36628313 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
22357 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
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

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

マウントする

とりあえず/mnt/images以下にマウントしてみます。

$ sudo mkdir /mnt/images
$ sudo chown admin:admin /mnt/images
$ sudo mount /dev/sdc1 /mnt/images
$ df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/crawler--vg-root  205G   77G  117G  40% /
none                          4.0K     0  4.0K   0% /sys/fs/cgroup
udev                          7.7G  4.0K  7.7G   1% /dev
tmpfs                         1.6G  692K  1.6G   1% /run
none                          5.0M     0  5.0M   0% /run/lock
none                          7.7G     0  7.7G   0% /run/shm
none                          100M     0  100M   0% /run/user
/dev/sda1                     236M   66M  158M  30% /boot
/dev/sdb1                     1.8T  1.5T  250G  86% /opt
/dev/sdc1                     2.7T   73M  2.6T   1% /mnt/images

マウントできているみたい。

$ touch /mnt/images/test
$ ll /mnt/images/test
-rw-r--r-- 1 admin admin 0 Aug 19 12:29 test

書き込みもできました。

起動時に自動でマウントする

以前書いたので(略)