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:
- identify the ssd block device with
lsblk
- format it with
mkfs.ext4 -F /dev/[block-dev-from-part1]
- 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?
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:The fdisk input is
n
for new,p
for system partition, then1
for partition 1, two blank lines to accept the defaults from fdisk, thenw
to write the partition table.The local SSD can be used directly as a block device without partitioning.
You can:
mkfs.ext4 -F /dev/sdb