blob: 61224b1b06f7c5eb8288cf0a1d46ce73ed36982f [file] [log] [blame]
#x86 image default configuration
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:
# The element that should be staged into "/". It must contain
# all the tools required to generate the image
# base: image-tools.bst
# The element that should be staged into %{build-root}. It is expected
# to be the system that you're planning to turn into an image.
# input: foo-system.bst
filesystem-tree-setup-commands:
- |
# XXX Split up the boot directory and the other
#
# This should be changed so that the /boot directory
# is created separately.
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=/sbin/init
EOF
filesystem-image-creation-commands:
- |
# 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-commands:
- |
########################################
# 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}
final-commands:
- |
# Move the image where it will be collected
mv /buildstream/sda.img %{install-root}
chmod 0644 %{install-root}/sda.img