For the benefit of the community I want to give an update
on how I solved my problem:

I only needed a one-line patch to /lib/svc/method/fs-root inside the 
boot_archive:

--- fs-root     Wed Oct  7 13:44:05 2015
+++ /lib/svc/method/fs-root     Tue Oct  6 20:53:08 2015
@@ -66,6 +66,7 @@
 /sbin/mount -F ufs -o remount,rw,nologging /devices/ramdisk:a /
 /usr/sbin/lofiadm -X -a /usr.lgz
 /sbin/mount -F ufs -o ro /devices/pseudo/lofi\@0:1 /usr
+[ -e /system/boot/overlay.tgz ] && tar xvzf /system/boot/overlay.tgz -C /

 #
 # Update kernel driver.conf cache with any additional driver.conf

To do that, I could have used smartos-isomerge, but I found another way 
that is much easier. The boot_archive is just an UFS image that can
be mounted r/w. So place the boot_archive on a writable filesystem and:

mount /zones/smartos/platform/i86pc/amd64/boot_archive /mnt
sed -i '' -e '/mount -F ufs -o ro/{p;s:.*:[ -e /system/boot/overlay.tgz ] \&\& 
tar xvzf /system/boot/overlay.tgz -C /:;}' /mnt/lib/svc/method/fs-root
umount /mnt

That is all. What exactly to put into the overlay.tgz is left as an exercise to 
the reader,
but for example here is what I did:

mkdir -p /zones/smartos/overlay/var
cp -a /var/ssh /zones/smartos/overlay/var/.
cp -a /usbkey /zones/smartos/overlay/.
mkdir -p /zones/smartos/overlay/lib/svc/method
cp -a /lib/svc/method/fs-joyent /zones/smartos/overlay/lib/svc/method/.
sed -i '' -e 's:/bin/bootparams | grep "^noimport=true" 
>/dev/null:/bin/bootparams | grep "^noimport=true" >/dev/null || 
/bin/bootparams | grep "^disklessnetwork=true" >/dev/null:' 
/zones/smartos/overlay/lib/svc/method/fs-joyent
cat <<EOF >> /zones/smartos/overlay.sh
#!/bin/sh
# build boot overlay tar file
(cd /zones/smartos/overlay ; tar cvzf ../overlay.tgz *)
EOF
chmod 755 /zones/smartos/overlay.sh
/zones/smartos/overlay.sh

Now you can edit the GRUB menu to load the overlay.tgz file with the kernel:

sed -i '' -e 's:boot_archive:boot_archive type=rootfs name=ramdisk:' 
/zones/boot/grub/menu.lst
sed -i '‘ -e '/boot_archive/{p;s:.*:   module /overlay.tgz type=file 
name=overlay.tgz:;}' /zones/boot/grub/menu.lst

Worked well for me, YMMV. This does not work to override files on /usr,
but I had no need for that. If needed, that can be done with LOFS(7FS).

BTW, the above, combined with the bootparam „disklessnetwork=true“, allows
for running SmartOS diskless without importing pools or touching disks,
but with full networking and sshd enabled, which is very useful for 
maintenance or installation on a remote system via ssh.
(This is why I made the whole effort in the first place).

All of this was done with smartos_20151001T070028Z.

My final GRUB entry looks like this:

title SmartOS disklessnetwork
   bootfs zones/smartos
   kernel$ /platform/i86pc/kernel/amd64/unix -B 
console=${os_console},${os_console}-mode="115200,8,n,1,-",root_shadow='$5$2HOHRnK3$NvLlm.1KQBbB0WjoP7xcIwGnllhzp2HnT.mDO7DpxYA',smartos=true,disklessnetwork=true
   module /platform/i86pc/amd64/boot_archive type=rootfs name=ramdisk
   module /overlay.tgz type=file name=overlay.tgz


/Dirk


