From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <703597eca26b570200b4a4a522d63a1c@plan9.bell-labs.com> To: 9fans@cse.psu.edu From: "Russ Cox" MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: [9fans] name space and fossil tricks Date: Fri, 7 Feb 2003 14:54:48 -0500 Topicbox-Message-UUID: 534f7e1a-eacb-11e9-9e20-41e7f4b1d025 [I wrote this back in November, but was waiting for Fossil to be released for context before mailing it, and then I forgot. -rsc] Rob wrote a script like the one below when we were working on the 4th edition distribution. To build the distribution binaries, we could make a copy of sources (say, in /n/dist) and then run g% namespace /n/dist which makes the name space in that window almost identical to the name space you'd get booting from /n/dist. If you then run g% window -m rio you've got a full terminal! This is much easier than using a different machine. In fact, you can, for example, boot over the network and then do g% 9fs kfs g% namespace /n/kfs kfs=; Then even if the network connection dies you can keep doing useful things in the kfs name space window. This is a neat trick, but I didn't realize how neat it was until just now. I've been testing the new file server (called fossil) on my laptop (hey, when you've only got one machine, ...). I can boot from fossil to get my up-to-date system, or if I really screw things up I can boot from kfs to get an out-of-date system I can use to fix things. I made a change to the on-disk layout of the new file system and needed to reformat the disk. Usually this would require the following: - build a new kernel containing the new fossil - copy kernel to 9fat - run a dump of the file system to Venti - reboot using kfs kernel - reformat the disk - reboot using new kernel But instead I did: - run a dump of fossil to Venti, remember score - switch to kfs and kill fossil g% namespace /n/kfs kfs=; slay fossil | rc - realize I forgot to copy the format binary to kfs - realize I forgot to build a new kernel - mount dump kfs=; vacfs <{echo vac:asdfadsfasdadsf} - reformat using binary in dump kfs=; cd /n/vac/sys/src/cmd/fossil kfs=; 8.format /dev/sdC0/fossil vac:asdfadsfadsfadsf - start fossil and switch back kfs=; 8.fossil ... kfs=; mount /srv/fossil /n/fossil kfs=; namespace /n/fossil - rebuild the kernel fossil=; cd /sys/src/cmd/fossil fossil=; mk install fossil=; cd /sys/src/9/pc fossil=; mk 'CONF=pcfl' 9pcfl.gz fossil=; 9fat: fossil=; cp 9pcfl.gz /n/9fat - reboot So despite screwing up I still only needed to reboot once (rather than the four reboots it would have taken without name space but with the same screwup). Anyhow, the point is: how many systems do you know that stay up after you've removed their root file systems out from under them? g% cat /usr/rsc/bin/rc/namespace #!/bin/rc rfork en # adapted from /lib/namespace if(! ~ $#* 1 || ! test -x $1/$cputype/bin/bind) { echo 'usage: namespace /n/foo' >[1=2] echo ' /n/foo/$cputype/bin/bind must exist' >[1=2] exit usage } root = $1 echo setting up $root fn bind{ /$cputype/bin/bind $* } # root bind $root / bind -b '#/' / # kernel devices bind '#c' /dev bind '#d' /fd bind -c '#e' /env bind '#p' /proc bind -c '#s' /srv bind -a '#S' /dev # standard bin bind /$cputype/bin /bin bind -a /rc/bin /bin ramfs cd prompt=(`{basename $root}^'=; ' ' ') fn cd rc -i g%