archbox/README.md

198 lines
8.1 KiB
Markdown
Raw Normal View History

2020-10-28 03:17:12 +00:00
# Archbox
2021-02-13 16:07:59 +00:00
Installs Arch Linux inside a chroot environment.
2020-10-28 03:17:12 +00:00
## Why?
2021-02-13 16:07:59 +00:00
Ever since I'm running some niche distros like Void, Solus, I had a problem finding softwares I need in their not-so-large repositories, also I don't like how flatpak and snap works. so i decided to create an Arch Linux chroot environment everytime I distrohop. Why Arch Linux? They have a really, really good repositories, oh and don't mention how big AUR is.
2020-10-28 03:54:45 +00:00
## Installation
2020-11-17 18:14:00 +00:00
### Dependencies
- Bash
- Sed
2021-01-23 08:48:31 +00:00
- Curl
- Wget (Optional: use ```wget``` when it's installed)
- Aria2 (Optional: use ```aria2c``` when it's installed)
2020-11-17 18:14:00 +00:00
- Tar
2020-12-29 11:44:40 +00:00
- Desktop-file-utils
2021-01-20 08:17:45 +00:00
- Xorg-xhost (Optional: allowing users in Archbox to access X server)
2020-12-15 07:14:52 +00:00
- Zenity (Optional: for .desktop entry manager GUI)
2020-10-28 03:54:45 +00:00
### Installing Archbox
It's pretty easy, just run ```install.sh``` as root.
2021-02-13 16:07:59 +00:00
### Installing chroot environment
Before creating chroot environment, edit your chroot username in ```/etc/archbox.conf```, then do :
2020-10-29 05:16:49 +00:00
```
sudo archbox --create <archlinux tarball download link>
```
2020-11-09 14:16:29 +00:00
### Configuring filesystem automount
2021-01-24 15:10:13 +00:00
Execute ```archbox --mount``` on boot.
If you use systemd, you can create a systemd service with this syntax below (Assuming the install prefix is ```/usr/local```) :
2020-11-17 18:07:02 +00:00
```
[Unit]
Description=Archbox init
PartOf=multi-user.target
[Service]
2021-03-06 06:21:08 +00:00
ExecStart=/usr/local/share/archbox/bin/init start
2020-11-17 18:07:02 +00:00
Type=oneshot
User=root
[Install]
WantedBy=multi-user.target
```
Thanks to [@SamsiFPV](https://github.com/SamsiFPV)
2021-03-06 06:21:08 +00:00
If you don't use systemd, either create your own init service, or create a @reboot cronjob :
```
@reboot /usr/local/share/archbox/bin/init start
```
2021-02-13 16:07:59 +00:00
### Removing chroot environment
**IMPORTANT**, Make sure you've unmounted everything in chroot environment, it's better to remove the init script and reboot to unmount everything. if you can't reboot for some reason, do :
2021-01-22 13:33:49 +00:00
```
archbox -u
2021-01-22 13:33:49 +00:00
```
2021-02-19 08:36:10 +00:00
then do (Assuming the INSTALL_PATH is /var/archlinux) :
2021-01-22 13:33:49 +00:00
```
2021-02-19 08:36:10 +00:00
mount | grep /var/archlinux
2021-01-22 13:33:49 +00:00
```
2021-02-19 08:36:10 +00:00
make sure there's no mounted Archbox directories and then delete the Arch Linux directory :
2021-02-18 13:28:53 +00:00
```
rm -rf /var/archlinux
```
2021-02-13 16:07:59 +00:00
### Entering chroot environment
2020-10-29 05:16:49 +00:00
To enter chroot, do :
```
archbox --enter
```
2021-02-13 16:07:59 +00:00
### Executing commands in chroot environment
To execute commands inside chroot environment, do :
2020-10-29 05:16:49 +00:00
```
archbox <command>
```
for example, to update chroot, do :
```
archbox sudo pacman -Syu
```
2020-10-28 03:17:12 +00:00
### Optional steps
2021-02-19 01:43:06 +00:00
You may want to add these rules if you want to use Archbox without password (assuming the install prefix is ```/usr/local``` and you're in group ```wheel```) :
2020-10-28 03:17:12 +00:00
#### Sudo
2020-10-29 05:16:49 +00:00
```
2021-03-06 06:35:24 +00:00
%wheel ALL=(root) NOPASSWD: /usr/local/share/archbox/bin/enter,/usr/local/share/archbox/bin/exec,/usr/local/share/archbox/bin/uth,/usr/local/share/archbox/bin/init
2020-10-29 05:16:49 +00:00
```
2020-10-28 03:17:12 +00:00
#### Doas
2020-10-29 05:16:49 +00:00
```
2021-03-06 06:21:08 +00:00
permit nopass :wheel as root cmd /usr/local/share/archbox/bin/enter
permit nopass :wheel as root cmd /usr/local/share/archbox/bin/exec
permit nopass :wheel as root cmd /usr/local/share/archbox/bin/uth
permit nopass :wheel as root cmd /usr/local/share/archbox/bin/init
2020-10-29 05:16:49 +00:00
```
2020-10-28 03:54:45 +00:00
### Misc
2020-11-09 14:16:29 +00:00
#### Systemd services
2021-01-11 07:08:17 +00:00
Use ```archboxctl``` command to manage systemd services.
2021-01-12 17:25:53 +00:00
More info [here](https://github.com/lemniskett/archboxctl).
2020-11-10 04:16:25 +00:00
2021-01-12 17:25:53 +00:00
This isn't actually using systemd to start services, rather it parses systemd .service files and executes it.
##### Autostart services
2021-01-11 07:08:17 +00:00
To enable service on host boot, edit `/etc/archbox.conf` :
2020-11-10 04:16:25 +00:00
```
2021-01-13 05:59:07 +00:00
SERVICES=( vmware-networks-configuration vmware-networks vmware-usbarbitrator nginx )
2020-11-10 04:16:25 +00:00
```
2021-01-12 17:25:53 +00:00
Keep in mind that this doesn't resolve service dependencies, so you may need to enable the dependencies manually. you can use ```archboxctl desc <service>``` to read the .service file
##### Post-exec delay
Services are asynchronously started, if some services have some issues when starting together you may want to add post-exec delay.
```
SERVICES=( php-fpm:3 nginx )
```
This will add 3 seconds delay after executing php-fpm.
##### Start services immediately
2021-01-11 07:08:17 +00:00
To start services immediately, in Archbox, do :
2020-11-10 04:16:25 +00:00
```
2021-01-11 07:08:17 +00:00
sudo archboxctl exec <Service name>
2020-11-10 04:16:25 +00:00
```
##### Custom command on boot
You can create a shell script located at ```/etc/archbox.rc``` and ```archboxinit``` will execute it in Archbox on boot.
2020-12-15 07:37:51 +00:00
#### Desktop entries
2021-02-18 11:23:22 +00:00
Use ```archbox-desktop``` to install desktop entries in chroot to host (installed to ```~/.local/share/applications/archbox```), you'll need to add ```sudo``` (or ```doas```) rules to launch archbox without a password.
2020-10-28 03:54:45 +00:00
#### Lauching apps via rofi
2020-12-15 07:37:51 +00:00
Instead of opening terminal or installing desktop entries everytime you want to run application inside chroot, you may want to launch rofi inside chroot, install rofi and do :
2020-10-29 05:16:49 +00:00
```
2020-11-09 14:16:29 +00:00
archbox rofi -show drun
2020-10-29 05:16:49 +00:00
```
2021-02-18 11:23:22 +00:00
Just like desktop entries, you'll need to add ```sudo``` (or ```doas```) rules to launch archbox without a password.
2020-10-28 16:06:06 +00:00
#### Prompt
2020-10-29 17:29:44 +00:00
If you use bash with nerd font you could add a nice little Arch Linux icon in your prompt, add :
2020-10-29 05:16:49 +00:00
```
[[ -e /etc/arch-release ]] && export PS1=" $PS1"
```
to your ```~/.bashrc```
2021-02-13 16:07:59 +00:00
#### Adding environment variables
2020-10-29 06:12:09 +00:00
Edit ENV_VAR in ```/etc/archbox.conf```. For example, if you want to use qt5ct as Qt5 theme, edit it like this :
2020-10-29 06:11:29 +00:00
```
ENV_VAR="QT_QPA_PLATFORMTHEME=qt5ct"
```
2021-02-13 16:07:59 +00:00
An example with multiple environment variables.
2020-10-29 17:29:44 +00:00
```
ENV_VAR="QT_QPA_PLATFORMTHEME=qt5ct GTK_CSD=0 LD_PRELOAD=/var/home/lemniskett/git_repo/gtk3-nocsd/libgtk3-nocsd.so.0"
```
2021-01-12 17:25:53 +00:00
#### Adding more shared directories
Edit SHARED_FOLDER in ```/etc/archbox.conf```. For example:
```
SHARED_FOLDER=( /home /var/www )
```
To mount to different directory, use ```:``` separator :
```
SHARED_FOLDER=( /home /var/www:/host_webroot )
```
2020-11-02 10:01:55 +00:00
### Known issues
2020-12-28 12:25:59 +00:00
#### NixOS-specific issues
2021-01-10 08:22:02 +00:00
##### /run mounting
2020-12-28 12:25:59 +00:00
Mounting ```/run``` somehow breaks NixOS, set ```MOUNT_RUN``` in ```/etc/archbox.conf``` to anything other than ```yes``` to disable mounting ```/run```, then do :
```
archbox --mount-runtime-only
```
after user login to make XDG runtime directory accessible to chroot enviroment. make sure dbus unix:path is in XDG runtime directory too.
```
$ echo $XDG_RUNTIME_DIR
/run/user/1000
$ echo $DBUS_SESSION_BUS_ADDRESS
unix:path=/run/user/1000/bus
```
2021-01-29 07:20:52 +00:00
Or alternatively if you use WM-only, just disable mounting ```/run``` entirely and manually set XDG_RUNTIME_DIR into ```/tmp``` like ```/tmp/$(whoami)```, this is not recommended if you use systemd, stuffs like Pipewire, Desktop portal, etc may broke.
2021-01-10 08:22:02 +00:00
2021-01-10 08:24:48 +00:00
##### Archbox didn't access resources in /usr/share
2021-01-10 08:22:02 +00:00
In Archbox, Symlink ```/usr``` to ```/run/current-system/sw```:
```
sudo mkdir -p /run/current-system
2021-01-10 08:22:02 +00:00
sudo ln -s /usr /run/current-system/sw
```
make sure /run isn't mounted.
2020-11-25 12:32:58 +00:00
#### PulseAudio refused to connect
This can be caused by different dbus machine-id between chroot and host, copying ```/etc/machine-id``` from host to chroot should do the job.
2021-03-06 04:34:18 +00:00
#### XDG_RUNTIME_DIR is not visible in Archbox
Although /run is mounted in chroot environment on boot, XDG_RUNTIME_DIR sometimes is not visible in chroot environment, remounting /run will make it visible. do :
2020-11-02 10:01:55 +00:00
```
archbox --remount-run
```
2021-03-06 04:34:18 +00:00
after user login, And sometimes you need to kill every process that runs in XDG_RUNTIME_DIR when you log out, You need to reinstall archbox with ```--exp``` flag and use ```startx-killxdg``` instead of ```startx```, or run :
2020-12-11 19:04:08 +00:00
```
2021-03-06 07:06:42 +00:00
/usr/local/share/archbox/bin/uth killxdg
2020-12-11 19:04:08 +00:00
```
2021-03-06 04:34:18 +00:00
on logout. you can put it in ```/etc/gdm/PostSession/Default``` if you use GDM, or just disable mounting ```/run``` entirely, set ```MOUNT_RUN``` in ```/etc/archbox.conf``` to anything other than ```yes``` to disable mounting ```/run``` and do :
```
archbox --remount-run
```
after user login.
2020-11-12 15:20:54 +00:00
#### Polkit
```pkexec``` is kind of tricky to make it work in chroot, if you use rofi to launch GUI applications in chroot, you may not able to launch any ```.desktop``` files with ```Exec=pkexec...``` in it. If you really want them to work, you can do :
```
2020-11-13 05:00:16 +00:00
sudo ln -sf /usr/bin/sudo /usr/bin/pkexec
2020-11-12 15:20:54 +00:00
```
in chroot and prevent pacman from restoring ```/usr/bin/pkexec``` by editing ```NoExtract``` in ```/etc/pacman.conf```.
#### No sudo password in chroot by default.
You could use ```sudo``` in archbox, but you'll have no way to enter the password when doing e.g. ```archbox sudo pacman -Syu```. also you could enter the password if you do ```archbox -e < <(echo $COMMAND)```, but that would disable stdin entirely during $COMMAND.