You can see below that our /storage mount is full. Time to add some more storage. Now, there's two options here. Luckily this is a virtual machine so I can just tell VMWare I want to make that disk bigger, reboot or rescan the disk and it'll pick it up... but it won't resize the partition. If this is a physical box, however, there could still be a simple solution, if this disk has multiple partitions on it, you can consume the next one on the disk to create one big partition and likewise solve this issue. If you're completely out of space on that disk, you'll need some more magic to make it happen, and that won't be covered here.
root@web01.example.com:~# df Filesystem 1K-blocks Used Available Use% Mounted on dev 1012984 12 1012972 1% /dev tmpfs 204896 756 204140 1% /run /dev/dm-0 255583756 9385312 233192416 4% / none 4 0 4 0% /sys/fs/cgroup none 5120 0 5120 0% /run/lock none 1024468 0 1024468 0% /run/shm none 102400 0 102400 0% /run/user /dev/sda1 240972 104857 123674 46% /boot /dev/sdb1 515929528 515912512 0 100% /storage
The steps you'll need to follow to expand the partition above, called '/dev/sdb1' is as follows:
- Unmount the disk with the standard 'umount /dev/sdb1' command.
- If you're consuming a partition, skip to step 4. If you're running this as a VM and can simply expand the disk, do so and reboot or rescan. (Different virtualization programs allow different options here. Some will allow online expansion, others will require a shutdown first)
- After booting back up, make sure the drive is not mounted and open fdisk on that drive. You should see your updated drive size.
- Using fdisk, you'll need to remember the partition number you're resizing, the type, and the starting position. If you're consuming the next partition and not going to the end of the disk, you'll need that number as well.
- Delete the partition. If you're consuming another, delete that as well. Now, you haven't deleted data, just pointers to where it starts.
- Create a new partition. Start where the old one started, end either at the end of the disk, or the end of the partition you're consuming and hit "w" to write the changes to disk.
- Now the system knows about the partition but the file system inside it only knows about the old format. We have to resize the file system to fill the space. In order to resize, we must verify that it's in order and clean.
- Finally, it's time to actually resize the drive
- Now we can resize the file system and the mount it!
- And a quick 'df' shows that we've got some breathing room!
- Go grab a beer or glass of wine and pat yourself on the back.
root@web01.example.com:~# fdisk /dev/sdb Command (m for help): p Disk /dev/sdb: 805.3 GB, 805306368000 bytes 193 heads, 8 sectors/track, 1018694 cylinders, total 1572864000 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: 0x4f10cdef Device Boot Start End Blocks Id System /dev/sdb1 2048 1048575999 524286976 83 Linux Command (m for help): d Selected partition 1
Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): Using default value 1 First sector (2048-1572863999, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-1572863999, default 1572863999): Using default value 1572863999 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
root@web01.example.com:~# resize2fs /dev/sdb1 resize2fs 1.42.9 (4-Feb-2014) Please run 'e2fsck -f /dev/sdb1' first.
root@web01.example.com:~# e2fsck -f /dev/sdb1 e2fsck 1.42.9 (4-Feb-2014) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sdb1: 1369/32768000 files (0.6% non-contiguous), 131067490/131071744 blocks
root@web01.example.com:~# resize2fs /dev/sdb1 resize2fs 1.42.9 (4-Feb-2014) Resizing the filesystem on /dev/sdb1 to 196607744 (4k) blocks. The filesystem on /dev/sdb1 is now 196607744 blocks long. root@web01.example.com:~# mount -a root@web01.example.com:~# df Filesystem 1K-blocks Used Available Use% Mounted on udev 1012984 12 1012972 1% /dev tmpfs 204896 756 204140 1% /run /dev/dm-0 255583756 9385316 233192412 4% / none 4 0 4 0% /sys/fs/cgroup none 5120 0 5120 0% /run/lock none 1024468 0 1024468 0% /run/shm none 102400 0 102400 0% /run/user /dev/sda1 240972 104857 123674 46% /boot /dev/sdb1 773960448 515911432 218711088 71% /storage
No comments:
Post a Comment