Ubuntu&docker mounts a new hard drive and docker overlay takes up the solution

Catalog

 

Preface

Ubuntu mounts a new hard drive

Doker overlay disk 100%

docker cleanup

Preface

It's really a setback. Keep a record of this problem solving. I hope you can also help.There are two internal servers using ubuntu systems, docker and recently disk full conditions. One of them, A, is because of the mirror, what the container is running on, too much fragmentation really bursts [32G memory]1T Hard Disk) Suddenly feel that 1T is really too small; the other B is more bizarre, the disk is full but only 100+G. Later I found that my colleague buried a pit when installing the system. This computer has two hard disks, 128 solid state and 1T machine, the system is installed on solid state, the other one is useless, so I will solve it one by one.

Ubuntu mounts a new hard drive

1. Hard disk partition | Hard disk add new partition

1. Display the hard disk and its partitions.Enter the following command in the terminal window:

sudo fdisk -l

Disk /dev/nvme0n1: 119.2 GiB, 128035676160 bytes, 250069680 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

Disklabel type: gpt

Disk identifier: 6753C7C5-F2B5-495A-8787-25AD4980AC1D

equipment Start End Sector Size type

/dev/nvme0n1p1 2048 1050623 1048576 512M EFI System

/dev/nvme0n1p2 1050624 248068095 247017472 117.8G Linux filesystem

/dev/nvme0n1p3 248068096 250068991 2000896 977M Linux swap

Disk /dev/sda: 931.5 GiB, 2048 bytes, 1953525168 sectors

Disk /dev/sda doesn't contain a valid partition table

2. Partition the hard disk.Enter the following command in the terminal window:

sudo fdisk /dev/sda

