{"id":20041552,"url":"https://github.com/calebccff/c630_bootstrap","last_synced_at":"2025-03-02T07:13:44.130Z","repository":{"id":110396356,"uuid":"574295259","full_name":"calebccff/c630_bootstrap","owner":"calebccff","description":"notes and musings for bootstrapping Arch Linux on the Yoga C630","archived":false,"fork":false,"pushed_at":"2022-12-05T01:35:35.000Z","size":10,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-12T19:27:13.638Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/calebccff.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-05T01:35:23.000Z","updated_at":"2024-12-09T03:41:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"ef084e20-3f88-43ac-afd7-869bec88da46","html_url":"https://github.com/calebccff/c630_bootstrap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebccff%2Fc630_bootstrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebccff%2Fc630_bootstrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebccff%2Fc630_bootstrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/calebccff%2Fc630_bootstrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/calebccff","download_url":"https://codeload.github.com/calebccff/c630_bootstrap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241470401,"owners_count":19968041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T10:47:02.794Z","updated_at":"2025-03-02T07:13:44.081Z","avatar_url":"https://github.com/calebccff.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# C630 Arch Linux setup\n\n## Build image\n\n### Setup rootfs\n\n```bash\nmkdir rootfs\nfallocate -l 4G rootfs.img\nmkfs.ext4 rootfs.img\nmount rootfs.img rootfs\nbsdtar -xpf ArchLinuxARM-aarch64-latest.tar.gz -C /rootfs\n# chroot to the container, you can also use arch-chroot from arch-install-scripts\nsudo systemd-nspawn -D /rootfs\n```\n\n### Setup pacman\n\nIf using systemd-resolved on your host... (and /etc/resolv.conf is a symlink)\n```bash\nrm /etc/resolv.conf\necho \"nameserver 1.1.1.1\" \u003e /etc/resolv.conf\n```\n\n\n```bash\npasswd\n\npacman-key --init\npacman-key --populate archlinuxarm\npacman-key --refresh-keys\npacman-key --lsign-key 77193F152BDBE6A6    # Arch Linux ARM Build System \u003cbuilder@archlinuxarm.org\u003e\npacman -Rdd linux-aarch64\npacman -Syyu neofetch htop vim terminus-font sudo grub linux-firmware-qcom arch-install-scripts efibootmgr rmtfs wget iwd\n# We need these for wifi later... (Expect these links to break)\nwget https://gitlab.com/kupfer/packages/prebuilts/-/raw/main/aarch64/main/tqftpserv-git-r12.783425b-2-aarch64.pkg.tar.xz\nwget https://gitlab.com/kupfer/packages/prebuilts/-/raw/main/aarch64/main/pd-mapper-git-r13.d7fe25f-2-aarch64.pkg.tar.xz\npacman -U *.xz\nrm *.xz\n\nsed -e '0,/^#en_US/s//en_US/' -i /etc/locale.gen\nlocale-gen\necho -e 'LANG=en_US.UTF-8\\nLC_COLLATE=C' \u003e /etc/locale.conf\n\nuserdel alarm\nuseradd -g users -G wheel,storage,disk,rfkill,network,input,log -m YOURUSER # Pick your own\npasswd YOURUSER\necho 'HOSTNAME' \u003e /etc/hostname # Pick your own\n# Enable sudo\nsed -i 's/%wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/g' /etc/sudoers\n```\n\n### Add firmware\n\nOn your host:\n\n```bash\ngit clone https://gitlab.com/sdm845-mainline/firmware-lenovo-yogac630\nsudo rsync -rv firmware-lenovo-yogac630/lib/firmware/qcom rootfs/usr/lib/firmware/\nsudo rsync -rv firmware-lenovo-yogac630/lib/firmware/postmarketos/* rootfs/usr/lib/firmware/\n```\n\n\n### Set up grub\n\nBack in the container.. Set the following in `/etc/default/grub`:\n\n```bash\n# Adjust/remove earlycon and serial console. This will put kernel logs on tty2\nGRUB_CMDLINE_LINUX_DEFAULT=\"ignore_loglevel earlycon=qcom_geni clk_ignore_unused console=ttyMSM0,115200 console=tty2\"\n# For grub over Serial\nGRUB_TERMINAL_INPUT=\"console serial\"\nGRUB_TERMINAL_OUTPUT=\"gfxterm serial\"\nGRUB_SERIAL_COMMAND=\"serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1\"\n# Devicetree requires some changes to grub-mkconfig\nGRUB_DEVICETREE=\"sdm850-lenovo-yoga-c630\"\n```\n\nEdit `/usr/bin/grub-mkconfig` and add `GRUB_DEVICETREE` to the list (find `export GRUB_DEFAULT`):\n\n```bash\n...\n  GRUB_DEVICETREE \\\n...\n```\n\n\nFor auto-generated grub config, the following snippet needs to be added to `/etc/grub.d/10_linux`:\n\n```bash\n# Add the following before the line \"if test -n \"${initrd}\" ; then\"\n  if [ -n \"${GRUB_DEVICETREE}\" ]; then\n    message=\"$(gettext_printf \"Loading devicetree ...\")\"\n    sed \"s/^/$submenu_indentation/\" \u003c\u003c EOF\n        echo    '$(echo \"$message\" | grub_quote)'\n        devicetree ${rel_dirname}/dtbs/${GRUB_DEVICETREE}.dtb\nEOF\n  fi\n```\n\n### Set up wifi\n\nIn container:\n\n```bash\nsystemctl enable rmtfs pd-mapper tqftpserv iwd\n\necho \u003c\u003c EOF \u003e /etc/systemd/network/20-wifi.network\n[Match]\nName=wlan0\n\n[Network]\nDHCP=yes\nEOF\n\n```\n\n### Install kernel\n\nIt's easiest to do this manually the first time to bootstrap, then just copy\nartifacts from the host and package them on device, or self-host or whatever.\n\nIn your kernel source directory:\n\n```bash\n# Copy in kernel and DTB\nsudo install .output/arch/arm64/boot/Image.gz /path/to/rootfs/boot/vmlinuz-c630\nsudo install -D .output/arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dtb /path/to/rootfs/boot/dtbs/\n# Install kernel modules (to /usr because /lib is a symlink to /usr/lib)\nsudo make O=.output ARCH=arm64 INSTALL_MOD_PATH=/hdd/cartel/mainline/c630/arch/rootfs/usr modules_install\n# Record the kernel release (also make a note of it)\nmake O=.output ARCH=arm64 kernelrelease | sudo tee /path/to/rootfs/boot/kernel-release\n```\n\nCreate an mkinitcpio preset for the kernel: `/etc/mkinitcpio.d/linux-c630.preset`:\n\n```bash\nALL_config=\"/etc/mkinitcpio.conf\"\nALL_kver=\"KERNELRELEASE_FROM_EARLIER\" # Set your kernel release here (e.g. 6.1.0-rc6-sdm845+)\n\nPRESETS=('default')\n\ndefault_image=\"/boot/initramfs-c630.img\"\n```\n\nCreate an install hook to add firmware and kernel modules: `/usr/lib/initcpio/install/c630`:\n\n```bash\n#!/bin/bash\n\nbuild() {\n        # Probably a few more modules are needed depending\n        # on the kernel config you use...\n        add_module ufs_qcom\n        add_module ti_sn65dsi86\n\n        add_file /usr/lib/firmware/qcom/LENOVO/81JL/qcdxkmsuc850.mbn\n        add_file /usr/lib/firmware/qcom/a630_gmu.bin\n        add_file /usr/lib/firmware/qcom/a630_sqe.fw\n        add_file /usr/lib/firmware/ipa_fws.mdt\n}\n\nhelp() {\n    cat \u003c\u003cHELPEOF\nLenovo Yoga C630 firmware and modules required in ramdisk\nHELPEOF\n}\n```\n\nAdd the install hook to `/etc/mkinitcpio.conf`: `HOOKS=(... c630 ...)`.\n\nBuild a new initramfs and grub config:\n\n```bash\nmkinitcpio -p linux-c630\ngrub-mkconfig -o /boot/grub/grub.cfg\n```\n\nFormat your temporary bootable USB with a labelled fat32 boot partition and ext4\nroot partition. Make sure you set the ESP flag on the boot partition.\n\nMount them and sync over the rootfs:\n\n```bash\nmount /dev/sdX2 mnt\nmount /dev/sdX1 mnt/boot\nsudo rsync -raxWHAX --info=progress2 rootfs mnt\n```\n\n### Set up the bootloader\n\nUnfortunately this seems to _require_ arch-chroot otherwise grub-install fails\n```\nsudo arch-chroot mnt\ngrub-install --efi-directory=/boot --removable --no-nvram\n```\n\nFinally copy the rootfs image to the USB and unmount it. We want a copy of the\nimage so we can flash it to the internal storage more easily.\n\n```bash\nsudo umount rootfs\nsudo cp rootfs.img mnt/srv/\nsudo umount -R mnt\nsync\n# If this takes a while you can watch the progress with\nwatch -n1 \"cat /proc/meminfo | grep Dirty\"\n```\n\n## Install Arch Linux\n\nSet up internal storage and copy over the rootfs\n\n```bash\n# Manually mount the bootable USB boot partition\nmkfs.ext4 -L root /dev/sda5 # Replace with your rootfs partition...\nmount /dev/sda5 /mnt\nmount /dev/sda1 /mnt/boot\nmkdir /rootmnt\nmount /srv/rootfs.img /rootmnt\n# Copy over the rootfs image\nrsync -raxWHAX --info=progress2 /rootmnt /mnt\n```\n\nWe need to redo the final steps to set up the bootloader and mountpoints\n\n```bash\ngenfstab -U /mnt \u003e\u003e /mnt/etc/fstab\narch-chroot /mnt\ngrub-mkconfig -o /boot/grub/grub.cfg\n# Drop the --removable to have grub run efibootmgr to add a boot entry for itself instead\ngrub-install --efi-directory=/boot --removable --no-nvram\n```\n\nThis should be it! Install base-devel, git and set up yay. Install your DE of choice... off to the races\n\n## Upgrading the kernel\n\nBuild your new kernel, stick modules in /usr/lib/modules/ and image in\n/boot/vmlinuz-c630. Modify /etc/mkinitcpio.d/linux-c630.preset to point to the\nnew kernel release. Do:\n\n```bash\nmkinitcpio -p linux-c630\ngrub-mkconfig -o /boot/grub/grub.cfg\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalebccff%2Fc630_bootstrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcalebccff%2Fc630_bootstrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalebccff%2Fc630_bootstrap/lists"}