How to mount LVM disk in online environment?

How to mount LVM disk in online environment?

ESC cloud server disk expansion

In daily operation, the directory where the container service is located takes up a lot of disk space due to the increase of container-log and image, so expand the /var/lib/docker/ directory to mount the LVM data disk.

First check the disk properties


sudo fdisk -l

The corresponding disk information will appear, partition and format the added data disk

Partition the disk according to the actual situation

sudo fdisk /dev/vdb
m 查看命令帮助
n 添加新的分区

Change the partition number

Change the partition type to Linux lvm volume to create LVM

t 表示更改分区编号
L 表示查看所有编号
8e 代表LVM
w 用来保存并退出

Create LVM after successful partition

sudo fdisk -l 查看分区情况

Create Physical Volume (PV)


sudo pvcreate /dev/vdb1 创建pv
sudo pvdisplay 查看pv信息

Create Volume Group (VG)


sudo vgcreate vg1 /dev/vdb1 创建vg
sudo vgdisplay 查看vg信息

Create Logical Volumes (LV)


sudo lvcreate -n lv1 -l 100%VG vg1 #将所有的vg1的内存都给lv1 逻辑卷
sudo lvdisplay

Format logical volume


sudo mkfs.ext4 /dev/vg1/lv1
sudo blkid |grep 'lv1' # 查看UUID,在/etc/fstab 文件中填写

About the /etc/fstab file

File introduction

fstab contains information about storage devices and file systems, and is used to automatically mount hard disks, partitions, removable devices, and remote devices in system format.

File field explanation


fs mountpoint type opts dump/pass
/dev/sda1 / ext4 default 0 0

<fs>--file systems: Mount the device and tell the name of the partition. You can use UUID instead of
<mountpoint>: mount path
<type>: file system type, typical examples: ext2, ext3, ext4, xfs, etc.
<opts>: file system parameters, which can make the mounted device start automatically at boot and limit the The read and write permissions of the mounted partition, the specific parameters can be searched by google
<dump>: backup command, used by dunp utility to decide whether to backup, check the entry and use the number to decide whether to backup the file system. The allowed number is 0 or 1. 0 will ignore no backup, 1, dump will make a backup
<pass>: whether fsck checks the sector, 0 means no check, 1 means the earliest check, 2 is also to check, but 1 is the earliest Tested

Docker container data backup and recovery

1. First of all, if the production environment can provide services to the outside world normally, stop the Docker daemon to ensure data integrity and execute commands.


sudo systemctl stop docker

2. Back up the data in the Docker default data directory and execute the command.


sudo mv /var/lib/docker /var/lib/docker_data

3. Then mount the new formatted disk to the /var/lib/docker directory.


sudo vim /etc/fstab
UUID=****** /var/lib/docker ext4 defaults 0 0

4. Create the corresponding directory

sudo mkdir /var/lib/docker

5. Mount the disk


sudo mount -a

6. Move the previously backed up Docker data to the new disk and execute the command.


sudo mv /var/lib/docker_data/* /var/lib/docker/

7. Start Docker, check the data location, and execute the command.


sudo systemctl start docker
  1. Execute the command df to view the new mount information

9. Execute the command docker ps to check whether the container is lost, and start the unstarted container according to the actual situation

All articles of this official account have been organized into a catalog, please reply "m" in the background of this official account to get!

Click ``Read the original text'' at the bottom of the article to jump to the historical article~

Guess you like

Origin blog.51cto.com/15067236/2606174