Ubuntu 14.10 の仮想環境に追加のHDDをマウントする方法です。

まず VirtualBox の設定で HDDを追加します。
設定画面を開きます。

新規でHDDを追加します。

良くわからないのでデフォルト

可変にしておくと、使った分しかHDDを使用しないようです

余裕をもって50G くらい割り当てておきます

さて、設定が終わったら仮想マシンを起動し
今作ったデバイスを確認します。

root@ubuntu:~# fdisk -l

Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 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 Disklabel type: dos Disk identifier: 0x340d5599

Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 39845887 39843840 19G 83 Linux /dev/sda2 39847934 41940991 2093058 1022M 5 Extended /dev/sda5 39847936 41940991 2093056 1022M 82 Linux swap / Solaris

Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 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

まだマウントされていない /dev/sdb が見つかりました。
これをフォーマットしてマウントします。

まず fdisk でパーティション設定。

root@ubuntu:~# fdisk /dev/sdb

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

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

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

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): 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-104857599, default 2048): < デフォルト Last sector, +sectors or +size{K,M,G,T,P} (2048-104857599, default 104857599): < デフォルト

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

Command (m for help): w < パーティションを書き出し The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.

root@ubuntu:~#

うまくいったようです。
次は ファイルシステムを指定してフォーマット

root@ubuntu:~# mkfs.ext4 /dev/sdb1
mke2fs 1.42.10 (18-May-2014)
Creating filesystem with 13106944 4k blocks and 3276800 inodes
Filesystem UUID: 8867e418-3721-4a93-abfd-6b77ee5e8d1b
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424

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

root@ubuntu:~#

次はマウント。

まだ Docker をインストールしていない環境ですが
今後、Docker用としてこのデバイスを使いたいため
このデバイスを /var/lib/docker にマウントします。

root@ubuntu:~# mkdir /var/lib/docker
root@ubuntu:~# mount /dev/sdb1 /var/lib/docker/

マウントできたか確認。

root@ubuntu:~# ll /var/lib/docker total 24 drwxr-xr-x 3 root root 4096 Jun 18 22:35 ./ drwxr-xr-x 27 root root 4096 Jun 18 22:34 ../ drwx—— 2 root root 16384 Jun 18 22:35 lost+found/ root@ubuntu:~# df -H Filesystem Size Used Avail Use% Mounted on /dev/sda1 20G 865M 19G 5% / none 4.1k 0 4.1k 0% /sys/fs/cgroup udev 517M 4.1k 517M 1% /dev tmpfs 105M 295k 104M 1% /run none 5.3M 0 5.3M 0% /run/lock none 521M 0 521M 0% /run/shm none 105M 0 105M 0% /run/user /dev/sdb1 53G 55M 50G 1% /var/lib/docker

いいですね!
ついでに 再起動時に自動マウントされるように fstab も書き換えます。

root@ubuntu:~# vi /etc/fstab

※以下一行を追加 /dev/sdb1 /var/lib/docker ext4 defaults 0 0

root@ubuntu:~# reboot

※リブート後、dfの結果が以下になれば成功 root@ubuntu:~# df -H Filesystem Size Used Avail Use% Mounted on /dev/sda1 20G 868M 19G 5% / none 4.1k 0 4.1k 0% /sys/fs/cgroup udev 517M 4.1k 517M 1% /dev tmpfs 105M 295k 104M 1% /run none 5.3M 4.1k 5.3M 1% /run/lock none 521M 0 521M 0% /run/shm none 105M 0 105M 0% /run/user /dev/sdb1 53G 55M 50G 1% /var/lib/docker