By default, the new disks attached during the instance creation cannot be used directly. You need to format and mount it to your instance to put that in use.
In this article, we will explain how to format and mount an extra disk to your google compute engine VM instance.
Note: We assume that you have created the VM instance with an extra disk attached to it.
Formatting and Mounting Extra Disk on VM Instance
1. Login to the instance and list the available extra disk using the following command.
sudo lsblk
An example output is shown below. All the extra disks will not have any entry under the MOUNTPOINT tab
. Here, sdb is
the extra disk that has to be formatted and mounted.
[devopscube@demo-mount ~]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 10G 0 disk └─sda1 8:1 0 10G 0 part / sdb 8:16 0 20G 0 disk
2. Next, we should format the disk to ext4 using the following command. In the below command we are mentioning /dev/sdb as that is the extra disk available.
sudo mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sdb
3. Next, create a mount directory on the instance as shown below. You can replace the /demo-mount
with a custom name and path you prefer.
sudo mkdir -p /demo-mount
4. Now, mount the disk to the directory we created using the following command.
sudo mount -o discard,defaults /dev/sdb /demo-mount
5. If you want write permissions to this disk for all the users, you can execute the following command. Or, based on the privileges you need for the disk, you can apply the user permissions.
sudo chmod a+w /demo-data
6. Check the mounted disk using the following command.
df -h
A sample output,
[devopscube@demo-mount]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 10G 2.3G 7.8G 23% / devtmpfs 842M 0 842M 0% /dev tmpfs 849M 0 849M 0% /dev/shm tmpfs 849M 8.4M 840M 1% /run tmpfs 849M 0 849M 0% /sys/fs/cgroup tmpfs 170M 0 170M 0% /run/user/1001 tmpfs 170M 0 170M 0% /run/user/0 /dev/sdb 20G 45M 20G 1% /demo-data
Automount Disk On Reboot
To automount the disk on system start or reboots, you need to add the mount entry to the fstab. Follow the steps given below for adding the mount to fstab.
1. First, back up the fstab file.
sudo cp /etc/fstab /etc/fstab.backup
2. Execute the following command to make a fstab entry with the UUID of the disk.
echo UUID=`sudo blkid -s UUID -o value /dev/sdb` /demo-mount ext4 discard,defaults,nofail 0 2 | sudo tee -a /etc/fstab
2. Check the UUID of the extra disk
sudo blkid -s UUID -o value /dev/sdb
3. Open fstab file and check for the new entry for the UUID of the extra disk
sudo cat /etc/fstab
Now, on every reboot, the disk will automatically mount to the defined folder based on the fstab entry.
The post How To Mount Extra Disks on Google Cloud VM Instance appeared first on DevopsCube.
Comments
Post a Comment