Changing the size of an ext4-format RBD device
First, identify the RBD device and pool. Just to be confusing, in the following example the pool/device is called "media/disk0" the filesystem's mount point is "/media/disk0". The following files and commands can be informative at this stage:
/etc/fstab
/etc/ceph/rbdmap
/proc/mounts
ceph osd lspools
rbd list {pool} list -l
blkid /dev/{device}
Example:
# cat /proc/mounts | fgrep rbd
/dev/rbd0 /media/disk0 ext4 rw,relatime,stripe=1024,data=ordered 0 0
Unmount the filesystem:
# umount /dev/rbd0
Force a full fsck
before we do anything else:
# fsck.ext4 -f /dev/rbd0
e2fsck 1.42.9 (28-Dec-2013)
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/rbd0: 9453/196608000 files (20.0% non-contiguous), 697890832/786432000 blocks
Unmap the RBD device:
# rbd unmap /dev/rbd0
Make sure it is really unmapped (there should be no mention of it in the following command's output):
# rbd showmapped
Resize the device:
# rbd resize -s 3500G media/disk0
Resizing image: 100% complete...done.
At this point, if you have an entry in /etc/fstab
for the device so it is automatically mounted at boot time, you should comment it out because the next step will trigger this and cause it to mount before you have finished checking that all went well. If you leave the /etc/fstab
in place you get the following:
# rbd map media/disk0
/dev/rbd0
# fsck.ext4 -f /dev/rbd0
e2fsck 1.42.9 (28-Dec-2013)
/dev/rbd0 is mounted.
e2fsck: Cannot continue, aborting.
# umount /dev/rbd0
Now the resize of the device (but not the filesystem on it) is done, do another fsck
:
# fsck.ext4 -f /dev/rbd0
e2fsck 1.42.9 (28-Dec-2013)
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/rbd0: 9453/196608000 files (20.0% non-contiguous), 697890832/786432000 blocks
Now resize the filesystem on the device to match the new device size. This may take a while:
# time resize2fs /dev/rbd0
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/rbd0 to 917504000 (4k) blocks.
The filesystem on /dev/rbd0 is now 917504000 blocks long.
real 2m55.392s
user 0m28.888s
sys 0m1.144s
Another fsck
:
# fsck.ext4 -f /dev/rbd0
e2fsck 1.42.9 (28-Dec-2013)
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/rbd0: 9453/229376000 files (20.0% non-contiguous), 699946832/917504000 blocks
Put the entry back in /etc/fstab
is necessary.
Remount the filesystem:
# mount -a
Check:
# cat /proc/mounts | fgrep rbd
/dev/rbd0 /media/disk0 ext4 rw,relatime,stripe=1024,data=ordered 0 0
Done:
#