Skip to content

Instantly share code, notes, and snippets.

@svelleweetakealot
Created March 18, 2019 20:05
Show Gist options
  • Save svelleweetakealot/06105f6ed19a9bf5e780b52416477f82 to your computer and use it in GitHub Desktop.
Save svelleweetakealot/06105f6ed19a9bf5e780b52416477f82 to your computer and use it in GitHub Desktop.
Notes on UML basics.

From (this site)[https://www.kernel.org/doc/Documentation/kbuild/kconfig.txt]

You can cherry pick only a subset of config settings by using KCONFIG_ALLCONFIG variable.

Example:

Extract a linux kernel source file to a dir and change to that directory.

tar -xvf linux...tar.xz 
cd ~/linux-4.20.2/   # or whatever the linux source directory is called

Then make the mini.config with the settings you require. Remember to add the settings' required settings else the options you're interested in won't reflect.

cat <<EOF > mini.config
CONFIG_64BIT=y
CONFIG_X86_64=y
CONFIG_BINFMT_ELF=y
CONFIG_HOSTFS=y
CONFIG_BLOCK=y
CONFIG_LBD=y
CONFIG_BLK_DEV=y
CONFIG_BLK_DEV_LOOP=y
CONFIG_STDERR_CONSOLE=y
CONFIG_UNIX98_PTYS=y
CONFIG_EXT2_FS=y
CONFIG_MODULES=y
CONFIG_INOTIFY_USER=y
CONFIG_NET=y
CONFIG_UNIX=y
CONFIG_EXT3_FS=y
CONFIG_EXT4_FS=y
EOF

For example, I'd want CONFIG_EXT2_FS=y support, but that won't work unless I also add CONFIG_BLOCK=y.

Next create a target directory you wish to build in. I chose~/uml as my target directory.

mkdir ~/uml/

Now inside your linux directory seed the new ~/uml with your chosen settings:

make O=/home/stephan/uml ARCH=um  KCONFIG_ALLCONFIG=./mini.config allnoconfig

This roughly translates to, don't set any configs allnoconfig except what we specify using the mini.config. The ARCH=um tells the build system we want to build a usermode linux kernel.

Then start the actual build!

make O=/home/stephan/uml ARCH=um -j2

Then run using your hostfs as your root filesystem!

/home/stephan/uml/linux  /home/stephan/uml/linux rootfstype=hostfs rw init=/bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment