Skip to content

Commit b260281

Browse files
create/run: bindmount kernel source at /src/kernel
Add 9p bind mount for convenience, ensure uid matches for guest user so we can just map it. We let the foreign (i.e. cross-compiled) version bitrot for now as it's already somewhat bitrotted, will return to that if I need to use it.
1 parent ec29c47 commit b260281

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

kerndev-create

+9-7
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ echo Running chroot-ed rootfs image config script...
6767
cp $chroot_script_path /mnt/chroot.sh
6868
# Copy ssh keys + config.
6969
cp -R /home/$SUDO_USER/.ssh /mnt/
70-
arch-chroot /mnt /chroot.sh $SUDO_USER $ROOT_PASSWORD
70+
arch-chroot /mnt /chroot.sh $SUDO_USER $(id -u $SUDO_USER) $ROOT_PASSWORD
7171
rm /mnt/chroot.sh
7272
# arch-chroot mounts the system's /etc/resolv.conf, so do this outside the
7373
# chroot.
@@ -116,13 +116,15 @@ fi
116116
unmount
117117
trap - EXIT
118118

119-
echo Building linux...
120-
# Install separately so we can update user on progress separately, also this
121-
# means we can run as the user and thus not write root owned files!
122-
NO_DONE=y DONT_INSTALL=y sudo -E -u $SUDO_USER kerndev-build
119+
if [[ -n "$KERNEL_BUILD_ON_CREATE" ]]; then
120+
echo Building linux...
121+
# Install separately so we can update user on progress separately, also this
122+
# means we can run as the user and thus not write root owned files!
123+
NO_DONE=y DONT_INSTALL=y sudo -E -u $SUDO_USER kerndev-build
123124

124-
echo Installing modules into image...
125-
NO_DONE=y kerndev-install
125+
echo Installing modules into image...
126+
NO_DONE=y kerndev-install
127+
fi
126128

127129
pop
128130

kerndev-create.chroot.sh

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ CONSOLE_COLS=${CONSOLE_COLS:-80}
88

99
# Passed by calling script.
1010
username=$1 # == $SUDO_USER
11-
password=$2 # Optional, if not provided script will prompt.
11+
uid=$2 # The user ID associated with $username so we can sync bindmount.
12+
password=$3 # Optional, if not provided script will prompt.
1213

1314
# Functions.
1415

@@ -44,6 +45,8 @@ echo "nohook resolv.conf" >> /etc/dhcpcd.conf
4445
# No delay for incorrect password reattempt. Pet peeve!
4546
sed -i 's/try_first_pass/try_first_pass nodelay/' /etc/pam.d/system-auth
4647
echo tux > /etc/hostname
48+
# Set up directory for kernel source bindmount.
49+
mkdir -p /src/kernel
4750

4851
# Now get the packages we want.
4952
echo Installing packages...
@@ -62,7 +65,7 @@ else
6265
fi
6366

6467
echo Setting up user $username with auto-login...
65-
useradd -m $username -G wheel >&/dev/null || true
68+
useradd -m $username -u $uid -G wheel >&/dev/null || true
6669
passwd -d $username >/dev/null
6770
echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers
6871
mkdir -p /etc/systemd/system/serial-getty@ttyS0.service.d
@@ -89,6 +92,8 @@ EOF
8992
chmod +x /usr/bin/leave
9093
mv /.ssh /home/$username/
9194
chown -R $username:$username /home/$username/.ssh
95+
chown -R $username:$username /src
96+
echo "kernel /src/kernel 9p trans=virtio,version=9p2000.L 0 0" >> /etc/fstab
9297

9398
echo Configuring zsh...
9499

@@ -107,6 +112,11 @@ chsh -s /usr/bin/zsh $username >/dev/null
107112
cat >>$user_zshrc <<EOF
108113
stty icrnl
109114
stty rows $CONSOLE_ROWS cols $CONSOLE_COLS
115+
116+
# The bindmounted kernel source chokes on fancy git plugin. Stub it out.
117+
git_custom_status() {
118+
}
119+
110120
EOF
111121
chown $username:$username $user_zshrc
112122

kerndev-run

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ esac
104104

105105
# '-echr 0x02' moves escape key to C-b to avoid C-a getting nerfed.
106106
shared_opts="-nographic -s -echr 0x02"
107+
# We expose the kernel source as a 9p bindmount to /src/kernel in the guest.
108+
shared_opts+=" -virtfs local,path=$LINUX_DEV_PATH,mount_tag=kernel,security_model=mapped,id=kernel"
107109
# Can add the latter in case heavier log output is required -> console.
108110
shared_append="root=/dev/vda rw earlyprintk=ttyS0 nokaslr no_hash_pointers loglevel=2" #loglevel=7 systemd.journald.forward_to_console=1"
109111

0 commit comments

Comments
 (0)