2

I am trying to set up a "scratch" local SSD on Google Cloud Platform / Google Compute Engine in a start script for a preemptable instance to be run on VM creation. No valuable data is on the VM when this script is run.

After creating a VM with a local SSD from gcloud or the web console, there is some setup to do on the VM.

Local SSD Documentation says I should:

  1. identify the ssd block device with lsblk
  2. format it with mkfs.ext4 -F /dev/[block-dev-from-part1]
  3. mount it somewhere && enjoy

But in step 2 I get an error that /dev/sdb1 is not found.

fdisk reveals that /dev/sdb exists but has no partition table.

I could use fdisk manually and that works, but how can I partition the SSD and setup in a start script?

1

If you are willing to take a chance that the SSD is always at /dev/sdb and that fdisk doesn't change their user interface, you can simply run fdisk and supply fdisk's input in an EOF block as follows:

#!/bin/bash
sleep 30
fdisk /dev/sdb <<EOF
n
p
1


w
EOF
mkfs.ext4 -F /dev/sdb1
mkdir /tmp/ssd
mount /dev/sdb1 /tmp/ssd
chmod 777 /tmp/ssd

The fdisk input is n for new, p for system partition, then 1 for partition 1, two blank lines to accept the defaults from fdisk, then w to write the partition table.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.