-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimage_write.sh
More file actions
44 lines (35 loc) · 1.23 KB
/
image_write.sh
File metadata and controls
44 lines (35 loc) · 1.23 KB
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
#!/bin/bash
function find_disk() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "To find the disk name on macOS:"
echo "1. Open Terminal."
echo "2. Run the command: diskutil list"
echo "3. Identify your disk (e.g., /dev/disk6) from the list."
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo "To find the disk name on Ubuntu:"
echo "1. Open Terminal."
echo "2. Run the command: lsblk"
echo "3. Identify your disk (e.g., /dev/sdb) from the list."
else
echo "Unsupported operating system: $OSTYPE"
exit 1
fi
}
find_disk
read -p "Please enter the disk name you want to write to (e.g., /dev/disk6 or /dev/sdb): " disk_name
img_path="img.img"
echo "Using default image file: $img_path"
if lsof | grep -q "$disk_name"; then
echo "Disk $disk_name is in use. You need to unmount it first."
exit 1
fi
echo "Unmounting disk $disk_name..."
if [[ "$OSTYPE" == "darwin"* ]]; then
diskutil unmountDisk "$disk_name"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
sudo umount "$disk_name"
fi
echo "Writing image file $img_path..."
sudo dd if="$img_path" of="$disk_name" bs=4M status=progress
sync
echo "Write operation completed. You can safely eject the disk."