-
Notifications
You must be signed in to change notification settings - Fork 0
/
vultr_block.sh
executable file
·52 lines (40 loc) · 1.33 KB
/
vultr_block.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
# Prepare the block storage
prepare_block_storage() {
local device_name=$1
# Verify the device name
if [ ! -b "/dev/${device_name}" ]; then
echo "Device /dev/${device_name} not found."
return 1
fi
# Check if the device already has a partition
if lsblk "/dev/${device_name}" | grep -q "part"; then
echo "A partition already exists on /dev/${device_name}."
return 1
fi
# Create a new disk label
parted -s "/dev/${device_name}" mklabel gpt
# Make a primary partition
parted -s "/dev/${device_name}" unit mib mkpart primary 0% 100%
# Create an EXT4 filesystem
mkfs.ext4 "/dev/${device_name}1"
}
# Mount the block storage
mount_block_storage() {
local device_name=$1
local device_path="/dev/${device_name}1" # Assuming the first partition is to be mounted
local mount_point_base="/mnt"
local mount_point="${mount_point_base}/${device_name}"
# Check if the device exists
if [ ! -b "${device_path}" ]; then
echo "Device ${device_path} not found."
return 1
fi
# Create mount point
mkdir -p "${mount_point}"
# Add mount entry to /etc/fstab
echo "${device_path} ${mount_point} ext4 defaults,noatime,nofail 0 0" >> /etc/fstab
# Manually mount the block storage
mount "${mount_point}"
}
lsblk