cleaning /usr/obj before copying it to USB key

Tim Kientzle tim at kientzle.com
Sat Jun 9 16:24:52 UTC 2012


On Jun 9, 2012, at 7:35 AM, Matthias Apitz wrote:
> 
> To use the (booted) USB key later to install other laptops or netbooks I
> enrich the key with /usr/src and /usr/obj as:
> 
> # cd /usr
> # cp -Rp src /mnt/usr
> # cp -Rp obj /mnt/usr
> 
> my problem is that the both 'cp -Rp ...' commands takes many hours (12
> and six hours) because they are transferring a lot(!!!) of small files;

As someone else pointed out, flash drives are pretty slow
when making a lot of small writes.

You can speed things up a lot by creating the image locally
then copying the image to USB.  Here are parts of a shell
script I've been using for something similar:

# Create an empty file IMG_SIZE bytes
dd if=/dev/zero of=${IMG} bs=1 seek=${IMG_SIZE} count=0
# Attach it as a virtual disk device
MD=`mdconfig -a -t vnode -f ${IMG}`
# Partition the virtual disk
gpart create -s MBR ${MD}
gpart add -t freebsd ${MD}
gpart set -a active -i 1 ${MD}
# Format and mount
newfs ${MD}s1 >/dev/null
mount /dev/${MD}s1 /mnt

… copy stuff …

# Unmount and detach the virtual disk
umount /dev/${MD}s1
mdconfig -d -u ${MD}

# Copy the disk image to your flash drive
dd if=${IMG} of=${SDCARD} bs=8m


> I have had a look into /usr/obj and it seems that after 'makeworld' and
> 'makekernel' there are left over a lot of temporary files from the build
> processes...
> 
> is there a clean way to remove those files before 'cp -Rp obj /mnt/usr'
> while the result is still useful for another make install with DESTDIR=/mnt ?

You can delete all of the '.o' files using a command like this:

   find /usr/obj -name '*.o' | xargs rm

With a little experimenting, you should be able to extend this
to remove most of the intermediate files.



More information about the freebsd-hackers mailing list