6
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ubuntu ディスク容量の拡張

Last updated at Posted at 2017-03-02

パーティションの作成

  • 事前確認
    • p free コマンドにより、以下のことが分かります。
      • プライマリで使用しているのは sda1 である。
      • ディスクの 1049kB~3221MB を使用。
      • sda2 が 3222MB~4294MB を使用しているので、プライマリのsda1 を連続して拡張することができない。
    • そのため、新規にパーティションを作成し、プライマリで使用しているファイルをそちらに移行し、プライマリボリュームを空けることにする。
    • du コマンドにより、一番容量のあるディレクトリは/opt であることが分かります。
inohana@ino-ubuntu:~/repo/chef/Packages$ sudo parted /dev/sda
sudo: unable to resolve host ino-ubuntu
[sudo] password for inohana:
GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)
(parted) p free
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 4295MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system     Flags
        32.3kB  1049kB  1016kB            Free Space
 1      1049kB  3221MB  3220MB  primary   ext4            boot
        3221MB  3222MB  1048kB            Free Space
 2      3222MB  4294MB  1072MB  extended
 5      3222MB  4294MB  1072MB  logical   linux-swap(v1)
        4294MB  4295MB  1049kB            Free Space

(parted) quit
inohana@ino-ubuntu:~$ sudo du -s -j /h /*
9.5M	/bin
34M	/boot
4.0K	/dev
5.9M	/etc
288M	/home
0	/initrd.img
272M	/lib
4.0K	/lib64
16K	/lost+found
12K	/media
4.0K	/mnt
1.1G	/opt
du: cannot access ‘/proc/2121/task/2121/fd/4’: No such file or directory
du: cannot access ‘/proc/2121/task/2121/fdinfo/4’: No such file or directory
du: cannot access ‘/proc/2121/fd/4’: No such file or directory
du: cannot access ‘/proc/2121/fdinfo/4’: No such file or directory
0	/proc
56K	/root
544K	/run
11M	/sbin
4.0K	/srv
0	/sys
4.0K	/tmp
208K	/user01
619M	/usr
480M	/var
0	/vmlinuz
  • パーティションの作成
    • 予めvCenter からディスクを拡張しておきます。
    • Primary として作成しました。
      • kmkpart
sudo parted
(parted) kmkpart
Partition type?  primary/logical? primary
File system type?  [ext2]? ext4
Start? 4295MB
End? 10.7GB
  • マウント
    • sda3 を /mnt/ にマウント
      • mount /dev/sda3 /mnt/

inohana@ino-ubuntu:~$ sudo mke2fs -t exrt4 /dev/sda3
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
393216 inodes, 1572864 blocks
78643 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1610612736
48 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

Allocating group tables:  0/48     done                            
Writing inode tables:  0/48     done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:  0/48 4/48 6/48 8/4826/48     done
  • ファイルの移動
    • sda1 で容量が多い /opt/opscode/のデータを /mnt に移動。
      • mv /opt/opscode/ /mnt/
    • sda1 の容量が減りました。
inohana@ino-ubuntu:~$ mv /opt/opscode/ /mnt/ 
inohana@ino-ubuntu:~$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1        3029776 1769200   1086960  62% /
none                   4       0         4   0% /sys/fs/cgroup
udev              498156       4    498152   1% /dev
tmpfs             101792     544    101248   1% /run
none                5120       0      5120   0% /run/lock
none              508956       0    508956   0% /run/shm
none              102400       0    102400   0% /run/user
/dev/sda3        6061632 1081032   4649644  19% /mnt
inohana@ino-ubuntu:~$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1        3029776 1769280   1086880  62% /
none                   4       0         4   0% /sys/fs/cgroup
udev              498156       4    498152   1% /dev
tmpfs             101792     544    101248   1% /run
none                5120       0      5120   0% /run/lock
none              508956       0    508956   0% /run/shm
none              102400       0    102400   0% /run/user
  • /mnt をアンマウント
inohana@ino-ubuntu:~$ sudo umount /mnt 
  • sda3 を(先ほど移動したファイルの)元の場所である /opt にマウントします。
inohana@ino-ubuntu:~$ sudo mount /dev/sda3 /opt/
inohana@ino-ubuntu:~$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1        3029776 1769296   1086864  62% /
none                   4       0         4   0% /sys/fs/cgroup
udev              498156       4    498152   1% /dev
tmpfs             101792     544    101248   1% /run
none                5120       0      5120   0% /run/lock
none              508956       0    508956   0% /run/shm
none              102400       0    102400   0% /run/user
/dev/sda3        6061632 1078868   4651808  19% /opt

p free の結果

  • Before
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 4295MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system     Flags
        32.3kB  1049kB  1016kB            Free Space
 1      1049kB  3221MB  3220MB  primary   ext4            boot
        3221MB  3222MB  1048kB            Free Space
 2      3222MB  4294MB  1072MB  extended
 5      3222MB  4294MB  1072MB  logical   linux-swap(v1)
        4294MB  4295MB  1049kB            Free Space
  • After
    • Partition 作成後
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system     Flags
        32.3kB  1049kB  1016kB            Free Space
 1      1049kB  3221MB  3220MB  primary   ext4            boot
        3221MB  3222MB  1048kB            Free Space
 2      3222MB  4294MB  1072MB  extended
 5      3222MB  4294MB  1072MB  logical   linux-swap(v1)
        4294MB  4295MB  1049kB            Free Space
 3      4295MB  10.7GB  6442MB  primary

df の結果

  • Before
    • もともと、/dev/sda1 は100% 使い切っている。
inohana@ino-ubuntu:~$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1        3029776 2829304     26856 100% /
none                   4       0         4   0% /sys/fs/cgroup
udev              498156       4    498152   1% /dev
tmpfs             101792     544    101248   1% /run
none                5120       0      5120   0% /run/lock
none              508956       0    508956   0% /run/shm
none              102400       0    102400   0% /run/user
  • After1
    • /dev/sda1 の使用率が62% となった。(/mnt にマウント中)
inohana@ino-ubuntu:~$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1        3029776 1769200   1086960  62% /
none                   4       0         4   0% /sys/fs/cgroup
udev              498156       4    498152   1% /dev
tmpfs             101792     544    101248   1% /run
none                5120       0      5120   0% /run/lock
none              508956       0    508956   0% /run/shm
none              102400       0    102400   0% /run/user
/dev/sda3        6061632 1081032   4649644  19% /mnt
  • After2
    • /dev/sda1 の使用率が62% となった。(/opt に再マウント)
inohana@ino-ubuntu:~$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1        3029776 1769296   1086864  62% /
none                   4       0         4   0% /sys/fs/cgroup
udev              498156       4    498152   1% /dev
tmpfs             101792     544    101248   1% /run
none                5120       0      5120   0% /run/lock
none              508956       0    508956   0% /run/shm
none              102400       0    102400   0% /run/user
/dev/sda3        6061632 1078868   4651808  19% /opt

fdisk の結果

  • Before
    • もともと sda3 はなかった。
inohana@ino-ubuntu:~$ sudo fdisk -l -u /dev/sda

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 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: 0x000cebba

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     6291455     3144704   83  Linux
/dev/sda2         6293502     8386559     1046529    5  Extended
/dev/sda5         6293504     8386559     1046528   82  Linux swap / Solaris
  • After
    • もともと sda3 が作成された。
inohana@ino-ubuntu:~$ sudo fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 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: 0x000cebba

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     6291455     3144704   83  Linux
/dev/sda2         6293502     8386559     1046529    5  Extended
/dev/sda3         8388608    20971519     6291456   83  Linux
/dev/sda5         6293504     8386559     1046528   82  Linux swap / Solaris
6
10
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
6
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?