Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Sep 2014 00:44:11 -0700
From:      Mehmet Erol Sanliturk <m.e.sanliturk@gmail.com>
To:        Matthias Apitz <guru@unixarea.de>, Mehmet Erol Sanliturk <m.e.sanliturk@gmail.com>,  FreeBSD Questions Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: Using the ISO releases on USB sticks.
Message-ID:  <CAOgwaMtUKNiFdtj%2BNKH8BRGOMB3VaO=TdJqFeTx2s4bXbPZaXw@mail.gmail.com>
In-Reply-To: <20140915051242.GA1175@tiny-r269739>
References:  <4D32ABC9-D0D0-48D2-98D3-FF1D72A4261E@gmail.com> <6.0.0.22.2.20140910111010.052bfb38@mail.computinginnovations.com> <A9FD5744-C05D-43C3-815D-F253F9B76FB0@gmail.com> <B7FAE207-78AC-431F-9D33-B8C8C76BD4E1@gmail.com> <alpine.BSF.2.11.1409141113370.27884@wonkity.com> <lv4oa8$md4$1@ger.gmane.org> <20140914192419.GA1559@tiny-r269739> <CAOgwaMvzGzzR9RwcCiSM4viHbc=kTuEaM5zy%2BwULROBFE7jmiw@mail.gmail.com> <20140915051242.GA1175@tiny-r269739>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Sep 14, 2014 at 10:12 PM, Matthias Apitz <guru@unixarea.de> wrote:

