A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://cloud.google.com/compute/docs/disks/format-mount-disk-linux below:

Format and mount a non-boot disk on a Linux VM | Compute Engine Documentation

Format and mount a non-boot disk on a Linux VM

Stay organized with collections Save and categorize content based on your preferences.

Linux

If you attached a new, blank disk to your VM, before you can use it you must format and mount the disk. If you attached a disk that already contains data, then you must mount the disk before you can use it.

Before you begin Connect to the VM
  1. Go to the VM instances page.

    Go to the VM instances page

  2. Click the SSH button next to the instance that has the new attached disk. The browser opens a terminal connection to the VM.

Format a non-boot disk on a Linux VM Permissions required for this task

To perform this task, you must have the following permissions:

If you are connecting to a VM instance that can run as a service account, you must also grant the roles/iam.serviceAccountUser role.

  1. In the terminal, use the symlink created for your attached disk to determine which device to format.

     ls -l /dev/disk/by-id/google-*
    

    Unformatted disks don't have additional symlinks with -partN in the name.

     google-extra-scsi-disk -> ../../sdb
     google-instance-2 -> ../../sda
     google-instance-2-part1 -> ../../sda1
     google-instance-2-part14 -> ../../sda14
     google-instance-2-part15 -> ../../sda15
     google-local-nvme-ssd-0 -> ../../nvme0n1
     google-local-nvme-ssd-1 -> ../../nvme0n2
    

    In this example, the new Persistent Disk was created with the name extra-scsi-disk. The device name for the new disk is sdb.

  2. Format the disk device using the mkfs tool. This command deletes all data from the specified disk, so make sure that you specify the disk device correctly.

    You can use any file format that you need, but we recommend a single ext4 file system without a partition table. You can increase the size of your disk later without having to modify disk partitions.

    To maximize disk performance, use the recommended formatting options with the -E flag. It is not necessary to reserve space for the root volume on this secondary disk, so specify -m 0 to use all of the available disk space. The following command formats the entire disk with no partition table.

     $ sudo mkfs.FILE_SYSTEM_TYPE -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/DEVICE_NAME
     

    Replace the following:

Mount the disk
  1. 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/MOUNT_DIR
    

    Replace MOUNT_DIR with the directory at which to mount disk.

  2. Use the mount tool to mount the disk to the instance, and enable the discard option:

    $ sudo mount -o discard,defaults /dev/DEVICE_NAME /mnt/disks/MOUNT_DIR
    

    Replace the following:

  3. 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/MOUNT_DIR
    

    Replace MOUNT_DIR with the directory where you mounted your disk.

Configure automatic mounting on VM restart

Add the disk to your /etc/fstab file, so that the disk automatically mounts again when the VM restarts. On Linux operating systems, the device name can change with each reboot, but the device UUID always points to the same volume, even when you move disks between systems. Because of this, we recommend using the device UUID instead of the device name to configure automatic mounting on VM restart.

Note: If you use Container-Optimized OS, modifications to /etc/fstab don't persist across system reboots. To ensure the device is checked and mounted during boot, run the fsck and mount operations on the disk from your cloud-config's bootcmd section. See Mounting and formatting disks in the Container-Optimized OS documentation.
  1. Create a backup of your current /etc/fstab file.

    $ sudo cp /etc/fstab /etc/fstab.backup
    
  2. Use the blkid command to list the UUID for the disk.

    $ sudo blkid /dev/DEVICE_NAME
    
    /dev/DEVICE_NAME: UUID="a9e1c14b-f06a-47eb-adb7-622226fee060" BLOCK_SIZE="4096"
    TYPE="ext4" PARTUUID="593b3b75-108f-bd41-823d-b7e87d2a04d1"
    

    Replace the following:

  3. Open the /etc/fstab file in a text editor and create an entry that includes the UUID. For example:

    UUID=UUID_VALUE /mnt/disks/MOUNT_DIR FILE_SYSTEM_TYPE discard,defaults,MOUNT_OPTION 0 2
    

    Replace the following:

  4. Use the cat command to verify that your /etc/fstab entries are correct:

    $ cat /etc/fstab
    
    UUID=6B33-A686 /boot/efi vfat defaults 0 0
    UUID=UUID_VALUE /mnt/disks/MOUNT_DIR FILE_SYSTEM_TYPE discard,defaults,MOUNT_OPTION 0 2
    
    

Always keep the /etc/fstab file in sync with the devices that are attached to a VM. If you want to detach a disk or create a snapshot from the boot disk for a VM, edit the /etc/fstab file and remove the entry for the disk. Even if you set MOUNT_OPTION to nofail or nobootwait, remove the entry before you create your boot disk snapshot or detach the disk.

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-07 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["New or pre-existing disks attached to a Linux VM must be formatted and/or mounted before they can be used."],["Formatting a disk with the `mkfs` tool deletes all data, requiring correct disk device specification, and `ext4` is recommended for maximizing disk performance."],["Mounting a disk involves creating a mount point directory and using the `mount` tool, and you can set permissions such as universal write access using `chmod`."],["To ensure disks automatically mount on VM restart, you should add an entry to the `/etc/fstab` file using the disk's UUID instead of its device name."],["It is crucial to keep the `/etc/fstab` file updated to match the current disk configuration and remove disk entries before detaching or snapshotting."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4