As follows:
Enter m after the Command (m for help) prompt to display a help menu.(

Welcome to fdisk (util-linux 2.27.1).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

/dev/sda: device contains a valid 'ext4' signature; it is strongly recommended to wipe the device with wipefs(8) if this is unexpected, in order to avoid possible collisions

 

Device does not contain a recognized partition table.

Created a new DOS disklabel with disk identifier 0x5e4ce3c3.

 

command(input m get help): m

 

Help:

 

DOS (MBR)

a toggle a bootable flag

b edit nested BSD disklabel

c toggle the dos compatibility flag

 

Generic

d delete a partition

F list free unpartitioned space

l list known partition types

n add a new partition

p print the partition table

t change a partition type

v verify the partition table

i print information about a partition

 

Misc

m print this menu

u change display/entry units

x extra functionality (experts only)

 

Script

I load disk layout from sfdisk script file

O dump disk layout to sfdisk script file

 

Save & Exit

w write table to disk and exit

q quit without saving changes

 

Create a new label

g create a new empty GPT partition table

G create a new empty SGI (IRIX) partition table

o create a new empty DOS partition table

s create a new empty Sun partition table

Enter n after the Command (m for help) prompt and execute the add a new partition directive to add a new partition to the hard disk.
When Command action occurs, enter e to specify that the partition is extended.
When Partition number(1-4) appears, enter 1 to indicate that there is only one partition.
Subsequently, the cylinder number is specified to complete the partition.

command(input m get help): n

Partition type

p primary (0 primary, 0 extended, 4 free)

e extended (container for logical partitions)

Select (default p): e

Partition Number (1-4, default 1):

First sector (2048-1953525167, default 2048): 2048

Last sector, +sectors or +size{K,M,G,T,P} (2048-1953525167, default 1953525167): 1953525167

 

Created a new partition 1 of type 'Extended' and of size 931.5 GiB.

Enter p after the Command (m for help) prompt to display the partition table.
The system tips are as follows:

command(input m get help): p

Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disklabel type: dos

Disk identifier: 0x5e4ce3c3

 

Device startup Start End Sector Size Id type

/dev/sda1 2048 1953525167 1953523120 931.5G 5 extend

Save the partition table by typing w after the Command (m for help) prompt.
System Tip: The partition table has been altered!

command(input m get help): w

The partition table has been altered.

Calling ioctl() to re-read partition table.

Syncing disks.

Enter the following command in the terminal window:

sudo fdisk -l

As follows:
The partition of the hard disk/dev/sda has been identified by the system.

Disk /dev/nvme0n1: 119.2 GiB, 128035676160 bytes, 250069680 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

Disklabel type: gpt

Disk identifier: 6753C7C5-F2B5-495A-8787-25AD4980AC1D

 

equipment Start End Sector Size type

/dev/nvme0n1p1 2048 1050623 1048576 512M EFI System

/dev/nvme0n1p2 1050624 248068095 247017472 117.8G Linux filesystem

/dev/nvme0n1p3 248068096 250068991 2000896 977M Linux swap

 

 

Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 4096 bytes

I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disklabel type: dos

Disk identifier: 0x5e4ce3c3

 

Device startup Start End Sector Size Id type

/dev/sda1 2048 1953525167 1953523120 931.5G 5 extend

2. Hard disk formatting | Format hard disk

1. Display the hard disk and its partitions.Enter the following command in the terminal window:

sudo mkfs -t ext4 /dev/sdb

Explain:
-t ext4 means that the partition is formatted into an ext4 file system type.

root@q:/web/grafana/plugins# mkfs -t ext4 /dev/sda

mke2fs 1.42.13 (17-May-2015)

/dev/sda contains a ext4 file system

last mounted on Wed Mar 4 11:12:15 2020

Continue anyway? (y,n) y

Creating filesystem with 244190646 4k blocks and 61054976 inodes

Filesystem UUID: 95c3c581-7970-430c-9c07-4801ecfba839

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,

102400000, 214990848

 

Allocating group tables: complete

Writing inode surface: complete

Creating journal (32768 blocks): complete

Writing superblocks and filesystem accounting information: complete 

Mount hard disk partition

1. Display the hard disk mounting.Enter the following command in the terminal window:

df -l

The new hard disk partition is not mounted and cannot be accessed and viewed.(

Enter the following command in the terminal window:

sudo mount -t ext4 /dev/sda /devdata

The following prompt means that the mounted directory does not exist

mount: mount point /devdata does not exist

Solution: A mount node path must exist to create one

cd /

mkdir -p devdata

Enter the following command again in the terminal window: You can see that the disk is mounted

sudo mount -t ext4 /dev/sda /devdata
df -l

 

2. Configure the hard disk to mount automatically when the system starts.

In some versions, you said to add the following configuration to the file/etc/fstab:

/dev/sdb     /devdata    ext4     defaults       0 0

I am adding mount/dev/sda/devdata at/etc/rs.local

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

mount /dev/sda /devdata
exit 0

 

Doker overlay disk 100%

This is the easiest way to do this, and of course there is a way to modify the docker configuration, which is available in the reference documentation

1 Stop docker moving to the existing directory and have enough space, 2 soft connections, 3 restart docker

systemctl stop docker
mv /var/lib/docker /devdata/
ln -s /devdata/docker/ /var/lib/

systemctl restart docker

 

docker cleanup

docker system prune to automatically clean up space, refer to the following:

  • This directive clears all of the following resources by default:
    • Stopped container
    • Volumes not used by any container
    • A network that is not associated with any container
    • All suspended image s.
  • By default, this command clears only suspended mirrors, and unused mirrors are not deleted.
  • When the -a or -all parameter is added, all unused and suspended mirrors can be cleared at the same time.
  • You can add a -f or -force parameter to ignore the alert confirmation information.
  • The total cleanup space released is displayed at the end of the instruction.

Reference resources:

[Processing method when docker overlay2 occupies 100% space]

[The / var/lib/docker/overlay folder of docker suddenly fills the hard disk]

[Mount a new hard drive in the Ubuntu environment]

[The docker container holds the directory with full disk space]

260 original articles published. 482 approved. 1.12 million visits+
His message board follow

Tags: Docker sudo Linux Ubuntu

Posted on Wed, 04 Mar 2020 19:02:05 -0800 by nivaspm