This page looks best with JavaScript enabled

Migrating Docker Storage to a New Disk

 ·  ☕ 2 min read

1. Formatting the Disk

  • Check the new disk
1
fdisk -l

Usually, the second disk is named /dev/sdb.

  • Partition the disk
1
fdisk /dev/sdb

You will be prompted to enter parameters:

command (m for help):n
Partition number(1-4):1
First cylinder (1-22800,default 1):Enter
command (m for help):w

  • Format the disk as ext4
1
mkfs.ext4 /dev/sdb
  • Mount the disk to the target directory
1
2
mkdir /data
mount -t ext4 /dev/sdb /data
  • Mount the directory automatically at boot

First find the device UUID.

1
2
3
blkid |grep /dev/sdb

/dev/sdb: UUID="328a9d32-abb6-492a-aabe-b6a63583674d" TYPE="ext4"

Edit /etc/fstab to add the mount entry.

1
2
3
vim /etc/fstab

UUID=328a9d32-abb6-492a-aabe-b6a63583674d /dev/sdb ext4 defaults 0 0

1.1 Adding a Data Disk to a Cloud Server

After scaling up a cloud instance, the new disk may be named /dev/vdc and so on. The steps are as follows.

  1. Find the device name of the new disk
1
fdisk -l
  1. Partition
1
fdisk /dev/vdc

Select in order:

  • n add a new partition
  • p primary partition (1-4), choose as needed
  1. Format
1
mke2fs -j /dev/vdc
  1. Mount
1
2
mkdir /local_dir
mount /dev/vdc /local_dir

2. Migrating Docker Storage

  • Stop Docker
1
systemctl stop docker
  • Move the Docker storage data
1
mv /var/lib/docker /data/
  • Create a new symlink
1
ln -s /data/docker /var/lib/docker
  • Restart Docker
1
systemctl start docker

WeChat Official Account
WRITTEN BY
WeChat Official Account