-
Notifications
You must be signed in to change notification settings - Fork 0
/
format-and-mount-partitions
46 lines (34 loc) · 1.24 KB
/
format-and-mount-partitions
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
rm -rf $mount_dir
# for device_to_mount in $(ls -1 /dev/${dev}?*); do
# device_short=${device_to_mount:5}
# mount_point=${mount_dir}$device_short
# echo "mounting $device_to_mount to $mount_point"
# mkdir -p $mount_point
# sudo mount $device_to_mount $mount_point
# done
# ----------------------------------
mount_partition() {
local dev_nr=$1
sudo mount /dev/${device}$dev_nr ${mount_dir}${device}${dev_nr} # -o uid=$(id -u),gid=$(id -g)
sudo chown -R $(id -u):$(id -g) ${mount_dir}${device}${dev_nr}
}
format_and_mount() {
local dev_nr=$1
mkdir -p ${mount_dir}${device}${dev_nr}
# Wipe partition
local logical_block_size=$(cat /sys/block/$device/queue/logical_block_size)
local size=$(cat /sys/block/$device/${device}${dev_nr}/size) # size in block size?
# use dd to overwrite partition.
# status=none only writes error messages.
sudo dd if=/dev/zero of=/dev/${device}${dev_nr} bs=$logical_block_size count=$size status=none
echo "formatting /dev/${device}$dev_nr"
sudo mkfs.ext4 /dev/${device}$dev_nr -q # -q: quiet mode
mount_partition $dev_nr
}
# don't create 1
format_and_mount 2
format_and_mount 3
format_and_mount 4
format_and_mount 5
format_and_mount 6
# don't create 7