-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMigrate.sh
More file actions
85 lines (65 loc) · 1.61 KB
/
Copy pathMigrate.sh
File metadata and controls
85 lines (65 loc) · 1.61 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
set -e
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}
check_command() {
if [ $? -ne 0 ]; then
log "Error: $1 failed"
exit 1
fi
}
log "Displaying PCI devices"
lspci
check_command "lspci"
log "Displaying block devices"
lsblk
check_command "lsblk"
log "Creating a new partition on the NVMe drive"
fdisk /dev/nvme0n1 << EOF
n
p
1
a
1
w
EOF
check_command "Creating partition"
log "Cloning SD card to NVMe drive"
dd if=/dev/mmcblk0 of=/dev/nvme0n1 bs=4M status=progress
check_command "Cloning SD card"
log "Syncing data to NVMe"
sync
log "Creating a new data partition on the NVMe drive"
fdisk /dev/nvme0n1 << EOF
n
p
4
w
EOF
check_command "Creating data partition"
log "Creating ext4 filesystem on the new partition"
mkfs.ext4 /dev/nvme0n1p4
check_command "Creating ext4 filesystem"
log "Creating mount point directory"
mkdir -p /mnt/data
check_command "Creating mount point"
log "Mounting the new partition"
mount /dev/nvme0n1p4 /mnt/data
check_command "Mounting partition"
log "Displaying mounted partition information"
df -h | grep /mnt/data
check_command "Displaying partition info"
log "Getting UUID of the new partition"
blkid /dev/nvme0n1p4
check_command "Getting partition UUID"
log "Setting ownership and permissions for /mnt/data"
chown rpi:rpi /mnt/data
chmod 775 /mnt/data
check_command "Setting ownership and permissions"
log "Adding entry to /etc/fstab for automatic mounting"
UUID=$(blkid -s UUID -o value /dev/nvme0n1p4)
echo "UUID=$UUID /mnt/data ext4 defaults 0 2" >> /etc/fstab
check_command "Updating /etc/fstab"
log "Script completed successfully. Rebooting..."
reboot