|
NAMEwifibox-alpine —
wifibox based on Alpine Linux
INTRODUCTIONThe implementation of the wifibox(8) embedded wireless router is based on the use of a Linux-based guest operating system which can communicate with the host's wireless network card on behalf of the host. In order to meet the requirements of this setup, this has to be a system with a low resource footprint and easy to manage.Alpine Linux is an actively maintained, security-oriented, lightweight Linux distribution that is based on musl libc and busybox. For more information and introduction to the tools that are going to be used in the sections below, please visit the following sites:
IMPLEMENTATIONBy default, the guest is created with a root user, which is associated with a blank password. This can only be used to login to the guest via theconsole command of
wifibox(8),
no other services are configured for remote access.
Although the root user possesses unlimited access to every resource inside the guest, files cannot be changed immediately. Before any administrative operation, the root file system needs to be remounted in writeable mode. # mount -o remount,rw / That is because the guest is built in a way that it does not normally require any write access to the contents of the root file system. Everything that needs to be modified during the guest's run time is stored on dedicated file systems that are either memory-backed or shared with the host. This prevents the guest from damaging the system files on sudden shutdowns, which may occur due to short and strict time limits placed on the spin-down sequence, and lack of journaling enabled. For the same reasons, it is recommended to restore the original mounting strategy once all the changes have been made on the guest. # mount -o remount,ro / For the ease of management, the host shares configuration files with the services that are responsible for implementing the domain logic.
The generic configuration files are read from the /media/etc directory where the config 9P (VirtFS) share is mounted in read-only mode. From there, the files are hooked up in the system in the following ways.
The wpa_supplicant.conf configuration file is shared with the host through the /media/wpa directory where the wpa_config 9P (VirtFS) share is mounted. This will let wpa_supplicant change the contents when instructed to do so from the host through the forwarded control sockets and permitted by the configuration. The variable data files under the guest's /var directory are shared with the host by mounting the var 9P (VirtFS) share there. This includes streaming out all the logs under the /var/log directory, such as /var/log/dmesg or /var/log/messages so that the internal state of the guest can be tracked by accessing these files on the host. The contents of the /var/run directory will not be visible on the host, as it is stored only in the memory. STARTING, STOPPING, AND RESTARTING SERVICESEvery service running on the guest can be managed by the rc-service (locate and run OpenRC service) command, which is going to be used in this section. The list of actively managed services can be learned as follows.# rc-service --list The status of a specific service can be queried by the
# rc-service wpa_supplicant status Similary to this, the # rc-service networking restart These commands can help with troubleshooting and restoring the respective services in case of failures. RESIZING THE FILE SYSTEMThe size of the disk image is optimized, and no free space left on the root file system. In result, installation of further packages or performing a system upgrade requires changing the size of the root file system as well as that of the enclosing disk image. This can be achieved with the help of specific tools, described below shortly.Such operations must always be considered on two levels: the size of the disk image needs to be changed on the host, and the size of the file system needs to be changed on the guest. The order of the corresponding commands must always reflect the direction of the change in size to avoid losing data. For growing the root file system, increase the size of the disk image to the desired capacity with the truncate(1) utility. For example, consider extending the virtual disk to 1 gigabyte. # truncate -s 1G disk.img The guest has to be restarted to notice the change in the disk parameters. # wifibox restart guest Once the # cfdisk The # mount -o remount,rw / # resize2fs /dev/vda1 For shrinking the root file system, the size of the root file
system has to be decreased first. This can be implemented by the
Through the following set of commands, a tmpfs-backed file system is created and populated with the contents of the root so it could take over its place in the next steps. mkdir /tmp/tmproot mount -t tmpfs tmpfs /tmp/tmproot for dir in oldroot dev proc sys run tmp boot; do \ mkdir /tmp/tmproot/$dir; done for dir in bin etc home lib media mnt opt root sbin srv usr var; do \ cp -a /$dir /tmp/tmproot/$dir; done Then the cd /tmp/tmproot pivot_root . oldroot for dir in boot dev proc run sys media/etc media/var; do \ mount --move /oldroot/$dir /$dir; done mount -t tmpfs tmpfs /tmp Since all the services, including the # kill -QUIT 1 Login and restart the # rc-service networking restart Now it should be possible to detach the old root file system. # umount /oldroot In case this previous command fails, it is recommended to use the
# fuser -m /oldroot If the old root file system has been successfully unmounted, it
must be checked for errors first and it must be marked clean, otherwise
# e2fsck -f /dev/vda1 # resize2fs -M /dev/vda1 After the successful shrinking of the file system, the
# dumpe2fs -h /dev/vda1 | fgrep "Block count:" | cut -c27- This value has to be multipled by 8 to get the number of sectors
for the new partition size. This ratio comes from the difference of file
system block size, which is 4096 bytes, and the sector size, which is 512
bytes. Once this is learnt, # cfdisk Before leaving the # truncate -s `expr 745472 \* 512` disk.img Restore the guest memory to the standard setting and restart the guest to make it pick up the changes in the disk parameters, also to give back the extra memory to the host. # wifibox restart guest INSTALLING OR REMOVING PACKAGESThe list of installed packages can be queried by the apk (Alpine Package Keeper) tool. This tool is going to be used for the rest of the section.# apk list --installed Note that the amount of memory configured for the guest might not be enough for the next steps. Raise it to around 128 MB if it has not been set like that already. Once prepared, it is possible to proceed with getting the latest version of the database. The apk tool stores the list of currently used package repositories in the /etc/apk/repositories file. # apk update Individual packages can be then installed by the
# apk add wireless-tools The unneeded packages can be removed by the
# apk del wireless-tools PERFORMING UPGRADESIt is possible to upgrade the operating system running on the guest to receive fixes for the kernel, drivers, and the userland programs. The entire process can be managed with the help of the apk tool.First make sure that the local package database is brought in sync with latest versions of the configured repositories. This can be verified by checking that the proper version numbers are used in the /etc/apk/repositories file. In addition to this, before moving between major or minor versions, e.g. from Alpine Linux 3.14 to 3.15, it is important to ensure that the system is on the latest available version for the current branch, and then try to pull the package index for the next major or minor version. That is required otherwise apk may report an untrusted signature due to lack of the necessary certificates to verify the fresh ones. As soon as everything is properly prepared, refresh the package index. # apk update The system can be then upgraded in a single step by using the
# apk upgrade --available Restart the guest for these changes to take effect, especially if the kernel or the firmware files received an update. # wifibox restart guest CAVEATSCustom modifications to the published guest disk images are not supported. Use these commands at your own risk!SEE ALSOwifibox(8), truncate(1)AUTHORSGábor Páli <pali.gabor@gmail.com>
Visit the GSP FreeBSD Man Page Interface. |