> El d=C3=ADa Sunday, September 14, 2014 a las 01:55:44PM -0700, Mehmet Ero=
l
> Sanliturk escribi=C3=B3:
>
> > On Sun, Sep 14, 2014 at 12:24 PM, Matthias Apitz <guru@unixarea.de>
> wrote:
> >
> > > I always test new versions of FreeBSD on USB keys, right now while
> > > typing I run a 11-CURRENT with KDE ... and mutt as MUA booted from an
> USB
> > > key, while the disk in the laptop has still an older FreeBSD.
> > >
> > > The procedure to creat a boot-able USB key is simple:
> > >
> > > - make a file system on it
> > > - mount it to /mnt
> > > - do 'make installkernel' and 'make installworld' with DESTDIR=3D/mnt
> > > - enrich the file system in /mnt with some stuff (for example install
> > >   packages into it with 'chroot /mnt pkg install ...')
> > > - unmount and reboot
> > >
> > > even better, if you do not use an USB key directly, but do all the
> above
> > > to a mdconfig file system (a file system in a normal plain file) and
> > > copy later the result with dd(1) to the real USB key;
> > >
> > > let me know if you need a detailed procedure of it.
> > >
> >
> > Dear Matthias ,
> >
> >
> > If you supply such an algorithm , me and other people may use it to
> > generate boot-able USB sticks with some installed packages .
> >
> > Thank you very much .
> >
> >
> > Mehmet Erol Sanliturk
>
> here it comes; comments are always welcome;
>
>         matthias
>
>
> $Id: buildingImage.txt,v 1.15 2014/08/15 17:39:21 guru Exp $
>
>        Building bootable FreeBSD/i386 USB keys
>              <guru@unixarea.de>
>
> This small howto file describes how to build and enrich bootable USB keys=
.
> Some ideas are stolen from:
>
> http://bsdimp.blogspot.com/2007/10/building-bootable-freebsdi386-images.h=
tml
>
> File operations, esp. of a large amount of small files, are very SLOW
> on USB keys. That's why we use in general the following procedure:
>
> 1. dd(1) the complete /dev/da0 to a plain file, an image of the USB key;
> 2. use mdconfig(8) to make a memory disk of this file and mount(8) it;
> 3. do everything of the formatting and installation in this virtual disk;
> 4. unmount(8) it and dd(1) it back to the USB key;
>
> here we go (use for /dev/da0 what your key is in /var/log/messages):
>
> check the size of your USB key with:
>
> # dd if=3D/dev/da0 of=3D/dev/null bs=3D8m
> 1878+1 records in
> 1878+1 records out
> 15758000128 bytes transferred in 783.312179 secs (20117139 bytes/sec)
>
> note: this step is essential to define an image which later fits again to
> the
> real USB key; my "16 Gbyte" keys vary between 1868 and 1914 blocks of 8m
> (which is ofc lesse than 16 GByte); that's why I decided to use always th=
e
> number 1860 for my keys of this "16 marketing GBytes".
>
> now we create an empty large disk file of this size 1860 blocks of 8m:
>
> # dd if=3D/dev/zero of=3Dda0.r269739 bs=3D8m count=3D1860
>
> attach the file da0.r269739 as a memory disk:
>
> # mdconfig -a -t vnode -f da0.r269739
> md0
>
> now we use the normal procedure to create a bootable UFS on /dev/md0:
>
> # fdisk -I md0
> # fdisk -B md0
> # bsdlabel -w md0s1 auto
> # bsdlabel -B md0s1
> # bsdlabel -e md0s1  # edit the disk label and change partition "a" from
> "unused" to "4.2BSD"
>
> build the file system:
>
> # newfs /dev/md0s1a
> # mount /dev/md0s1a /mnt
>
> note: if your running host system is older than 20121201 (see
> src/UPDATING) you
> must add some new user if you try to install 'head':
>
> # pw useradd -n auditdistd -g audit -c "Auditdistd unprivileged user" -d
> /var/empty -s /usr/sbin/nologin
>
> install the system from your host which must have been compiled
> in /usr/src; if you compiled it in another place check for MAKEOBJDIRPREF=
IX
> below;
>
> # cd /usr/src
> # make installworld  DESTDIR=3D/mnt
> # make installkernel DESTDIR=3D/mnt KERNCONF=3DGENERIC INSTALL_NODEBUG=3D=
t
> # make distrib-dirs  DESTDIR=3D/mnt
> # make distribution  DESTDIR=3D/mnt
>
> the new system in /mnt needs some files to start:
>
> # echo /dev/da0s1a / ufs rw,noatime 1 1 > /mnt/etc/fstab
> # cp /etc/wpa_supplicant.conf /mnt/etc
>
> # cat <<EOF > /mnt/etc/rc.conf
> tmpmfs=3D"YES"
> tmpsize=3D"128m"
> wlans_ath0=3D"wlan0"
> ifconfig_wlan0=3D"WPA DHCP"
> ifconfig_bge0=3D"DHCP"
> hostname=3Dtiny-r269739
> sshd_enable=3D"YES"
> moused_enable=3D"YES"
> dbus_enable=3D"YES"
> hald_enable=3D"YES"
> vboxguest_enable=3D"YES"
> vboxservice_enable=3D"YES"
> keymap=3D"german.iso"
> # powerd
> powerd_enable=3D"YES"
> powerd_flags=3D"-a max -b adp"
> performance_cx_lowest_cx_lowest=3D"Cmax"
> economy_cx_lowest=3D"Cmax"
> EOF
>
> # cat <<EOF > /mnt/boot/loader.conf
> kern.cam.boot_delay=3D"10000"
> kern.cam.scsi_delay=3D"3000"
> hint.p4tcc.0.disabled=3D1
> hint.acpi_throttle.0.disabled=3D1
> EOF
>
> to use the above created USB key to install another system (the EeePC for
> example, or the Acer) we need 'src' and 'obj' as well on the key:
>
> # cd /usr
> # cp -Rp src /mnt/usr
> # cp -Rp obj /mnt/usr
>
> but remove the SVN control files from the copied soure tree:
>
> # rm -rf /mnt/usr/src/.svn
>
> enrich the USB key with the prepared packages:
>
> # cd /usr/local/poudriere/data/packages/freebsd-head-ports-head/All
> # cp -p * /mnt/PKGDIR
>
> o run later
>
> # cd /usr/local/poudriere/data/packages/freebsd-head-ports-head/All
> # rsync -avz . /mnt/PKGDIR
>
> as well we need in 11-CURRENT now the new pkg(8) command; we compile
> the old way ports-mgmt/pkg-devel and install only 'pkg-static' into
> the /mnt system:
>
> # cd /usr/ports/ports-mgmt/pkg-devel
> # make install
> # chroot /mnt mkdir -p /usr/local/sbin
> # cp -p /usr/local/sbin/pkg-static /mnt/usr/local/sbin
>
> let's see if this works:
>
> # chroot /mnt /usr/local/sbin/pkg-static help
>
> first we have to build the 'repo' from the directory of all
> packages; we run:
>
> # chroot /mnt pkg-static repo /PKGDIR
> Creating repository in /PKGDIR: 83%
> ...
> Packing files for repository: 100%
>
> the recent version of pkg(8) needs in any case the definition
> of the respository; we create the myrepo.conf file as:
>
> # chroot /mnt mkdir -p /usr/local/etc/pkg/repos
> # vim /mnt/usr/local/etc/pkg/repos/myrepo.conf
> # cat /mnt/usr/local/etc/pkg/repos/myrepo.conf
>
>            FreeBSD: {
>                url: "file:/PKGDIR",
>                enabled: true,
>            }
>
> now we are able to install any stuff (and its dependencies), here
> as an example 'autoconf-2.69' and its dependencies:
>
> # chroot /mnt pkg-static -R /usr/local/etc/pkg/repos/  install
> autoconf-2.69
> Updating repository catalogue
> FreeBSD repository is up-to-date
> All repositories are up-to-date
> The following 5 packages will be affected (of 0 checked):
>
> New packages to be INSTALLED:
>         autoconf: 2.69
>         indexinfo: 0.2
>         perl5: 5.16.3_11
>         m4: 1.4.17_1,1
>         autoconf-wrapper: 20131203
>
> The process will require 45 MB more space
> 13 MB to be downloaded
>
> Proceed with this action [y/N]: y
> Fetching autoconf-2.69.txz: 100% of 529 KB
> Fetching indexinfo-0.2.txz: 100% of 6 KB
> Fetching perl5-5.16.3_11.txz: 100% of 12 MB
> Fetching m4-1.4.17_1,1.txz: 100% of 183 KB
> Fetching autoconf-wrapper-20131203.txz: 100% of 4 KB
> Checking integrity... done (0 conflicting)
> [1/5] Installing indexinfo-0.2: 100%
> [2/5] Installing perl5-5.16.3_11: 100%
> [3/5] Installing m4-1.4.17_1,1: 100%
> [4/5] Installing autoconf-wrapper-20131203: 100%
> [5/5] Installing autoconf-2.69: 100%
>
> are they really there?:
>
> # chroot /mnt pkg-static info
> autoconf-2.69                  Automatically configure source code on man=
y
> Un*x platforms
> autoconf-wrapper-20131203      Wrapper script for GNU autoconf
> indexinfo-0.2                  Utility to regenerate the GNU info page
> index
> m4-1.4.17_1,1                  GNU m4
> perl5-5.16.3_11                Practical Extraction and Report Language
>
> later, when the system we building in /mnt is booted, we can use
> pkg-static directly with the same repo, we do:
>
> # pkg-static -R /usr/local/etc/pkg/repos/  install foo-x.x
>
> copy some initial xorg.conf files to see what we can make use
> of them later:
>
> # cp /etc/X11/xorg.* /mnt/etc/X11
>
> add an unpriv user 'guru' (for beeing able to SSH-in):
>
> # chroot /mnt /usr/sbin/adduser
>
> and enrich its HOME with files to bringup KDE:
>
> # cp -p ~guru/.xinitrc   /mnt/home/guru
> # cp -p ~guru/.xserverrc /mnt/home/guru
>
> umount the key, detach the memory disk and copy the image back
> with dd(1) to the USB device:
>
> # umount /mnt
> # mdconfig -d -u md0
> # dd if=3Dda0.r269739 of=3D/dev/da0 bs=3D8m
>
>
> soem more hints for special cases:
>
> If we have the real USB device locally, but the image on a laptop
> without USB ports, one may use:
>
> # ssh -C root@10.49.8.36 dd of=3D/dev/da1 bs=3D8m < da0-r269739
> 0+823717 records in
> 1868+0 records out
> 15669919744 bytes transferred in 12135.626342 secs (1291233 bytes/sec)
> #
> (i.e. around 3h 17min)
>
> To write the image from the VM to Ubuntu's USB port:
>
> $ ssh -C 192.168.2.102
> $ sudo chmod 0666 /dev/sdb
> $ ssh -C 192.168.2.102 dd of=3D/dev/sdb bs=3D8M < da0-r269739
>
> MAKEOBJDIRPREFIX hints to compile in and install from some other places:
>
> If you want to build world and kernel out of SVN in 'src' and into 'obj',
> but in
> some other place as /usr/[src|obj], for example in
> /home/guru/head/[src|obj]
> use this procedure:
>
> # mkdir -p /home/guru/head/obj
> # MAKEOBJDIRPREFIX=3D/home/guru/head/obj ; export MAKEOBJDIRPREFIX
> # cd /home/guru/head
> # svn checkout svn://svn.freebsd.org/base/head src
>
> # cd /home/guru/head/src
> # make buildworld
> # make buildkernel KERNCONF=3DGENERIC
> ...
>
> if you have built the kernel and world in some other place as /usr/src:
>
> # MAKEOBJDIRPREFIX=3D/home/guru/head/obj ; export MAKEOBJDIRPREFIX
> # cd /home/guru/head/src
> # make installworld  DESTDIR=3D/mnt
> # make installkernel DESTDIR=3D/mnt KERNCONF=3DGENERIC INSTALL_NODEBUG=3D=
t
> # make distrib-dirs  DESTDIR=3D/mnt
> # make distribution  DESTDIR=3D/mnt
> ...
>
> to use the key to install other system, you must have 'src' and 'obj'
> again in the correct places; do:
>
> # mkdir -p /mnt/usr/home/guru/head/
> # cd /mnt
> # ln -s usr/home home
>
> # cd /home/guru/head/
> # cp -Rp src /mnt/home/guru/head/    # 40 mins
> # cp -Rp obj /mnt/home/guru/head/    # 20 mins
>
>
> --
> Matthias Apitz               |  /"\   ASCII Ribbon Campaign:
> E-mail: guru@unixarea.de     |  \ /   - No HTML/RTF in E-mail
> WWW: http://www.unixarea.de/ |   X    - No proprietary attachments
> phone: +49-170-4527211       |  / \   - Respect for open standards
>                              | en.wikipedia.org/wiki/ASCII_Ribbon_Campaig=
n
>




Thank you very much .

Mehmet Erol Sanliturk



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOgwaMtUKNiFdtj%2BNKH8BRGOMB3VaO=TdJqFeTx2s4bXbPZaXw>