From 6bdcc59f94ecd2fd84facda953f92e1d2a5cf727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Fabian=20Silva=20Delgado?= Date: Fri, 4 May 2012 15:33:55 -0300 Subject: updating all files --- README | 361 +++++++++++++++-- archiso/Makefile | 44 +- archiso/archiso_pxe_nbd | 6 + archiso/archiso_shutdown | 40 ++ archiso/hooks/archiso | 210 +++++----- archiso/hooks/archiso_loop_mnt | 33 +- archiso/hooks/archiso_pxe_common | 42 ++ archiso/hooks/archiso_pxe_http | 61 +++ archiso/hooks/archiso_pxe_nbd | 73 +--- archiso/hooks/archiso_pxe_nfs | 26 ++ archiso/hooks/archiso_shutdown | 23 ++ archiso/install/archiso | 39 +- archiso/install/archiso_kms | 14 + archiso/install/archiso_loop_mnt | 15 +- archiso/install/archiso_pxe_common | 30 ++ archiso/install/archiso_pxe_http | 15 + archiso/install/archiso_pxe_nbd | 22 +- archiso/install/archiso_pxe_nfs | 16 + archiso/install/archiso_shutdown | 18 + archiso/mkarchiso | 257 ++++++++---- archiso/testiso | 10 +- configs/baseline/build.sh | 31 +- configs/baseline/mkinitcpio.conf | 2 +- configs/baseline/syslinux/syslinux.cfg | 8 +- configs/releng/build.sh | 450 +++++++++++++++------ configs/releng/efiboot/EFI/boot/startup.nsh | 10 + configs/releng/isolinux/isolinux.cfg | 4 +- configs/releng/mkinitcpio.conf | 2 +- configs/releng/packages.i686 | 10 +- configs/releng/packages.x86_64 | 10 +- configs/releng/root-image/etc/hosts | 4 +- configs/releng/root-image/etc/issue | 2 +- configs/releng/root-image/etc/motd | 3 - configs/releng/root-image/etc/rc.conf | 4 +- .../etc/rc.d/functions.d/automated_script | 10 +- .../rc.d/functions.d/symlink_used_block_devices | 7 + configs/releng/syslinux.dual/archiso.cfg | 11 + configs/releng/syslinux.dual/archiso_head.cfg | 25 ++ configs/releng/syslinux.dual/archiso_pxe32.cfg | 32 ++ configs/releng/syslinux.dual/archiso_pxe64.cfg | 32 ++ .../releng/syslinux.dual/archiso_pxe_32_inc.cfg | 3 + .../releng/syslinux.dual/archiso_pxe_both_inc.cfg | 4 + .../releng/syslinux.dual/archiso_pxe_choose.cfg | 11 + configs/releng/syslinux.dual/archiso_sys32.cfg | 9 + configs/releng/syslinux.dual/archiso_sys64.cfg | 9 + .../releng/syslinux.dual/archiso_sys_32_inc.cfg | 3 + .../releng/syslinux.dual/archiso_sys_both_inc.cfg | 4 + .../releng/syslinux.dual/archiso_sys_choose.cfg | 11 + configs/releng/syslinux.dual/archiso_tail.cfg | 27 ++ configs/releng/syslinux.dual/syslinux.cfg | 15 +- configs/releng/syslinux/archiso.cfg | 11 + configs/releng/syslinux/archiso_head.cfg | 25 ++ configs/releng/syslinux/archiso_pxe.cfg | 32 ++ configs/releng/syslinux/archiso_pxe_inc.cfg | 3 + configs/releng/syslinux/archiso_sys.cfg | 9 + configs/releng/syslinux/archiso_sys_inc.cfg | 3 + configs/releng/syslinux/archiso_tail.cfg | 27 ++ configs/releng/syslinux/syslinux.cfg | 73 +--- 58 files changed, 1692 insertions(+), 599 deletions(-) create mode 100644 archiso/archiso_pxe_nbd create mode 100644 archiso/archiso_shutdown create mode 100644 archiso/hooks/archiso_pxe_common create mode 100644 archiso/hooks/archiso_pxe_http create mode 100644 archiso/hooks/archiso_pxe_nfs create mode 100644 archiso/hooks/archiso_shutdown create mode 100644 archiso/install/archiso_kms create mode 100644 archiso/install/archiso_pxe_common create mode 100644 archiso/install/archiso_pxe_http create mode 100644 archiso/install/archiso_pxe_nfs create mode 100644 archiso/install/archiso_shutdown create mode 100644 configs/releng/efiboot/EFI/boot/startup.nsh create mode 100644 configs/releng/root-image/etc/rc.d/functions.d/symlink_used_block_devices create mode 100644 configs/releng/syslinux.dual/archiso.cfg create mode 100644 configs/releng/syslinux.dual/archiso_head.cfg create mode 100644 configs/releng/syslinux.dual/archiso_pxe32.cfg create mode 100644 configs/releng/syslinux.dual/archiso_pxe64.cfg create mode 100644 configs/releng/syslinux.dual/archiso_pxe_32_inc.cfg create mode 100644 configs/releng/syslinux.dual/archiso_pxe_both_inc.cfg create mode 100644 configs/releng/syslinux.dual/archiso_pxe_choose.cfg create mode 100644 configs/releng/syslinux.dual/archiso_sys32.cfg create mode 100644 configs/releng/syslinux.dual/archiso_sys64.cfg create mode 100644 configs/releng/syslinux.dual/archiso_sys_32_inc.cfg create mode 100644 configs/releng/syslinux.dual/archiso_sys_both_inc.cfg create mode 100644 configs/releng/syslinux.dual/archiso_sys_choose.cfg create mode 100644 configs/releng/syslinux.dual/archiso_tail.cfg create mode 100644 configs/releng/syslinux/archiso.cfg create mode 100644 configs/releng/syslinux/archiso_head.cfg create mode 100644 configs/releng/syslinux/archiso_pxe.cfg create mode 100644 configs/releng/syslinux/archiso_pxe_inc.cfg create mode 100644 configs/releng/syslinux/archiso_sys.cfg create mode 100644 configs/releng/syslinux/archiso_sys_inc.cfg create mode 100644 configs/releng/syslinux/archiso_tail.cfg diff --git a/README b/README index df37d35..d562b2e 100644 --- a/README +++ b/README @@ -5,14 +5,31 @@ This is a rebranded fork of the original Archiso for Parabola GNU/Linux-libre. * Boot parameters (initramfs stage) * hooks/archiso + * hooks/archiso_pxe_common * hooks/archiso_pxe_nbd + * hooks/archiso_pxe_http + * hooks/archiso_pxe_nfs * hooks/archiso_loop_mnt * Boot parameters (only for configs/releng) * etc/rc.conf +* Transfer ISO file to target medium (configs/releng) + * To -> CD / DVD / BD + * To -> USB-key / SD / HDD / SSD + * PC-BIOS (MBR) + * PC-BIOS (ISOHYBRID-MBR) + * PC-EFI (GPT) [x86_64 only] +* Alternative boot methods (configs/releng) + * ISO in loopback mode + * ISO in memdisk mode + * Network booting (PXE) [first stage] + * DHCP + TFTP + * DHCP + HTTP + * HTTP/NFS/NBD [second stage] * Build requirements * Image types generated by mkarchiso. * File format for aitab. * Why the /isolinux and /libre/boot/syslinux directories? +* Know issues * Building the most basic Parabola live media. (configs/baseline) * Building official Parabola live media. (configs/releng) @@ -37,15 +54,23 @@ This is a rebranded fork of the original Archiso for Parabola GNU/Linux-libre. performs a self-test of all files inside ${install_dir}, and continue booting if ok. Default: (unset) +* cow_label= Set the filesystem label where COW (dm-snapshot) + files must be stored. + Default: (unset) +* cow_device= Set the device node where COW (dm-snapshot) files + must be stored. + Default: (unset) or "/dev/disk/by-label/${cow_label}" +* cow_directory= Set a directory inside ${cow_device}. + Default: "/persistent_${archisolabel}/${arch}" +* cow_persistent= Set if snapshots are persistent "P" or non-persistent "N". + Default: "N" (if no ${cow_device} is used) otherwise "P". * cowspace_size= Set the size of tmpfs /cowspace. This space is used for Copy-On-Write files of dm-snapshot. - (directory not visible outside initramfs) Size is in bytes (suffix with "k", "m" and "g") or in percentage of available RAM. Default: "75%" -* copytoram_size= Set the size of tmpfs /cowpytoram. This space is used for +* copytoram_size= Set the size of tmpfs. This space is used for copy of all SquashFS images used, if copytoram=y. - (directory not visible outside initramfs) Size is in bytes (suffix with "k", "m" and "g") or in percentage of available RAM. Default: "75%" @@ -57,7 +82,7 @@ This is a rebranded fork of the original Archiso for Parabola GNU/Linux-libre. Default: (architecture of running kernel) -** hooks/archiso_pxe_nbd +** hooks/archiso_pxe_common * ip= This parameter is setup automatically by PXELINUX when option "IPAPPEND" is set to 1 or 2 in config. @@ -67,14 +92,53 @@ This is a rebranded fork of the original Archiso for Parabola GNU/Linux-libre. when option "IPAPPEND" is set to 2 or 3 in config. BOOTIF= Default: (set via PXELINUX) + + +** hooks/archiso_pxe_nbd + * archiso_nbd_name= Set NBD export name used by the server. Default: archiso +* archiso_nbd_srv= Set an IP address where NBD reside. + If ${pxeserver} is used, PXE IP will be used. + Default: (unset) + + +** hooks/archiso_pxe_http + +* archiso_http_srv= Set an HTTP URL (must end with /) where ${archisobasedir} + is found with all *.sfs files. + In the IP/domain part if ${pxeserver} is used, use PXE IP. + Default: (unset) +* archiso_http_spc= Set the size of tmpfs where *.sfs files are downloaded. + Default: "75%" + + +** hooks/archiso_pxe_nfs + +* archiso_nfs_srv= Set the NFS-IP:/path of the server + In the IP part if ${pxeserver} is used, PXE IP will be used. + Default: (unset) +* archiso_nfs_opt= Set NFS mount options separated by comma. + Default: (unset, see below) + These are the implicit options: + port = as given by server portmap daemon + rsize = 1024 + wsize = 1024 + timeo = 7 + retrans = 3 + acregmin = 3 + acregmax = 60 + acdirmin = 30 + acdirmax = 60 + flags = hard, nointr, noposix, cto, ac ** hooks/archiso_loop_mnt -* img_dev= Device where archiso-image.iso reside. +* img_label= Set the filesystem label where archiso-image.iso. Default: (unset) +* img_dev= Device where archiso-image.iso reside. + Default: (unset) or "/dev/disk/by-label/${img_label}" * img_loop= Full path where archiso-image.iso is located on ${img_dev} Default: (unset) @@ -98,23 +162,258 @@ if nothing is specified on command line. +*** Transfer ISO image to target medium (configs/releng) + +ISO images names consist of: parabola-..
--.iso + +Where: + Year + Month +
Day + netinstall | core + i686 | x86_64 | dual(*) + +(*) "dual" includes both i686 and x86_64 architectures. + + +** To -> CD / DVD / BD + +Note: All ISO images are booteable on a PC-BIOS via "El Torito" in no-emulation mode, + All x86_64 ISO images are booteable on a PC-EFI via "El Torito" in no-emulation mode. + +Nomeclature: + scsibus number + target number + lun number + (Note: see cdrecord -scanbus, for these numbers) + + +1) Write it directly using your favorite recording program. +# cdrecord dev=,, -dao parabola-..
--.iso + + +** To -> USB Flash Drive (USB-key) / Memory card (SD) / + Hard-Disk Drive (HDD) / Solid-State Drive (SSD) + +Note: These steps are the general workflow, you can skip some of them, + using another filesystem if your bootloader supports it, + installing to another directory than "arch/" or using more than + one partition. Just ensure that main boot params options + (archisolabel= and archisobasedir=) are set correctly according to your setup. + +Nomeclature: +: Device node of the drive where ISO contents should be copied + (example: /dev/sdx) +: Device node of the partition on + (example: /dev/sdx1) +: Mount point path where is mounted + (example: /mnt/sdx/1) +: Path to the ISO file parabola-..
--.iso + (example: ~/parabola-2012.04.16-netinstall-x86_64.iso) +: Represents the filesystem label of the + (example: LIBRE_201204 [for all ~/parabola-2012.04.*.iso]) + + +* PC-BIOS (MBR): + +Note: Using here a MBR partition mode as example, but GPT should also works + if machine firmware is not broken. + Just ensure that partition is set with attribute "2: legacy BIOS bootable" + and use gptmbr.bin instead of mbr.bin for syslinux. + +1) Create one partition entry in MBR (of type "b" for FAT32 or "83" for EXTFS) + and mark it as "active" (bootable). +# fdisk + +2) Create a FAT32 or EXTFS filesystem on such partition and setup a label. +# mkfs.vfat -F 32 -n +# mkfs.ext4 -L + +3) Mount target filesystem. +# mount + +4) Extract ISO image on target filesystem. +# bsdtar -x --exclude=isolinux/ --exclude=EFI/ -f -C + +5) Install syslinux bootloader on target filesystem. +# extlinux -i /arch/boot/syslinux + +6) Unmount target filesystem. +# umount + +7) Install syslinux MBR boot code on target drive. +# dd bs=440 count=1 conv=notrunc if=/usr/lib/syslinux/mbr.bin of= + + +* PC-BIOS (ISOHYBRID-MBR): + +Note: This method is the most easily, quick and dirty, but is the most limited + if you want to use your target medium for other purposes. + +1) Dump ISO file to target medium. +# dd if= of= + + +* PC-EFI (GPT) [x86_64 only] + +Note: Using here a GPT partition mode as example, but MBR should also works + if machine firmware is not broken. + +1) Create one partition entry in GPT (of type "ef00") +# gdisk + +2) Create a FAT32 filesystem on such partition and setup a label. +# mkfs.vfat -F 32 -n + +3) Mount target filesystem. +# mount + +4) Extract ISO image on target filesystem. +# bsdtar -x --exclude=isolinux/ --exclude=arch/boot/syslinux/ -f -C + +5) Extract efiboot.img on EFI/ on target filesystem. +# mcopy -s -i /EFI/archiso/efiboot.img ::/EFI / + +6) Remove uneeded efiboot.img +# rm /EFI/archiso/efiboot.img + +7) Unmount target filesystem. +# umount + + + +*** Alternative boot methods (configs/releng) + +** ISO in loopback mode. + +Note: Described method is for using with GRUB2. + GRUB2 is installed on target media and parabola-..
--.iso + is at path on disk and partition

