3

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?

Paul
  • 1,634
  • 15
  • 19

2 Answers2

2

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.

Paul
  • 1,634
  • 15
  • 19
1

The local SSD can be used directly as a block device without partitioning.

You can: mkfs.ext4 -F /dev/sdb

Kl4m
  • 361
  • 2
  • 6