Mount and format Disk on Ubuntu on GCP.

Check the current Filesystem

df only displays mounted file systems.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        16G  4.0G   12G  26% /
devtmpfs        2.0G     0  2.0G   0% /dev
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           394M  960K  393M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda15      105M  9.2M   96M   9% /boot/efi
/dev/loop0       56M   56M     0 100% /snap/core18/1932
/dev/loop1       56M   56M     0 100% /snap/core18/1944
/dev/loop2      130M  130M     0 100% /snap/google-cloud-sdk/161
/dev/loop3      130M  130M     0 100% /snap/google-cloud-sdk/162
/dev/loop4       71M   71M     0 100% /snap/lxd/16922
/dev/loop5       68M   68M     0 100% /snap/lxd/18150
/dev/loop6       32M   32M     0 100% /snap/snapd/10238
/dev/loop7       32M   32M     0 100% /snap/snapd/10492
tmpfs           394M     0  394M   0% /run/user/1005

Find the newly added Disk.

In GCP, the name of the disk is written at the end. (In this example, sdb is a newly created disk.)

ll /dev/disk/by-id
lrwxrwxrwx 1 root root   9 Jan 11 16:46 scsi-0Google_PersistentDisk_mysql-2-backup -> ../../sdb

List currently available block devices.

$ sudo lsblk
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0     7:0    0  55.3M  1 loop /snap/core18/1885
loop1     7:1    0 128.8M  1 loop /snap/google-cloud-sdk/160
loop3     7:3    0  70.6M  1 loop /snap/lxd/16922
loop4     7:4    0  55.4M  1 loop /snap/core18/1932
loop5     7:5    0 128.8M  1 loop /snap/google-cloud-sdk/159
loop6     7:6    0    31M  1 loop /snap/snapd/9607
loop7     7:7    0    31M  1 loop /snap/snapd/9721
loop8     7:8    0  67.8M  1 loop /snap/lxd/18150
sda       8:0    0    16G  0 disk 
├─sda1    8:1    0  15.9G  0 part /
├─sda14   8:14   0     4M  0 part 
└─sda15   8:15   0   106M  0 part /boot/efi
sdb       8:16   0    16G  0 disk 

format

mkfs.ext4 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/disk/by-id/scsi-0Google_PersistentDisk_mysql-2-backup
# mkfs.ext4 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/disk/by-id/scsi-0Google_PersistentDisk_mysql-2-backup
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done
Creating filesystem with 4194304 4k blocks and 1048576 inodes
Filesystem UUID: a9b02fa8-593b-4ee4-9764-0bff20b8b558
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
	4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

mount

$ mkdir -p /mnt/mysql-2-backup
$ mount -o discard,defaults /dev/disk/by-id/scsi-0Google_PersistentDisk_mysql-2-backup /mnt/mysql-2-backup

Auto mount settings on reboot

Add the following to / etc/fstab

/dev/disk/by-id/scsi-0Google_PersistentDisk_mysql-2-backup /mnt/mysql-2-backup ext4 defaults 1 1

Gives all users write access to the device.

chmod a+w /mnt/mysql-2-backup

Back up fstab

cp /etc/fstab /etc/fstab.backup

Check if Filesystem is recognized

sdb is increasing.

# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        16G  3.7G   12G  24% /
devtmpfs        2.0G     0  2.0G   0% /dev
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           394M  960K  393M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda15      105M  9.2M   96M   9% /boot/efi
/dev/loop0       56M   56M     0 100% /snap/core18/1932
/dev/loop1       56M   56M     0 100% /snap/core18/1944
/dev/loop2      130M  130M     0 100% /snap/google-cloud-sdk/161
/dev/loop3      130M  130M     0 100% /snap/google-cloud-sdk/162
/dev/loop4       71M   71M     0 100% /snap/lxd/16922
/dev/loop5       68M   68M     0 100% /snap/lxd/18150
/dev/loop6       32M   32M     0 100% /snap/snapd/10238
/dev/loop7       32M   32M     0 100% /snap/snapd/10492
tmpfs           394M     0  394M   0% /run/user/1005
/dev/sdb         16G   45M   15G   1% /mnt/mysql-2-backup

Recommended Posts

Mount and format Disk on Ubuntu on GCP.
Changed partition mount point on Ubuntu
Install Mecab and mecab-python3 on Ubuntu 14.04
Install and run dropbox on Ubuntu 20.04
Install OpenCV and Chainer on Ubuntu
Install CUDA 8.0 and Chainer on Ubuntu 16.04
Mount S3 on Ubuntu with goofys
Install fabric on Ubuntu and try
Build Python3 and OpenCV environment on Ubuntu 18.04
Python virtual environment and packages on Ubuntu
Install Puppet Master and Client on Ubuntu 16.04
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Manage Django images and static assets on Ubuntu
Shebang on Ubuntu 20.04
Install MongoDB on Ubuntu 16.04 and operate via python
Install Apache 2.4 on Ubuntu 19.10 Eoan Ermine and run CGI
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Dealing with pip and related installation errors on Ubuntu 18.04
Set up python and machine learning libraries on Ubuntu
Install TensorFlow on Ubuntu
Install PySide2 on Ubuntu
Install JModelica on Ubuntu
build Python on Ubuntu
Install Python 3.3 on Ubuntu 12.04
Installing pyenv on ubuntu 16.04
Install Theano on Ubuntu 12.04
Install angr on Ubuntu 18.04
Install pip / pip3 on Ubuntu
How to share OS and Vim clipboard on Ubuntu 18.04.3 LTS
Install python3 and scientific calculation library on Ubuntu (virtualenv + pip)
I installed FreeCAD on Linux (Ubuntu) and created an icon
Problems with `visudo` not working on Ubuntu 18.04 and its workaround
Precautions and solutions when installing Ubuntu on NVIDIA GeForce PCs