blob: 7a91a2b4367366e52ff35231dd6754c8f984f98f (
plain)
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
|
kind: script
description: Create a deployment of the devel system
depends:
- filename: systems/devel-system.bst
type: build
- filename: deploy-tools.bst
type: build
variables:
# Size of the disk to create
#
# Should be able to calculate this based on the space
# used, however it must be a multiple of (63 * 512) bytes
# as mtools wants a size that is devisable by sectors (512 bytes)
# per track (63).
boot-size: 252000K
rootfs-size: 4G
swap-size: 1G
sector-size: 512
config:
base: deploy-tools.bst
input: systems/devel-system.bst
collect: "%{install-root}"
commands:
- |
# Split up the boot directory and the other
cd /buildstream
mkdir -p /buildstream/sda1
mkdir -p /buildstream/sda2
mv %{build-root}/boot/* /buildstream/sda1
mv %{build-root}/* /buildstream/sda2
- |
# Generate an fstab
cat > /buildstream/sda2/etc/fstab << EOF
/dev/sda2 / ext4 defaults,rw,noatime 0 1
/dev/sda1 /boot vfat defaults 0 2
/dev/sda3 none swap defaults 0 0
EOF
- |
# Create the syslinux config
mkdir -p /buildstream/sda1/syslinux
cat > /buildstream/sda1/syslinux/syslinux.cfg << EOF
PROMPT 0
TIMEOUT 5
ALLOWOPTIONS 1
SERIAL 0 115200
DEFAULT boot
LABEL boot
KERNEL /vmlinuz
INITRD /initramfs.gz
APPEND root=/dev/sda2 rootfstype=ext4 rootdelay=20 init=/usr/lib/systemd/systemd
EOF
- |
# Create the vfat image
truncate -s %{boot-size} /buildstream/sda1.img
mkdosfs /buildstream/sda1.img
- |
# Copy all that stuff into the image
mcopy -D s -i /buildstream/sda1.img -s /buildstream/sda1/* ::/
- |
# Install the bootloader on the image, it should get the config file
# from inside the vfat image, I think
syslinux --directory /syslinux/ /buildstream/sda1.img
- |
# Now create the root filesys on sda2
truncate -s %{rootfs-size} /buildstream/sda2.img
mkfs.ext4 -F -i 8192 /buildstream/sda2.img -L root -d /buildstream/sda2
- |
# Create swap
truncate -s %{swap-size} /buildstream/sda3.img
mkswap -L swap /buildstream/sda3.img
- |
########################################
# Partition the disk #
########################################
# First get the size in bytes
sda1size=$(stat --printf="%s" /buildstream/sda1.img)
sda2size=$(stat --printf="%s" /buildstream/sda2.img)
sda3size=$(stat --printf="%s" /buildstream/sda3.img)
# Now convert to sectors
sda1sec=$(( ${sda1size} / %{sector-size} ))
sda2sec=$(( ${sda2size} / %{sector-size} ))
sda3sec=$(( ${sda3size} / %{sector-size} ))
# Now get the offsets in sectors, first sector is MBR
sda1offset=1
sda2offset=$(( ${sda1offset} + ${sda1sec} ))
sda3offset=$(( ${sda2offset} + ${sda2sec} ))
# Get total disk size in sectors and bytes
sdasectors=$(( ${sda3offset} + ${sda3sec} ))
sdabytes=$(( ${sdasectors} * %{sector-size} ))
# Create the main disk and do the partitioning
truncate -s ${sdabytes} /buildstream/sda.img
parted -s /buildstream/sda.img mklabel msdos
parted -s /buildstream/sda.img unit s mkpart primary fat32 ${sda1offset} $(( ${sda1offset} + ${sda1sec} - 1 ))
parted -s /buildstream/sda.img unit s mkpart primary ext2 ${sda2offset} $(( ${sda2offset} + ${sda2sec} - 1 ))
parted -s /buildstream/sda.img unit s mkpart primary linux-swap ${sda3offset} $(( ${sda3offset} + ${sda3sec} - 1 ))
# Make partition 1 the boot partition
parted -s /buildstream/sda.img set 1 boot on
# Now splice the existing filesystems directly into the image
dd if=/buildstream/sda1.img of=/buildstream/sda.img \
ibs=%{sector-size} obs=%{sector-size} conv=notrunc \
count=${sda1sec} seek=${sda1offset}
dd if=/buildstream/sda2.img of=/buildstream/sda.img \
ibs=%{sector-size} obs=%{sector-size} conv=notrunc \
count=${sda2sec} seek=${sda2offset}
dd if=/buildstream/sda3.img of=/buildstream/sda.img \
ibs=%{sector-size} obs=%{sector-size} conv=notrunc \
count=${sda3sec} seek=${sda3offset}
- |
# Move the image where it will be collected
mv /buildstream/sda.img %{install-root}
chmod 0644 %{install-root}/sda.img
|