forked from bin456789/reinstall
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ubuntu-storage-early.sh
141 lines (136 loc) · 2.97 KB
/
ubuntu-storage-early.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
get_xda() {
# 排除只读盘,vda 放前面
# 有的机器有sda和vda,vda是主硬盘,另一个盘是只读
for _xda in vda xda sda hda xvda nvme0n1; do
if [ -e "/sys/class/block/$_xda/ro" ] &&
[ "$(cat /sys/class/block/$_xda/ro)" = 0 ]; then
echo $_xda
return
fi
done
return 1
}
sed -i -E '/^\.{3}$/d' /autoinstall.yaml
echo 'storage:' >>/autoinstall.yaml
# 禁用 swap
cat <<EOF >>/autoinstall.yaml
swap:
size: 0
EOF
xda=$(get_xda)
# 是用 size 寻找分区,number 没什么用
# https://curtin.readthedocs.io/en/latest/topics/storage.html
size_os=$(lsblk -bn -o SIZE /dev/disk/by-label/os)
if parted "/dev/$xda" print | grep '^Partition Table' | grep gpt; then
# efi
if [ -e /dev/disk/by-label/efi ]; then
size_efi=$(lsblk -bn -o SIZE /dev/disk/by-label/efi)
cat <<EOF >>/autoinstall.yaml
config:
# disk
- ptable: gpt
path: /dev/$xda
preserve: true
type: disk
id: disk-xda
# efi 分区
- device: disk-xda
size: $size_efi
number: 1
preserve: true
grub_device: true
type: partition
id: partition-efi
- fstype: fat32
volume: partition-efi
type: format
id: format-efi
# os 分区
- device: disk-xda
size: $size_os
number: 2
preserve: true
type: partition
id: partition-os
- fstype: ext4
volume: partition-os
type: format
id: format-os
# mount
- path: /
device: format-os
type: mount
id: mount-os
- path: /boot/efi
device: format-efi
type: mount
id: mount-efi
EOF
else
# bios > 2t
size_biosboot=$(parted "/dev/$xda" unit b print | grep bios_grub | awk '{print $4}' | sed 's/B$//')
cat <<EOF >>/autoinstall.yaml
config:
# disk
- ptable: gpt
path: /dev/$xda
preserve: true
grub_device: true
type: disk
id: disk-xda
# biosboot 分区
- device: disk-xda
size: $size_biosboot
number: 1
preserve: true
type: partition
id: partition-biosboot
# os 分区
- device: disk-xda
size: $size_os
number: 2
preserve: true
type: partition
id: partition-os
- fstype: ext4
volume: partition-os
type: format
id: format-os
# mount
- path: /
device: format-os
type: mount
id: mount-os
EOF
fi
else
# bios
cat <<EOF >>/autoinstall.yaml
config:
# disk
- ptable: msdos
path: /dev/$xda
preserve: true
grub_device: true
type: disk
id: disk-xda
# os 分区
- device: disk-xda
size: $size_os
number: 1
preserve: true
type: partition
id: partition-os
- fstype: ext4
volume: partition-os
type: format
id: format-os
# mount
- path: /
device: format-os
type: mount
id: mount-os
EOF
fi
echo ... >>/autoinstall.yaml