, + where filesystem is labeled as . + +menuentry "Parabola GNU/Linux-libre (x86_64)" { + set isofile="//parabola-..

--.iso" + loopback loop (hd,

)$isofile + linux (loop)/arch/boot/x86_64/vmlinuz archisolabel= img_label= img_loop=$isofile + initrd (loop)/arch/boot/x86_64/libreiso.img +} + +menuentry "Parabola GNU/Linux-libre (i686)" { + set isofile="//parabola-..

--.iso" + loopback loop (hd,

)$isofile + linux (loop)/arch/boot/i686/vmlinuz archisolabel= img_label= img_loop=$isofile + initrd (loop)/arch/boot/i686/libreiso.img +} + + +** ISO in memdisk mode. + +Note: Described method is for using with SYSLINUX. Anyway MEMDISK from SYSLINUX can work + with other bootloaders. + SYSLINUX is installed on target media and parabola-..

--.iso + is at path . + On 32-bit systems, is needed to pass vmalloc=nnM to the kernel, where nn is the size + of the ISO image plus 64 MiB (or 128 MiB). + + +LABEL parabola_x64 + LINUX memdisk + INITRD //parabola-..
--.iso + APPEND iso + +LABEL parabola_x32 + LINUX memdisk + INITRD //parabola-..
--.iso + APPEND iso + + +** Network booting (PXE). + +All ISOs are ready to act as PXE server, some manual steps are needed +to setup the desired PXE boot mode. +Alternatively it is possible to use an existing PXE server following the same logic. +Note: Setup network first, adjust IP adresses, and respect all slashes "/". + +First stage is for loading kernel and initramfs via PXE, two methods described here: + +* DHCP + TFTP + +Note: All NIC firmwares should support this. + +# dnsmasq --port=0 \ + --enable-tftp \ + --tftp-root=/run/archiso/bootmnt \ + --dhcp-range=192.168.0.2,192.168.0.254,86400 \ + --dhcp-boot=/arch/boot/syslinux/gpxelinux.0 \ + --dhcp-option-force=209,boot/syslinux/archiso.cfg \ + --dhcp-option-force=210,/arch/ + +* DHCP + HTTP + +Note: Not all NIC firmware supports HTTP and DNS (if domain name is used). + At least this works with iPXE and gPXE. + +# dnsmasq --port=0 \ + --dhcp-range=192.168.0.2,192.168.0.254,86400 \ + --dhcp-boot=http://192.168.0.7/arch/boot/syslinux/gpxelinux.0 \ + --dhcp-option-force=209,boot/syslinux/archiso.cfg \ + --dhcp-option-force=210,http://192.168.0.7/arch/ + + +Once the kernel is started from PXE, SquashFS files and other misc files +inside "arch" directory must be loaded (second stage). One of the following +methods can be used to serve the rest of live-medium. + +* HTTP + +# darkhttpd /run/archiso/bootmnt + + +* NFS + +# echo "/run/archiso/bootmnt 192.168.0.*(ro,no_subtree_check,no_root_squash)" >> /etc/exports +# rc.d start rpcbind nfs-common nfs-server + + +* NBD + +Note: Adjust LIBRE_201204 as needed. + +# cat << EOF > /tmp/nbd-server.conf +[generic] +[archiso] + readonly = true + exportname = /dev/disk/by-label/LIBRE_201204 +EOF +# nbd-server -C /tmp/nbd-server.conf + + + *** Build requirements ** For mkarchiso script needs these packages (build host): - + devtools for mkarchroot + squashfs-tools for mksquashfs - + syslinux for isohybrid - + cdrkit for mkisofs + + libisoburn for xorriso + + rsync for rsync + +** For configs/releng build.sh needs theses packages (build host): + + dosfstools for mkfs.vfat ** For these hooks needs these packages (on target root-image) * archiso + (none) * archiso_loop_mnt + (none) -* archiso_pxe_nbd +* archiso_pxe_common + mkinitcpio-nfs-utils for ipconfig +* archiso_pxe_nbd + nbd for nbd-client - +* archiso_pxe_http + + curl for curl +* archiso_pxe_nfs + + mkinitcpio-nfs-utils for nfsmount +* archiso_shutdown + + (none) *** Image types generated by mkarchiso. @@ -123,10 +422,6 @@ if nothing is specified on command line. * image-name.fs.sfs SquashFS with only one file inside (image-name.fs), which is an image of some type of filesystem (ext4, ext3, ext2, xfs), all files reside on it. -* image-name.fs Like image-name.fs.sfs but without SquashFS. - (For testing purposes only. The option copytoram - for archiso hook does not have any effect on these images) - *** File format for aitab. @@ -141,7 +436,6 @@ It consists of some fields which define the behaviour of images. Mount point. Architecture { i686 | x86_64 | any }. SquashFS compression type { gzip | lzo | xz }. - A special value of "none" denotes no usage of SquashFS. Set the filesystem type of the image { ext4 | ext3 | ext2 | xfs }. A special value of "none" denotes no usage of a filesystem. In that case all files are pushed directly to SquashFS filesystem. @@ -152,9 +446,6 @@ It consists of some fields which define the behaviour of images. This is an estimation, and calculated in a simple way. Space used + 10% (estimated for metadata overhead) + desired % -Note: Some combinations are invalid, example: sfs_comp=none and fs_type=none - - *** Why the /isolinux and /arch/boot/syslinux directories? @@ -165,6 +456,16 @@ When make your custom boot-pendrive, you need to copy /libre directory to it. /isolinux/isolinux.cfg just holds /libre/boot/syslinux/syslinux.cfg +*** Know issues + +** On shutdown there are two steps that [FAIL]: + "Unmounting Swap-backed Filesystems" and "Unmounting Non-API Filesystems", + These filesystem are in use at this stage by archiso, but... + This is not a real issue since, all mounted filesystem, loopback devices + and device mapper devices made by archiso will be "free" on "shutdown tmpfs" + (A.K.A deinitramfs), build at initramfs by [archiso_shutdown] initcpio hook. + + *** Building the most basic Parabola live media. (configs/baseline) @@ -177,7 +478,7 @@ When make your custom boot-pendrive, you need to copy /libre directory to it. * Install archiso on chroot (needs git and make) [host] # pacman -S git make --needed - [host] # git clone git://projects.archlinux.org/archiso.git + [host] # git clone git://projects.parabolagnulinux.org/archiso.git [host] # make -C archiso/archiso DESTDIR=/tmp/chroot install * Enter to chroot (prefix with linux32 if needed). @@ -191,7 +492,7 @@ When make your custom boot-pendrive, you need to copy /libre directory to it. [chroot] # echo 'Server = http://repo.parabolagnulinux.org/$repo/os/$arch' >> /etc/pacman.d/mirrorlist * Install aditional packages needed for mkarchiso. - [chroot] # pacman -S devtools squashfs-tools syslinux cdrkit + [chroot] # pacman -S devtools squashfs-tools syslinux cdrkit libisoburn rsync * Build a basic iso. [chroot] # cp -r /usr/share/archiso/configs/baseline /tmp @@ -205,7 +506,6 @@ Note: If you want to customize, just see the configs/releng directory which is used to build official images with much more things. - *** Building official Parabola live media. (configs/releng) Note: These steps should be done with 64 bits support. @@ -215,7 +515,7 @@ Note: These steps should be done with 64 bits support. [host64] # linux32 mkarchroot /tmp/chroot32 base [host64] # linux32 mkarchroot -r bash /tmp/chroot32 [chroot32] # echo 'Server = http://repo.parabolagnulinux.org/$repo/os/$arch' >> /etc/pacman.d/mirrorlist - [chroot32] # pacman -S devtools squashfs-tools syslinux cdrkit + [chroot32] # pacman -S devtools squashfs-tools syslinux cdrkit rsync dosfstools [chroot32] # exit * Prepare a 64 bits chroot enviroment. @@ -223,7 +523,7 @@ Note: These steps should be done with 64 bits support. [host64] # mkarchroot /tmp/chroot64 base [host64] # mkarchroot -r bash /tmp/chroot64 [chroot64] # echo 'Server = http://repo.parabolagnulinux.org/$repo/os/$arch' >> /etc/pacman.d/mirrorlist - [chroot64] # pacman -S devtools squashfs-tools syslinux cdrkit + [chroot64] # pacman -S devtools squashfs-tools syslinux cdrkit rsync dosfstools [chroot64] # exit * Install archiso on both chroots. @@ -245,20 +545,17 @@ Note: These steps should be done with 64 bits support. [chroot32] # mknod /dev/loop1032 b 7 1032 #assumed loop.max_part=0 (by default) [chroot32] # cp -r /usr/share/archiso/configs/releng /tmp [chroot32] # cd /tmp/releng - [chroot32] # ./build.sh all_iso_single - [chroot32] # ./build.sh purge_single #optional +* Build them! + [chroot64] # cd /tmp/releng + [chroot64] # ./build.sh build all all * Enter 64 bits chroot enviroment then build core and netinstall single images. [chroot64] # mkarchroot -r bash /tmp/chroot64 [chroot64] # mknod /dev/loop1064 b 7 1064 #assumed loop.max_part=0 (by default) [chroot64] # cp -r /usr/share/archiso/configs/releng /tmp +* Build them! [chroot64] # cd /tmp/releng - [chroot64] # ./build.sh all_iso_single - [chroot64] # ./build.sh purge_single #optional + [chroot64] # ./build.sh build all all -* Build core and netinstall dual images from any of the chroot enviroments. - - [host64] # mkarchroot -r bash /tmp/chroot64 - [chroot64] # cd /tmp/releng - [chroot64] # ./build.sh all_iso_dual +Note: See build.sh -h for more options. diff --git a/archiso/Makefile b/archiso/Makefile index 60632e2..28868bf 100644 --- a/archiso/Makefile +++ b/archiso/Makefile @@ -10,12 +10,23 @@ install-program: install-hooks: # hooks/install are needed by mkinitcpio - install -D -m 644 hooks/archiso $(DESTDIR)/lib/initcpio/hooks/archiso - install -D -m 644 install/archiso $(DESTDIR)/lib/initcpio/install/archiso - install -D -m 644 hooks/archiso_pxe_nbd $(DESTDIR)/lib/initcpio/hooks/archiso_pxe_nbd - install -D -m 644 install/archiso_pxe_nbd $(DESTDIR)/lib/initcpio/install/archiso_pxe_nbd - install -D -m 644 hooks/archiso_loop_mnt $(DESTDIR)/lib/initcpio/hooks/archiso_loop_mnt - install -D -m 644 install/archiso_loop_mnt $(DESTDIR)/lib/initcpio/install/archiso_loop_mnt + install -D -m 644 hooks/archiso $(DESTDIR)/usr/lib/initcpio/hooks/archiso + install -D -m 644 install/archiso $(DESTDIR)/usr/lib/initcpio/install/archiso + install -D -m 755 archiso_shutdown $(DESTDIR)/usr/lib/initcpio/archiso_shutdown + install -D -m 644 hooks/archiso_shutdown $(DESTDIR)/usr/lib/initcpio/hooks/archiso_shutdown + install -D -m 644 install/archiso_shutdown $(DESTDIR)/usr/lib/initcpio/install/archiso_shutdown + install -D -m 644 archiso_pxe_nbd $(DESTDIR)/usr/lib/initcpio/archiso_pxe_nbd + install -D -m 644 hooks/archiso_pxe_common $(DESTDIR)/usr/lib/initcpio/hooks/archiso_pxe_common + install -D -m 644 install/archiso_pxe_common $(DESTDIR)/usr/lib/initcpio/install/archiso_pxe_common + install -D -m 644 hooks/archiso_pxe_nbd $(DESTDIR)/usr/lib/initcpio/hooks/archiso_pxe_nbd + install -D -m 644 install/archiso_pxe_nbd $(DESTDIR)/usr/lib/initcpio/install/archiso_pxe_nbd + install -D -m 644 hooks/archiso_pxe_http $(DESTDIR)/usr/lib/initcpio/hooks/archiso_pxe_http + install -D -m 644 install/archiso_pxe_http $(DESTDIR)/usr/lib/initcpio/install/archiso_pxe_http + install -D -m 644 hooks/archiso_pxe_nfs $(DESTDIR)/usr/lib/initcpio/hooks/archiso_pxe_nfs + install -D -m 644 install/archiso_pxe_nfs $(DESTDIR)/usr/lib/initcpio/install/archiso_pxe_nfs + install -D -m 644 hooks/archiso_loop_mnt $(DESTDIR)/usr/lib/initcpio/hooks/archiso_loop_mnt + install -D -m 644 install/archiso_loop_mnt $(DESTDIR)/usr/lib/initcpio/install/archiso_loop_mnt + install -D -m 644 install/archiso_kms $(DESTDIR)/usr/lib/initcpio/install/archiso_kms install-examples: # install examples @@ -29,10 +40,23 @@ install-doc: uninstall: rm -f $(DESTDIR)/usr/sbin/mkarchiso rm -f $(DESTDIR)/usr/bin/testiso - rm -f $(DESTDIR)/lib/initcpio/hooks/archiso - rm -f $(DESTDIR)/lib/initcpio/install/archiso - rm -f $(DESTDIR)/lib/initcpio/hooks/archiso_pxe_nbd - rm -f $(DESTDIR)/lib/initcpio/install/archiso_pxe_nbd + rm -f $(DESTDIR)/usr/lib/initcpio/hooks/archiso + rm -f $(DESTDIR)/usr/lib/initcpio/install/archiso + rm -f $(DESTDIR)/usr/lib/initcpio/archiso_shutdown + rm -f $(DESTDIR)/usr/lib/initcpio/hooks/archiso_shutdown + rm -f $(DESTDIR)/usr/lib/initcpio/install/archiso_shutdown + rm -f $(DESTDIR)/usr/lib/initcpio/archiso_pxe_nbd + rm -f $(DESTDIR)/usr/lib/initcpio/hooks/archiso_pxe_common + rm -f $(DESTDIR)/usr/lib/initcpio/install/archiso_pxe_common + rm -f $(DESTDIR)/usr/lib/initcpio/hooks/archiso_pxe_nbd + rm -f $(DESTDIR)/usr/lib/initcpio/install/archiso_pxe_nbd + rm -f $(DESTDIR)/usr/lib/initcpio/hooks/archiso_pxe_http + rm -f $(DESTDIR)/usr/lib/initcpio/install/archiso_pxe_http + rm -f $(DESTDIR)/usr/lib/initcpio/hooks/archiso_pxe_nfs + rm -f $(DESTDIR)/usr/lib/initcpio/install/archiso_pxe_nfs + rm -f $(DESTDIR)/usr/lib/initcpio/hooks/archiso_loop_mnt + rm -f $(DESTDIR)/usr/lib/initcpio/install/archiso_loop_mnt + rm -f $(DESTDIR)/usr/lib/initcpio/install/archiso_kms rm -rf $(DESTDIR)/usr/share/archiso/ .PHONY: install install-program install-hooks install-examples install-doc uninstall diff --git a/archiso/archiso_pxe_nbd b/archiso/archiso_pxe_nbd new file mode 100644 index 0000000..e6b9872 --- /dev/null +++ b/archiso/archiso_pxe_nbd @@ -0,0 +1,6 @@ +omit_kill_nbd_client() { + add_omit_pids $(< /run/archiso/nbd_client.pid) +} + +add_hook shutdown_prekillall omit_kill_nbd_client +add_hook single_prekillall omit_kill_nbd_client diff --git a/archiso/archiso_shutdown b/archiso/archiso_shutdown new file mode 100644 index 0000000..85cce59 --- /dev/null +++ b/archiso/archiso_shutdown @@ -0,0 +1,40 @@ +#!/bin/ash + +# /oldroot depends on things inside /oldroot/run/archiso... +mkdir /oldrun +mount -n --move /oldroot/run /oldrun + +# Unmount all mounts now. +umount $(mount | awk '$3 ~/^\/oldroot/ {print $3}' | sort -r) + +# Remove all dm-snapshot devices. +dmsetup remove_all + +# Remove all loopback devices. +for _lup in $(grep ^/dev/loop /oldrun/archiso/used_block_devices | tac); do + if ! losetup -d ${_lup} 2> /dev/null; then + umount -d ${_lup} + fi +done + +# Unmount the space used to store *.cow. +umount /oldrun/archiso/cowspace + +# Unmount boot device if needed (no copytoram=y used) +if [[ ! -d /oldrun/archiso/copytoram ]]; then + if [[ -d /oldrun/archiso/img_dev ]]; then + umount /oldrun/archiso/img_dev + else + umount /oldrun/archiso/bootmnt + fi + if [[ -f /oldrun/archiso/nbd_client.pid ]]; then + nbd-client -d /dev/nbd0 + fi +fi + +# reboot / poweroff / halt, depending on the argument passed by init +# if something invalid is passed, we halt +case "$1" in + reboot|poweroff|halt) "$1" -f ;; + *) halt -f;; +esac diff --git a/archiso/hooks/archiso b/archiso/hooks/archiso index c973ffc..9445498 100644 --- a/archiso/hooks/archiso +++ b/archiso/hooks/archiso @@ -1,92 +1,100 @@ -# Initialize loopback device logic (we using on-demand mode) -# args: none -_init_loop_dev() { - modprobe loop - loop_dev_count=99 - loop_dev_range=$(cat /sys/block/loop0/range) - loop_dev_minor=$((loop_dev_count*loop_dev_range)) -} - -# Call this function before _make_loop_dev() each time. -# args: none -_next_loop_dev() { - loop_dev_count=$((loop_dev_count+1)) - loop_dev_minor=$((loop_dev_count*loop_dev_range)) -} - -# Setup a loopback device for image passed as argument and echo the path to loopback device used. -# args: /path/to/image_file -_make_loop_dev() { - local img="${1}" - mknod /dev/loop${loop_dev_count} b 7 ${loop_dev_minor} &> /dev/null - losetup /dev/loop${loop_dev_count} "${img}" &> /dev/null - echo /dev/loop${loop_dev_count} -} - -# args: source, mountpoint +# args: source, newroot, mountpoint _mnt_fs() { local img="${1}" - local mnt="${2}" + local newroot="${2}" + local mnt="${3}" local img_fullname="${img##*/}"; local img_name="${img_fullname%%.*}" local dm_snap_name="${dm_snap_prefix}_${img_name}" - local ro_dev ro_dev_size ro_dev_fs_type rw_dev + local ro_dev ro_dev_size rw_dev - mkdir -p "${mnt}" - - _next_loop_dev - ro_dev=$(_make_loop_dev "${img}") + ro_dev=$(losetup --find --show --read-only "${img}") + echo ${ro_dev} >> /run/archiso/used_block_devices ro_dev_size=$(blockdev --getsz ${ro_dev}) - ro_dev_fs_type=$(blkid -o value -s TYPE -p ${ro_dev} 2> /dev/null) - dd of="/cowspace/${img_name}.cow" count=0 seek=${ro_dev_size} &> /dev/null - _next_loop_dev - rw_dev=$(_make_loop_dev "/cowspace/${img_name}.cow") + if [[ "${cow_persistent}" == "P" ]]; then + if [[ -f "/run/archiso/cowspace/${cow_directory}/${img_name}.cow" ]]; then + msg ":: Found '/run/archiso/cowspace/${cow_directory}/${img_name}.cow', using as persistent." + else + msg ":: Creating '/run/archiso/cowspace/${cow_directory}/${img_name}.cow' as persistent." + dd of="/run/archiso/cowspace/${cow_directory}/${img_name}.cow" count=0 seek=${ro_dev_size} &> /dev/null + fi + else + if [[ -f "/run/archiso/cowspace/${cow_directory}/${img_name}.cow" ]]; then + msg ":: Found '/run/archiso/cowspace/${cow_directory}/${img_name}.cow' but non-persistent requested, removing." + rm -f "/run/archiso/cowspace/${cow_directory}/${img_name}.cow" + fi + msg ":: Creating '/run/archiso/cowspace/${cow_directory}/${img_name}.cow' as non-persistent." + dd of="/run/archiso/cowspace/${cow_directory}/${img_name}.cow" count=0 seek=${ro_dev_size} &> /dev/null + fi + + rw_dev=$(losetup --find --show "/run/archiso/cowspace/${cow_directory}/${img_name}.cow") + echo ${rw_dev} >> /run/archiso/used_block_devices - echo "0 ${ro_dev_size} snapshot ${ro_dev} ${rw_dev} N 8" | dmsetup create ${dm_snap_name} + echo "0 ${ro_dev_size} snapshot ${ro_dev} ${rw_dev} ${cow_persistent} 8" | dmsetup create ${dm_snap_name} - msg ":: Mounting '/dev/mapper/${dm_snap_name}' (${ro_dev_fs_type}) to '${mnt}'" - if ! mount -t "${ro_dev_fs_type}" "/dev/mapper/${dm_snap_name}" "${mnt}" ; then - echo "ERROR: while mounting '/dev/mapper/${dm_snap_name}' to '${mnt}'" - launch_interactive_shell - fi + _mnt_dev "/dev/mapper/${dm_snap_name}" "${newroot}${mnt}" "-w" + echo $(readlink -f /dev/mapper/${dm_snap_name}) >> /run/archiso/used_block_devices + echo "/dev/mapper/${dm_snap_name} ${mnt} auto defaults 0 0" >> ${newroot}/etc/fstab } # args: /path/to/image_file, mountpoint _mnt_sfs() { local img="${1}" local mnt="${2}" - local img_fullname="${img##*/}"; - - mkdir -p "${mnt}" + local img_fullname="${img##*/}" + local sfs_dev if [[ "${copytoram}" == "y" ]]; then msg -n ":: Copying squashfs image to RAM..." - if ! cp "${img}" "/copytoram/${img_fullname}" ; then - echo "ERROR: while copy '${img}' to '/copytoram/${img_fullname}'" + if ! cp "${img}" "/run/archiso/copytoram/${img_fullname}" ; then + echo "ERROR: while copy '${img}' to '/run/archiso/copytoram/${img_fullname}'" launch_interactive_shell fi - img="/copytoram/${img_fullname}" + img="/run/archiso/copytoram/${img_fullname}" msg "done." fi - _next_loop_dev - msg ":: Mounting '${img}' (SquashFS) to '${mnt}'" - if ! mount -r -t squashfs $(_make_loop_dev "${img}") "${mnt}" &> /dev/null ; then - echo "ERROR: while mounting '${img}' to '${mnt}'" + sfs_dev=$(losetup --find --show --read-only "${img}") + echo ${sfs_dev} >> /run/archiso/used_block_devices + _mnt_dev "${sfs_dev}" "${mnt}" "-r" +} + +# args: device, mountpoint, flags +_mnt_dev() { + local dev="${1}" + local mnt="${2}" + local flg="${3}" + + mkdir -p "${mnt}" + + msg ":: Mounting '${dev}' to '${mnt}'" + + while ! poll_device "${dev}" 30; do + echo "ERROR: '${dev}' device did not show up after 30 seconds..." + echo " Falling back to interactive prompt" + echo " You can try to fix the problem manually, log out when you are finished" + launch_interactive_shell + done + + if mount "${flg}" "${dev}" "${mnt}"; then + msg ":: Device '${dev}' mounted successfully." + else + echo "ERROR; Failed to mount '${dev}'" + echo " Falling back to interactive prompt" + echo " You can try to fix the problem manually, log out when you are finished" launch_interactive_shell fi } _verify_checksum() { local _status - cd "/bootmnt/${archisobasedir}" - md5sum -c checksum.md5 > /checksum.log 2>&1 + cd "/run/archiso/bootmnt/${archisobasedir}" + md5sum -c checksum.${arch}.md5 > /tmp/checksum.${arch}.log 2>&1 _status=$? cd "${OLDPWD}" return ${_status} } - run_hook() { [[ -z "${arch}" ]] && arch="$(uname -m)" [[ -z "${cowspace_size}" ]] && cowspace_size="75%" @@ -94,11 +102,24 @@ run_hook() { [[ -z "${archisobasedir}" ]] && archisobasedir="arch" [[ -z "${dm_snap_prefix}" ]] && dm_snap_prefix="arch" [[ -z "${archisodevice}" ]] && archisodevice="/dev/disk/by-label/${archisolabel}" + if [[ -z "${aitab}" ]]; then - aitab="/bootmnt/${archisobasedir}/aitab" + aitab="/run/archiso/bootmnt/${archisobasedir}/aitab" else - aitab="/bootmnt/${aitab}" + aitab="/run/archiso/bootmnt/${archisobasedir}/${aitab}" fi + + if [[ -n "${cow_label}" ]]; then + cow_device="/dev/disk/by-label/${cow_label}" + [[ -z "${cow_persistent}" ]] && cow_persistent="P" + elif [[ -n "${cow_device}" ]]; then + [[ -z "${cow_persistent}" ]] && cow_persistent="P" + else + cow_persistent="N" + fi + + [[ -z "${cow_directory}" ]] && cow_directory="persistent_${archisolabel}/${arch}" + # set mount handler for archiso mount_handler="archiso_mount_handler" } @@ -108,90 +129,69 @@ run_hook() { # args: /path/to/newroot archiso_mount_handler() { local newroot="${1}" - local fstype fserror - - _init_loop_dev - - msg ":: Waiting for boot device..." - while ! poll_device "${archisodevice}" 30; do - echo "ERROR: boot device didn't show up after 30 seconds..." - echo " Falling back to interactive prompt" - echo " You can try to fix the problem manually, log out when you are finished" - launch_interactive_shell - done - fstype=$(blkid -o value -s TYPE -p "${archisodevice}" 2> /dev/null) - if [[ -n "${fstype}" ]]; then - if mount -r -t "${fstype}" "${archisodevice}" /bootmnt; then - if [[ -f "${aitab}" ]]; then - msg ":: Mounted archiso volume successfully." - fserror=0 - else - echo "ERROR: Mounting was successful, but the '${aitab}' file does not exist." - fserror=1 - fi - else - echo "ERROR; Failed to mount '${archisodevice}' (FS is ${fstype})" - fserror=1 + if ! mountpoint -q "/run/archiso/bootmnt"; then + _mnt_dev "${archisodevice}" "/run/archiso/bootmnt" "-r" + if [[ "${copytoram}" != "y" ]]; then + echo $(readlink -f ${archisodevice}) >> /run/archiso/used_block_devices fi - else - echo "ERROR: '${archisodevice}' found, but the filesystem type is unknown." - fserror=1 fi - if [[ ${fserror} -eq 1 ]]; then + + if [[ ! -f "${aitab}" ]]; then + echo "ERROR: '${aitab}' file does not exist." echo " Falling back to interactive prompt" echo " You can try to fix the problem manually, log out when you are finished" launch_interactive_shell fi if [[ "${checksum}" == "y" ]]; then - if [[ -f "/bootmnt/${archisobasedir}/checksum.md5" ]]; then + if [[ -f "/run/archiso/bootmnt/${archisobasedir}/checksum.${arch}.md5" ]]; then msg -n ":: Self-test requested, please wait..." if _verify_checksum; then msg "done. Checksum is OK, continue booting." else echo "ERROR: one or more files are corrupted" - echo "see /checksum.log for details" + echo "see /tmp/checksum.${arch}.log for details" launch_interactive_shell fi else - echo "ERROR: checksum=y option specified but checksum.md5 not found" + echo "ERROR: checksum=y option specified but checksum.${arch}.md5 not found" launch_interactive_shell fi fi if [[ "${copytoram}" == "y" ]]; then - msg -n ":: Mounting /copytoram (tmpfs) filesystem, size=${copytoram_size}..." - mount -t tmpfs -o "size=${copytoram_size}",mode=0755 copytoram /copytoram - msg "done." + msg ":: Mounting /run/archiso/copytoram (tmpfs) filesystem, size=${copytoram_size}" + mkdir -p /run/archiso/copytoram + mount -t tmpfs -o "size=${copytoram_size}",mode=0755 copytoram /run/archiso/copytoram fi - msg -n ":: Mounting /cowspace (tmpfs) filesystem, size=${cowspace_size}..." - mount -t tmpfs -o "size=${cowspace_size}",mode=0755 cowspace /cowspace - msg "done." + if [[ -n "${cow_device}" ]]; then + _mnt_dev "${cow_device}" "/run/archiso/cowspace" "-r" + echo $(readlink -f ${cow_device}) >> /run/archiso/used_block_devices + mount -o remount,rw "/run/archiso/cowspace" + else + msg ":: Mounting /run/archiso/cowspace (tmpfs) filesystem, size=${cowspace_size}..." + mkdir -p /run/archiso/cowspace + mount -t tmpfs -o "size=${cowspace_size}",mode=0755 cowspace /run/archiso/cowspace + fi + mkdir -p "/run/archiso/cowspace/${cow_directory}" local aitab_img aitab_mnt aitab_arch aitab_sfs_comp aitab_fs_type aitab_fs_size while read aitab_img aitab_mnt aitab_arch aitab_sfs_comp aitab_fs_type aitab_fs_size; do [[ "${aitab_img#\#}" != "${aitab_img}" ]] && continue [[ "${aitab_arch}" != "any" && "${aitab_arch}" != "${arch}" ]] && continue if [[ "${aitab_fs_type}" != "none" ]]; then - if [[ "${aitab_sfs_comp}" != "none" ]]; then - _mnt_sfs "/bootmnt/${archisobasedir}/${aitab_arch}/${aitab_img}.fs.sfs" "/sfs/${aitab_img}" - _mnt_fs "/sfs/${aitab_img}/${aitab_img}.fs" "${newroot}${aitab_mnt}" - else - _mnt_fs "/bootmnt/${archisobasedir}/${aitab_arch}/${aitab_img}.fs" "${newroot}${aitab_mnt}" - fi + _mnt_sfs "/run/archiso/bootmnt/${archisobasedir}/${aitab_arch}/${aitab_img}.fs.sfs" "/run/archiso/sfs/${aitab_img}" + _mnt_fs "/run/archiso/sfs/${aitab_img}/${aitab_img}.fs" "${newroot}" "${aitab_mnt}" else - _mnt_sfs "/bootmnt/${archisobasedir}/${aitab_arch}/${aitab_img}.sfs" "${newroot}${aitab_mnt}" + _mnt_sfs "/run/archiso/bootmnt/${archisobasedir}/${aitab_arch}/${aitab_img}.sfs" "${newroot}${aitab_mnt}" fi done < "${aitab}" if [[ "${copytoram}" == "y" ]]; then - umount /bootmnt - else - mkdir "${newroot}/bootmnt" - mount --bind /bootmnt "${newroot}/bootmnt" + umount /run/archiso/bootmnt fi } diff --git a/archiso/hooks/archiso_loop_mnt b/archiso/hooks/archiso_loop_mnt index 13f8743..a02cfac 100644 --- a/archiso/hooks/archiso_loop_mnt +++ b/archiso/hooks/archiso_loop_mnt @@ -1,7 +1,8 @@ # vim: set ft=sh: run_hook () { - if [ -n "${img_dev}" ] && [ -n "${img_loop}" ]; then + [[ -n "${img_label}" ]] && img_dev="/dev/disk/by-label/${img_label}" + if [[ -n "${img_dev}" && -n "${img_loop}" ]]; then mount_handler="archiso_loop_mount_handler" fi } @@ -9,29 +10,23 @@ run_hook () { archiso_loop_mount_handler () { newroot="${1}" - msg ":: Waiting for boot device..." - while ! poll_device ${img_dev} 30; do - echo "ERROR: boot device didn't show up after 30 seconds..." - echo " Falling back to interactive prompt" - echo " You can try to fix the problem manually, log out when you are finished" - launch_interactive_shell - done + local _dev_loop + + msg ":: Setup a loop device from ${img_loop} located at device ${img_dev}" + _mnt_dev "${img_dev}" "/run/archiso/img_dev" "-r" + if [[ "${copytoram}" != "y" ]]; then + echo $(readlink -f ${img_dev}) >> /run/archiso/used_block_devices + fi - msg "::: Setup a loop device from ${img_loop} located at device ${img_dev}" - FSTYPE=$(blkid -o value -s TYPE -p ${img_dev} 2> /dev/null) - if [ -n "${FSTYPE}" ]; then - if mount -r -t "${FSTYPE}" ${img_dev} /img_dev > /dev/null 2>&1; then - _dev_loop=$(losetup -f) - losetup ${_dev_loop} /img_dev/${img_loop} - fi + if ! _dev_loop=$(losetup --find --show --read-only "/run/archiso/img_dev/${img_loop}"); then + echo "ERROR: Setting loopback device for file '/run/archiso/img_dev/${img_loop}'" + launch_interactive_shell fi archiso_mount_handler ${newroot} - if [ "${copytoram}" = "y" ]; then - msg "::: Deataching loop device ${_dev_loop}" + if [[ "${copytoram}" == "y" ]]; then losetup -d ${_dev_loop} - msg "::: Unmounting ${img_dev}" - umount ${img_dev} + umount /run/archiso/img_dev fi } diff --git a/archiso/hooks/archiso_pxe_common b/archiso/hooks/archiso_pxe_common new file mode 100644 index 0000000..febb503 --- /dev/null +++ b/archiso/hooks/archiso_pxe_common @@ -0,0 +1,42 @@ +# vim: set ft=sh: + +run_hook () { + local i net_mac bootif_mac bootif_dev + # These variables will be parsed from /tmp/net-*.conf generated by ipconfig + local DEVICE + local IPV4ADDR IPV4BROADCAST IPV4NETMASK IPV4GATEWAY IPV4DNS0 IPV4DNS1 + local HOSTNAME DNSDOMAIN NISDOMAIN ROOTSERVER ROOTPATH + local filename + # /tmp/net-*.conf + + if [[ -n "${ip}" ]]; then + if [[ -n "${BOOTIF}" ]]; then + bootif_mac=${BOOTIF#01-} + bootif_mac=${bootif_mac//-/:} + for i in /sys/class/net/*/address; do + read net_mac < ${i} + if [[ "${bootif_mac}" == "${net_mac}" ]]; then + bootif_dev=${i#/sys/class/net/} + bootif_dev=${bootif_dev%/address} + break + fi + done + ip="${ip}::${bootif_dev}" + fi + + # setup network and save some values + ipconfig "ip=${ip}" + + . /tmp/net-*.conf + + pxeserver=${ROOTSERVER} + + # setup DNS resolver + if [[ "${IPV4DNS0}" != "0.0.0.0" ]]; then + echo "nameserver ${IPV4DNS0}" > /etc/resolv.conf + fi + if [[ "${IPV4DNS1}" != "0.0.0.0" ]]; then + echo "nameserver ${IPV4DNS1}" >> /etc/resolv.conf + fi + fi +} diff --git a/archiso/hooks/archiso_pxe_http b/archiso/hooks/archiso_pxe_http new file mode 100644 index 0000000..ae56210 --- /dev/null +++ b/archiso/hooks/archiso_pxe_http @@ -0,0 +1,61 @@ +# vim: set ft=sh: + +run_hook() { + if [[ -n "${ip}" && -n "${archiso_http_srv}" ]]; then + + archiso_http_srv=$(eval echo ${archiso_http_srv}) + [[ -z "${archiso_http_spc}" ]] && archiso_http_spc="75%" + + mount_handler="archiso_pxe_http_mount_handler" + fi +} + +# Fetch a file with CURL +# +# $1 URL +# $2 Destination directory inside httpspace/${archisobasedir} +_curl_get() { + local _url="${1}" + local _dst="${2}" + + msg ":: Downloading '${_url}'" + if ! curl -f -o "/run/archiso/httpspace/${archisobasedir}${_dst}/${_url##*/}" --create-dirs "${_url}"; then + echo "ERROR: Downloading '${_url}'" + echo " Falling back to interactive prompt" + echo " You can try to fix the problem manually, log out when you are finished" + launch_interactive_shell + fi +} + +archiso_pxe_http_mount_handler () { + newroot="${1}" + + msg ":: Mounting /run/archiso/httpspace (tmpfs) filesystem, size='${archiso_http_spc}'" + mkdir -p "/run/archiso/httpspace" + mount -t tmpfs -o size="${archiso_http_spc}",mode=0755 httpspace "/run/archiso/httpspace" + + local _aitab_url="${archiso_http_srv}${aitab#/run/archiso/bootmnt/}" + local _aitab_file="/run/archiso/httpspace/${aitab#/run/archiso/bootmnt/}" + + _curl_get "${_aitab_url}" "/" + + local aitab_img aitab_mnt aitab_arch aitab_sfs_comp aitab_fs_type aitab_fs_size + while read aitab_img aitab_mnt aitab_arch aitab_sfs_comp aitab_fs_type aitab_fs_size; do + [[ "${aitab_img#\#}" != "${aitab_img}" ]] && continue + [[ "${aitab_arch}" != "any" && "${aitab_arch}" != "${arch}" ]] && continue + if [[ "${aitab_fs_type}" != "none" ]]; then + _curl_get "${archiso_http_srv}${archisobasedir}/${aitab_arch}/${aitab_img}.fs.sfs" "/${aitab_arch}" + else + _curl_get "${archiso_http_srv}${archisobasedir}/${aitab_arch}/${aitab_img}.sfs" "/${aitab_arch}" + fi + done < "${_aitab_file}" + + if [[ "${checksum}" == "y" ]]; then + _curl_get "${archiso_http_srv}${archisobasedir}/checksum.${arch}.md5" "/" + fi + + mkdir -p "/run/archiso/bootmnt" + mount -o bind /run/archiso/httpspace /run/archiso/bootmnt + + archiso_mount_handler ${newroot} +} diff --git a/archiso/hooks/archiso_pxe_nbd b/archiso/hooks/archiso_pxe_nbd index 588e033..6147d06 100644 --- a/archiso/hooks/archiso_pxe_nbd +++ b/archiso/hooks/archiso_pxe_nbd @@ -1,60 +1,9 @@ # vim: set ft=sh: -run_hook () { - local line i address netmask gateway dns0 dns1 rootserver rootpath filename - : > /ip_opts - - if [ -n "${ip}" ]; then - if [ -n "${BOOTIF}" ]; then - bootif_mac=${BOOTIF#01-} - bootif_mac=${bootif_mac//-/:} - bootif_dev=$(grep -l $bootif_mac /sys/class/net/*/address) - bootif_dev=${bootif_dev#/sys/class/net/} - bootif_dev=${bootif_dev%/address} - ip="$ip::$bootif_dev" - fi - - # setup network and save some values - ipconfig "ip=${ip}" | while read line; do - # echo ":: ${line}" - if [ "${line#"IP-Config:"}" != "${line}" ]; then - continue - fi - line="$(echo ${line} | sed -e 's/ :/:/g;s/: /=/g')" - for i in ${line}; do - case "${i}" in - address=*) - echo "${i}" >> /ip_opts - ;; - netmask=*) - echo "${i}" >> /ip_opts - ;; - gateway=*) - echo "${i}" >> /ip_opts - ;; - dns0=*) - echo "${i}" >> /ip_opts - ;; - dns1=*) - echo "${i}" >> /ip_opts - ;; - rootserver=*) - echo "${i}" >> /ip_opts - ;; - rootpath=*) - echo "${i}" >> /ip_opts - ;; - esac - done - done - - . /ip_opts - - echo "IP-Config: ${address}/${netmask}" - echo "IP-Config: gw: ${gateway} dns0: ${dns0} dns1: ${dns1}" - - nbdserver=${rootserver} +run_hook() { + if [[ -n "${ip}" && -n "${archiso_nbd_srv}" ]]; then + archiso_nbd_srv=$(eval echo ${archiso_nbd_srv}) [[ -z "${archiso_nbd_name}" ]] && archiso_nbd_name="archiso" mount_handler="archiso_pxe_nbd_mount_handler" @@ -74,21 +23,23 @@ archiso_pxe_nbd_mount_handler () { launch_interactive_shell done - msg "::: Setup NBD from ${nbdserver} at /dev/nbd0" - if [ "${copytoram}" = "y" ]; then - nbd-client ${nbdserver} -N ${archiso_nbd_name} /dev/nbd0 + msg ":: Setup NBD from ${archiso_nbd_srv} at /dev/nbd0" + if [[ "${copytoram}" = "y" ]]; then + nbd-client ${archiso_nbd_srv} -N ${archiso_nbd_name} /dev/nbd0 else - nbd-client ${nbdserver} -N ${archiso_nbd_name} /dev/nbd0 -persist + nbd-client ${archiso_nbd_srv} -N ${archiso_nbd_name} /dev/nbd0 -persist fi archisodevice=/dev/nbd0 archiso_mount_handler ${newroot} - if [ "${copytoram}" = "y" ]; then - msg "::: Disconnect NBD from ${nbdserver} at /dev/nbd0" + if [[ "${copytoram}" = "y" ]]; then + msg ":: Disconnect NBD from ${archiso_nbd_srv} at /dev/nbd0" nbd-client -d /dev/nbd0 else - pidof nbd-client > /run/nbd_client.pid + mkdir -p /run/archiso + pidof nbd-client > /run/archiso/nbd_client.pid + cp /archiso_pxe_nbd ${newroot}/etc/rc.d/functions.d/ fi } diff --git a/archiso/hooks/archiso_pxe_nfs b/archiso/hooks/archiso_pxe_nfs new file mode 100644 index 0000000..a053672 --- /dev/null +++ b/archiso/hooks/archiso_pxe_nfs @@ -0,0 +1,26 @@ +# vim: set ft=sh: + +run_hook() { + if [[ -n "${ip}" && -n "${archiso_nfs_srv}" ]]; then + + archiso_nfs_srv=$(eval echo ${archiso_nfs_srv}) + [[ -n "${archiso_nfs_opt}" ]] && archiso_nfs_opt="-o ${archiso_nfs_opt}" + + mount_handler="archiso_nfs_mount_handler" + fi +} + +archiso_nfs_mount_handler() { + newroot="${1}" + mkdir -p "/run/archiso/bootmnt" + msg ":: Mounting '${archiso_nfs_srv}'" + # Do not put "${archiso_nfs_opt}" nfsmount fails! + if ! nfsmount ${archiso_nfs_opt} "${archiso_nfs_srv}" "/run/archiso/bootmnt"; then + echo "ERROR: Mounting '${archiso_nfs_srv}'" + echo " Falling back to interactive prompt" + echo " You can try to fix the problem manually, log out when you are finished" + launch_interactive_shell + fi + + archiso_mount_handler ${newroot} +} diff --git a/archiso/hooks/archiso_shutdown b/archiso/hooks/archiso_shutdown new file mode 100644 index 0000000..24e4103 --- /dev/null +++ b/archiso/hooks/archiso_shutdown @@ -0,0 +1,23 @@ +run_hook () +{ + msg -n ":: Creating shutdown ramfs..." + + for _dir in bin lib sbin usr/bin usr/lib usr/sbin; do + mkdir -p /run/initramfs/${_dir} + done + cp /bin/busybox /run/initramfs/bin/ + cp /lib/ld-* /run/initramfs/lib/ + cp /lib/lib* /run/initramfs/lib/ + cp /usr/lib/lib* /run/initramfs/usr/lib/ + cp /bin/mount /run/initramfs/bin/ + cp /sbin/dmsetup /run/initramfs/sbin/ + cp /sbin/losetup /run/initramfs/sbin/ + if [[ -x /bin/nbd-client ]]; then + cp /bin/nbd-client /run/initramfs/bin/ + fi + + chroot /run/initramfs /bin/busybox --install + cp /shutdown /run/initramfs/ + + msg "done." +} diff --git a/archiso/install/archiso b/archiso/install/archiso index 514c011..c36c001 100644 --- a/archiso/install/archiso +++ b/archiso/install/archiso @@ -1,30 +1,19 @@ -build () -{ - MODULES="cdrom ide-cd_mod ide-core ide-generic loop dm-mod dm-snapshot squashfs isofs $(all_modules '/kernel/fs' | grep -v "nls")" - MODULES="${MODULES} $(checked_modules "/usb/host" | grep -ve "_cs" -e "sl811_hcd" -e "isp116x_hcd")" - MODULES="${MODULES} usb_storage sd_mod sr_mod" - MODULES="${MODULES} virtio_pci virtio_blk" - MODULES=$(echo ${MODULES}) #trim whitespace +#!/bin/bash - BINARIES="" - FILES="" - - add_dir /cowspace - add_dir /copytoram - add_dir /bootmnt - - add_binary /lib/udev/cdrom_id - add_binary /sbin/blockdev - add_binary /sbin/lvm - add_binary /sbin/dmsetup +build() { + MODULES="cdrom loop dm-snapshot" + SCRIPT="archiso" - add_file /lib/udev/rules.d/60-cdrom_id.rules - add_file /lib/udev/rules.d/10-dm.rules - add_file /lib/udev/rules.d/13-dm-disk.rules - add_file /lib/udev/rules.d/95-dm-notify.rules - add_file /lib/udev/rules.d/11-dm-lvm.rules + add_binary /usr/lib/udev/cdrom_id + add_binary blockdev + add_binary dmsetup + add_binary losetup + add_binary mountpoint - SCRIPT="archiso" + add_file /usr/lib/udev/rules.d/60-cdrom_id.rules + add_file /usr/lib/udev/rules.d/10-dm.rules + add_file /usr/lib/udev/rules.d/95-dm-notify.rules + add_file /usr/lib/initcpio/udev/11-dm-initramfs.rules /usr/lib/udev/rules.d/11-dm-initramfs.rules } -# vim:ft=sh:ts=4:sw=4:et: +# vim: set ft=sh ts=4 sw=4 et: diff --git a/archiso/install/archiso_kms b/archiso/install/archiso_kms new file mode 100644 index 0000000..6566049 --- /dev/null +++ b/archiso/install/archiso_kms @@ -0,0 +1,14 @@ +#!/bin/bash + +build() { + MODULES="radeon nouveau i915 via-agp sis-agp intel-agp" + if [[ $(uname -m) == i686 ]]; then + MODULES+=" amd64-agp ati-agp sworks-agp ali-agp amd-k7-agp nvidia-agp efficeon-agp" + fi +} + +help() { + cat << HELPEOF +Adds all common KMS drivers to the initramfs image. +HELPEOF +} diff --git a/archiso/install/archiso_loop_mnt b/archiso/install/archiso_loop_mnt index 2c8d6f2..4141043 100644 --- a/archiso/install/archiso_loop_mnt +++ b/archiso/install/archiso_loop_mnt @@ -1,18 +1,13 @@ -# vim: set ft=sh: +#!/bin/bash -build () -{ - MODULES="" - - BINARIES="" - FILES="" - add_dir /img_dev +build() { SCRIPT="archiso_loop_mnt" } -help () -{ +help() { cat< $BUILDROOT/etc/nsswitch.conf +} + +help() { +cat<" echo " general options:" echo " -p PACKAGE(S) Package(s) to install, can be used multiple times" - echo " -C Config file for pacman. Default ${pacman_conf}" + echo " -r Run inside root-image" + echo " -C Config file for pacman." + echo " Default: '${pacman_conf}'" echo " -L