7
8

More than 5 years have passed since last update.

OSイメージより大容量なDiskを借りたさくらのクラウドにおいてパーティション追加とマウント

Last updated at Posted at 2015-02-04

さくらのクラウドで60GばかりHDDを借りて、20GのOSイメージからインスタンスを作成
したところ、ディスクが20Gしか使われてない。

ディスクを確保して使う方法の例を示す。

環境

前述どおり、60Gかりて、20GのOSイメージからインスタンス作成。OSはDebian7。

~# cat /etc/issue
Debian GNU/Linux 7 \n \l

調べ方

空き容量

まずは、ディスク空き容量チェックコマンドから。 / にマウントされているデバイスと、容量がわかる。60G借りたのに、 / は 17Gしかないとわかる。

# df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                   18G  840M   17G   5% /
udev                                                     10M     0   10M   0% /dev
tmpfs                                                   101M  200K  101M   1% /run
/dev/disk/by-uuid/dc0004a3-24d9-4825-808a-47c518fadcaa   18G  840M   17G   5% /
tmpfs                                                   5.0M     0  5.0M   0% /run/lock
tmpfs                                                   582M     0  582M   0% /run/shm

uuidによるDisk

さっきのコマンドで / にマウントされているのは /dev/disk/by-uuid/dc0004a3-24d9-4825-808a-47c518fadcaa らしい。これは実際のデバイスの symbolic link なので、そのディレクトリを ls -l すればわかる。

~# ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Feb  5 01:11 dc0004a3-24d9-4825-808a-47c518fadcaa -> ../../vda1
lrwxrwxrwx 1 root root 10 Feb  5 01:11 fc9d3c6a-709f-499b-95f4-dd533f1a95c7 -> ../../vda2

マウント方式を調べる

マウント状況は mount で。そして、Linuxが起動したとき、自動的にどこにどのディスクをマウントするのかは、 /etc/fstabをみればわかる。

~# cat /etc/fstab
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/vda1 during installation
UUID=dc0004a3-24d9-4825-808a-47c518fadcaa /               ext4    relatime,errors=remount-ro 0       1
# swap was on /dev/vda2 during installation
UUID=fc9d3c6a-709f-499b-95f4-dd533f1a95c7 none            swap    sw              0       0
~# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,relatime,size=10240k,nr_inodes=126895,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=102708k,mode=755)
/dev/disk/by-uuid/dc0004a3-24d9-4825-808a-47c518fadcaa on / type ext4 (rw,relatime,errors=remount-ro,user_xattr,barrier=1,data=ordered)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=595960k)
rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)

パーティションを確認する

これまでの上記コマンドで、 ディスクは /dev/vda と予想できる。 /dev/vda上に作られた1が/、2がswapで、まだ空き容量があるはず。

/dev/vdaパーティション一覧をみる。これで空き容量があることは確認できた。

~# fdisk -l

Disk /dev/vda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders, total 125829120 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: 0x000947be

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    38035455    19016704   83  Linux
/dev/vda2        38035456    41940991     1952768   82  Linux swap / Solaris

パーティション作成

fdisk

最初に作成を指示すれば、あとは [ENTER]ですむ。

~# fdisk /dev/vda

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (1-4, default 3):
Using default value 3
First sector (41940992-125829119, default 41940992):
Using default value 41940992
Last sector, +sectors or +size{K,M,G} (41940992-125829119, default 125829119):
Using default value 125829119

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

~# fdisk /dev/vda -l

Disk /dev/vda: 64.4 GB, 64424509440 bytes
16 heads, 63 sectors/track, 124830 cylinders, total 125829120 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: 0x000947be

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    38035455    19016704   83  Linux
/dev/vda2        38035456    41940991     1952768   82  Linux swap / Solaris
/dev/vda3        41940992   125829119    41944064   83  Linux

まだ見えない?

warn通り、再起動か何かをしろと。私はpartprobeを叩いたら見えた。formatしないとuuidも得られないらしい。

~# ls /dev/vda
vda   vda1  vda2

~# partprobe

~# ls /dev/vda
vda   vda1  vda2  vda3

~# blkid /dev/vda3

format

短いプロジェクトの使い捨てのファイル共有インスタンスの予定なので特に深く考えず、 ext4を採用。uuidも得られた。

~# mkfs.ext4 /dev/vda3
mke2fs 1.42.5 (29-Jul-2012)
warning: 256 blocks unused.

Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2626560 inodes, 10485760 blocks
524300 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
320 block groups
32768 blocks per group, 32768 fragments per group
8208 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624

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

~# blkid /dev/vda3
/dev/vda3: UUID="0d3035b5-7790-48ca-bdd6-b36b7f0b290d" TYPE="ext4"

mount

uuidでマウントする。なんでuuidがいるのか?となるのは、複数台HDDがついている場合、実はどれが/dev/vdaとかvdbとかになるか保証してくれないので、(特にクラウド上ではない実機の場合、6台のHDDの接続を間違えるなんてあるあるである)これで指定するのである。

とりあえず新Diskは /home/ に採用するようにする。 ていうかもう/home/<username/ができている場合には上塗りされてしまうので注意。以下のcatは抜粋

~# vi /etc/fstab

~# cat /etc/fstab
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/vda1 during installation
UUID=dc0004a3-24d9-4825-808a-47c518fadcaa /               ext4    relatime,errors=remount-ro 0       1
UUID=0d3035b5-7790-48ca-bdd6-b36b7f0b290d /home           ext4    relatime,errors=remount-ro 0       1

/etc/fstabがまともにかけたかは、mount -a でテストできる。fstabはしくじるとほんとboot不能になったりするので注意。 df -h/home が40Gあることを確認できた。

~# mount -a
~# df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                   18G  840M   17G   5% /
udev                                                     10M     0   10M   0% /dev
tmpfs                                                   101M  204K  101M   1% /run
/dev/disk/by-uuid/dc0004a3-24d9-4825-808a-47c518fadcaa   18G  840M   17G   5% /
tmpfs                                                   5.0M     0  5.0M   0% /run/lock
tmpfs                                                   582M     0  582M   0% /run/shm
/dev/vda3                                                40G  176M   38G   1% /home
7
8
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
7
8