> Am 06.10.2015 um 11:07 schrieb Dirk Steinberg <[email protected]>:
> 
> Thanks for the pointer to smartos-isomerge. That might do the job, although
> I’d still prefer the dynamic, boot-time „patching“ of the GRUB/bootfs method.
> Maybe I’ll just make a minimal change to the ramdisk image to copy over the
> stuff found in /system/boot. The root (/) ramdisk is r/w anyway, and for 
> modifying /usr I could use bind mounts (mount -F lofs), i.e. to change the
> manpage for at(1):
> 
> mount -F lofs /system/boot/usr/share/man/man1/at.1 /usr/share/man/man1/at.1
> 
> /Dirk
> 
>> Am 06.10.2015 um 09:26 schrieb Gérczei Tamás <[email protected] 
>> <mailto:[email protected]>>:
>> 
>> Hi Dirk,
>> 
>> Since /system/boot is a preferred path only for kernel modules and their 
>> configurations, You'll likely have to resort to using smartos-isomerge. It's 
>> a tiny node application that takes a platform ISO, a JSON configuration file 
>> plus the files you want to replace and will spit out a modified image with 
>> those. I ended up extracting the kernel and the boot archive from the 
>> resulting image and booting them via TFTP.
>> 
>> Nahum told me about this a few weeks ago. It works indeed.
>> 
>> T.
>> 
>> On 6 October 2015 8:46:53 am "Dirk Steinberg" <[email protected] 
>> <mailto:[email protected]>> wrote:
>> 
>>> Hi Nahum (and others),
>>> 
>>> with great interest I read your blog post about 
>>> „Overriding Driver Config Files on SmartOS“
>>> 
>>> http://blog.shalman.org/overriding-driver-config-files-on-smartos/ 
>>> <http://blog.shalman.org/overriding-driver-config-files-on-smartos/>
>>> 
>>> I want to do almost the same, but overriding other files on the 
>>> ramdisk, for example the installer script.
>>> 
>>> I was able to reproduce your example of modifying kernel/drv/sd.conf,
>>> in my case I set the blocksize to 4096 and it did work.
>>> 
>>> Changing the installer script /smartdc/lib/smartos_prompt_config.sh
>>> did not work — in fact, even the modified /kernel/drv/sd.conf that
>>> clearly took effect when configuring the kernel had been reverted
>>> back to the original under the path /kernel/drv/sd.conf. After looking
>>> around I could find the modified versions of my files under
>>> 
>>> /system/boot/kernel/drv/sd.conf           and
>>> /system/boot/smartdc/lib/smartos_prompt_config.sh
>>> 
>>> However, that does not help me much, as the installer is launched
>>> from /smartdc/lib/smartos_prompt_config.sh and not
>>> from /system/boot/smartdc/lib/smartos_prompt_config.sh.
>>> The installer script is just an example here, I might want to 
>>> override other files in the ramdisk as well.
>>> 
>>> At the very least, could I place a „hook“ (script) somewhere under
>>> /system/boot that would get called sometime during the bootup
>>> process that would allow me to do whatever changes I want?
>>> 
>>> Background of this is that I want to modify the ramdisk such that 
>>> it brings up DHCP networking and sshd without importing
>>> the zones pool. I also want to inject an ssh key into the ramdisk
>>> image so that after booting and network auto-config I could
>>> login remotely via ssh and run the installer from the ssh session.
>>> 
>>> Any hints on how to do this?
>>> 
>>> BTW, the ssh service seems to have tons of dependencies,
>>> way too many to be realistic. Normally, if networking is up,
>>> you should just be able to run sshd. What is the minimalistic way 
>>> to get the ssh service running when in the ramdisk environment
>>> without a „zones“ pool?
>>> 
>>> I still hope to be able to use the GRUB mechanism the override
>>> ramdisk files. However, if this should not be possible, what is
>>> the easiest way to change the actual ramdisk image?
>>> 
>>> I realize that I could set up a full build system and rebuild the entire 
>>> SmartOS including the ramdisk, but this appears to be too much effort.
>>> Is there a way to unpack the ramdisk, make some changes, and repack
>>> the thing?
>>> 
>>> I am sending this to the list as this might be interesting for others as 
>>> well.
>>> 
>>> /Dirk
>>> 
> 
> smartos-discuss | Archives 
> <https://www.listbox.com/member/archive/184463/=now>  
> <https://www.listbox.com/member/archive/rss/184463/24390006-796fb66c> | 
> Modify <https://www.listbox.com/member/?&;> Your Subscription  
> <http://www.listbox.com/>



-------------------------------------------
smartos-discuss
Archives: https://www.listbox.com/member/archive/184463/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184463/25769125-55cfbc00
Modify Your Subscription: 
https://www.listbox.com/member/?member_id=25769125&id_secret=25769125-7688e9fb
Powered by Listbox: http://www.listbox.com

Reply via email to