Skip to content

Commit 0f247df

Browse files
committed
Merge branch 'release/0.27.0'
2 parents 3fa585a + 342acad commit 0f247df

File tree

5 files changed

+147
-2
lines changed

5 files changed

+147
-2
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ scripts/aur/aur/
77
tmp/
88
output/
99
debug.test
10+
scripts/rootfs
11+
scripts/boot.img
12+
scripts/debs.tar.gz
13+
scripts/boot.vdi
14+
scripts/boot.vmdk

pkg/grub/grub_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
func TestAccess(t *testing.T) {
1010
t.Skip()
11-
err := PrepareAccessToDevice("/dev/sdd2", os.Stdout)
11+
err := PrepareAccessToDevice("/dev/sdd2", os.Stdout, false)
1212
if err != nil {
1313
t.Fatal(err)
1414
}
@@ -25,7 +25,7 @@ func TestKernel(t *testing.T) {
2525
func TestMenuEntry(t *testing.T) {
2626
t.Skip()
2727
err := MenuEntry("test entry", func(w io.Writer) error {
28-
err := PrepareAccessToDevice("/dev/sdd2", w)
28+
err := PrepareAccessToDevice("/dev/sdd2", w, false)
2929
if err != nil {
3030
return err
3131
}

pkg/staging/sort.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package staging
2+
3+
// ByAge implements sort.Interface for []Person based on
4+
// the Age field.
5+
type sortStageImageNamed []StagedImageNamed
6+
7+
func (a sortStageImageNamed) Len() int { return len(a) }
8+
func (a sortStageImageNamed) Less(i, j int) bool { return a[i].Ref.FullName() < a[j].Ref.FullName() }
9+
func (a sortStageImageNamed) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

pkg/staging/staging.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/godarch/darch/pkg/reference"
66
"io/ioutil"
77
"path"
8+
"sort"
89
"strings"
910
)
1011

@@ -41,6 +42,9 @@ func (session *Session) GetAllStaged() ([]StagedImageNamed, error) {
4142
})
4243
}
4344

45+
// Sort the images.
46+
sort.Sort(sortStageImageNamed(result))
47+
4448
return result, nil
4549
}
4650

scripts/gen-bootable-image.sh

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
function test-command() {
5+
command -v $1 >/dev/null 2>&1 || { echo >&2 "The command \"$1\" is required. Try \"apt-get install $2\"."; exit 1; }
6+
}
7+
8+
test-command debootstrap debootstrap
9+
test-command arch-chroot arch-install-scripts
10+
test-command genfstab arch-install-scripts
11+
test-command parted parted
12+
13+
# Download the debs to be used to install debian
14+
if [ ! -e "debs.tar.gz" ]; then
15+
debootstrap --verbose \
16+
--make-tarball=debs.tar.gz \
17+
--include=linux-image-amd64,grub2 \
18+
stable rootfs https://deb.debian.org/debian
19+
fi
20+
21+
# Create our hard disk
22+
rm -rf boot.img
23+
truncate -s 20G boot.img
24+
parted -s boot.img \
25+
mklabel msdos \
26+
mkpart primary 0% 2GiB \
27+
mkpart primary 2GiB 2.5GiB \
28+
mkpart primary 2.5GiB 3GiB \
29+
mkpart primary 3GiB 100%
30+
31+
# Partition layout:
32+
# 1. The base recovery os
33+
# 2. Darch configuration (/etc/darch)
34+
# 3. Home directory
35+
# 3. Darch stage/images
36+
37+
# Mount the newly created drive
38+
loop_device=`losetup --partscan --show --find boot.img`
39+
40+
# Format the partitions
41+
mkfs.ext4 ${loop_device}p1
42+
mkfs.ext4 ${loop_device}p2
43+
mkfs.ext4 ${loop_device}p3
44+
mkfs.ext4 ${loop_device}p4
45+
46+
# Mount the new partitions
47+
rm -rf rootfs && mkdir rootfs
48+
mount ${loop_device}p1 rootfs
49+
mkdir -p rootfs/etc/darch
50+
mount ${loop_device}p2 rootfs/etc/darch
51+
mkdir rootfs/home
52+
mount ${loop_device}p3 rootfs/home
53+
mkdir -p rootfs/var/lib/darch
54+
mount ${loop_device}p4 rootfs/var/lib/darch
55+
56+
# Generate the rootfs
57+
debootstrap --verbose \
58+
--unpack-tarball=$(pwd)/debs.tar.gz \
59+
--include=linux-image-amd64,grub2 \
60+
stable rootfs https://deb.debian.org/debian
61+
62+
# Generate fstab (removing comments and whitespace)
63+
genfstab -U -p rootfs | sed -e 's/#.*$//' -e '/^$/d' > rootfs/etc/fstab
64+
65+
# Set the computer name
66+
echo "darch-demo" > rootfs/etc/hostname
67+
68+
# Update all the packages
69+
arch-chroot rootfs apt-get update
70+
71+
# Install network manager for networking and SSH
72+
arch-chroot rootfs apt-get -y install network-manager openssh-server
73+
74+
# Install GRUB
75+
arch-chroot rootfs grub-install ${loop_device}
76+
arch-chroot rootfs grub-mkconfig -o /boot/grub/grub.cfg
77+
78+
# Create the default users
79+
arch-chroot rootfs apt-get -y install sudo
80+
arch-chroot rootfs /usr/bin/bash -c 'echo -en "root\nroot" | passwd'
81+
arch-chroot rootfs useradd -m -G users,sudo -s /usr/bin/bash darch
82+
arch-chroot rootfs /usr/bin/bash -c 'echo -en "darch\ndarch" | passwd darch'
83+
84+
# Install Darch
85+
arch-chroot rootfs apt-get -y install curl gnupg software-properties-common
86+
arch-chroot rootfs /bin/bash -c "curl -L https://raw.githubusercontent.com/godarch/debian-repo/master/key.pub | apt-key add -"
87+
arch-chroot rootfs add-apt-repository 'deb https://raw.githubusercontent.com/godarch/debian-repo/master/darch testing main'
88+
arch-chroot rootfs apt-get update
89+
arch-chroot rootfs apt-get -y install darch
90+
arch-chroot rootfs mkdir -p /etc/containerd
91+
echo "root = \"/var/lib/darch/containerd\"" > rootfs/etc/containerd/config.toml
92+
arch-chroot rootfs systemctl enable containerd
93+
94+
# Setup the fstab hooks for Darch
95+
cat rootfs/etc/fstab | tail -n +2 > rootfs/etc/darch/hooks/default_fstab
96+
echo "*=default_fstab" > rootfs/etc/darch/hooks/fstab.config
97+
98+
# Run grub-mkconfig again to ensure it loads the Darch grub config file
99+
arch-chroot rootfs grub-mkconfig -o /boot/grub/grub.cfg
100+
101+
# Clone our examples repo
102+
arch-chroot rootfs apt-get -y install git
103+
arch-chroot rootfs git clone https://github.com/godarch/example-recipes.git /home/darch/example-recipes
104+
arch-chroot rootfs mkdir /home/darch/Desktop
105+
arch-chroot rootfs ln -s /home/darch/example-recipes /home/darch/Desktop/Recipes
106+
arch-chroot rootfs chown -R darch:darch /home/darch/
107+
108+
# Clean up
109+
umount rootfs/etc/darch
110+
umount rootfs/var/lib/darch
111+
umount rootfs/home
112+
umount rootfs
113+
losetup -d ${loop_device}
114+
115+
echo "------------------------"
116+
echo "Finished creating the boot.img file."
117+
echo "This file bootable drive that could be dd'd directly to a drive, or converted to a virtual machine."
118+
echo ""
119+
echo "Commands for VMs"
120+
echo " VirtualBox: qemu-img convert -O vdi boot.img boot.vdi"
121+
echo " VMWare: qemu-img convert -O vmdk boot.img boot.vmdk"
122+
echo ""
123+
echo "NOTE: Ensure your VM has at least 4G of RAM allocated."
124+
echo ""
125+
echo "Please follow further instructions here:"
126+
echo "https://pknopf.com/post/2018-11-09-give-ubuntu-darch-a-quick-ride-in-a-virtual-machine/"
127+
echo "------------------------"

0 commit comments

Comments
 (0)