HippoBlog
Web開発に関する備忘録や
日々の雑記ブログ
  • #Ubuntu
  • 2019年8月22日
ENTRY TITLE

[ubuntu] ハードディスクを追加・マウントする

TEXT BY @hippohack@hippohack
TEXT BY @hippohack@hippohack
  • このエントリーをはてなブックマークに追加

Ubuntu Server、80GB?のサブのHDDがすでにマウントされてるもんやと思ってたがされてなかったので設定する。

ubuntu serverやと自分のマウントしないといけないのかな?

とりま、ディクス容量確認。

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           382M   12M  371M   3% /run
/dev/sda2       229G  166G   52G  77% /
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/loop0       89M   89M     0 100% /snap/core/7396
/dev/loop2       89M   89M     0 100% /snap/core/7270
/dev/loop3       98M   98M     0 100% /snap/docker/321
/dev/loop1       98M   98M     0 100% /snap/docker/384
tmpfs           382M     0  382M   0% /run/user/1000

もしすでにマウントされていれば、/dev/sdb が存在するはず。

  • SCSIハードディスクを使用しているのでsda(プライマリのマスタ) or sdb(プライマリのスレーブ)となる。
  • IDEハードディスクを使用しているとhdaやhdbになる。

状態を確認していたら、

$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 73.1 GiB, 78518522880 bytes, 153356490 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

Device    Boot Start       End   Sectors  Size Id Type
/dev/sdb1        2048 153356489 153354442 73.1G 83 Linux

あった。

(あとからきづいたが、この時点でパーティション切れてるぽいのでマウントだけしてやれば使えたかも。)

ハードディスクにパーティションを作成する

m でヘルプ確認して実行すべし。

$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

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

Created a new partition 1 of type 'Extended' and of size 73.1 GiB.
Partition #1 contains a vfat signature.

Do you want to remove the signature? [Y]es/[N]o: Y

The signature will be removed by a write command.

Command (m for help): p
Disk /dev/sdb: 73.1 GiB, 78518522880 bytes, 153356490 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: 0x3b643540

Device    Boot Start       End   Sectors  Size Id Type
/dev/sdb1        2048 153356489 153354442 73.1G  5 Extended

Filesystem/RAID signature on partition 1 will be wiped.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

確認、

$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 73.1 GiB, 78518522880 bytes, 153356490 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

Device    Boot Start       End   Sectors  Size Id Type
/dev/sdb1        2048 153356489 153354442 73.1G  5 Extended

できた??

ハードディスクのパーティションをフォーマットする

$ sudo mke2fs /dev/sdb1
mke2fs 1.44.1 (24-Mar-2018)
Found a dos partition table in /dev/sdb1
Proceed anyway? (y,N) y
mke2fs: inode_size (128) * inodes_count (0) too big for a
     filesystem with 0 blocks, specify higher inode_ratio (-i)
     or lower inode count (-N).

???。ちょっとここ理解できてない。

ハードディスクをマウントする

最初にマウント先を用意

$ sudo mkdir sub

マウントする → エラー

$ sudo mount /dev/sdb1 /sub
mount: /sub: wrong fs type, bad option, bad superblock on /dev/sdb1, missing codepage or helper program, or other error.

パーティションの作成し直し

$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): p
Disk /dev/sdb: 73.1 GiB, 78518522880 bytes, 153356490 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

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): 
First sector (2048-153356489, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-153356489, default 153356489): 

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

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.


$ sudo fdisk -l /dev/sdb
Disk /dev/sdb: 73.1 GiB, 78518522880 bytes, 153356490 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

Device    Boot Start       End   Sectors  Size Id Type
/dev/sdb1        2048 153356489 153354442 73.1G 83 Linux

拡張ではなくprimaryにした。タイプが Linux になった。

$ sudo mke2fs /dev/sdb1

$ sudo mount /dev/sdb1 /sub

確認。

$ mount
/dev/sda2 on / type ext4 (rw,relatime,data=ordered)
/dev/sdb1 on /sub type ext2 (rw,relatime,block_validity,barrier,user_xattr,acl)

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       229G  166G   52G  77% /
/dev/sdb1        72G   52M   69G   1% /sub

自動マウントさせる

システム起動時に自動的にマウントされるよう設定する。

  • /etc/fstabファイルを編集・追記
  • 各パラメータ詳細は参考サイトを確認

    $ sudo vim /etc/fstab

[/etc/fstab]

︙
︙
/dev/sdb1 /sub ext2 defaults 0 0

再起動して確認

$ shutdown -r now

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       229G  166G   52G  77% /
/dev/sdb1        72G   52M   69G   1% /sub

マウントするディレクトリを変更する

気に入らなかったので変更。一旦アンマウント。

$ umount /sub

$ sudo mount /dev/sdb1 /home/share/_sdb

/etc/fstab も修正。

参考サイト


最後までお読みいただき、ありがとうございました。

ご意見などありましたら@hippohackへDMをお願いいたします。

  • このエントリーをはてなブックマークに追加