Adding persistent disk to Compute Engine Instance
- Creating a Compute Engine VM
- Now go to Disks section
- Click on Create Disk
- Name: disk-1
- Location: Single Zone
- Region: us-central-1
- Zone: this should be same as of your virtual machine
- Source: Blank disk
- Disk type: Balanced persistent disk
- Size: 10 GB
- Click on Create
- Attaching the disk to VM, Go to VM Instance section
- Select the VM instance
- Click on Edit
- Scroll to Additional disks > Attach existing disk
- Disk: select disk-1
- Click Done
- Click Save
- Mounting the Disk on Operating System
- Connect to VM using SSH
- In the terminal, use the
lsblk
command to list the disks that are attached to your instance and find the disk that you want to format and mount. - Format the disk using the mkfs tool. This command deletes all data from the specified disk, so make sure that you specify the disk device correctly.
sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sdb
- Create a directory that serves as the mount point for the new disk on the VM. You can use any directory. The following example creates a directory under /mnt/disks/.
sudo mkdir -p /mnt/disks/new
- Use the mount tool to mount the disk to the instance, and enable the discard option:
sudo mount -o discard,defaults /dev/sdb /mnt/disks/new
- Configure read and write permissions on the disk. For this example, grant write access to the disk for all users.
sudo chmod a+w /mnt/disks/new
- Change directory to /mnt/disks/new
cd /mnt/disks/new
- Create some files in new disk
touch file1 file2 file3 file4
Comments are closed, but trackbacks and pingbacks are open.