Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Sep 2016 00:59:13 +1000 (EST)
From:      Ian Smith <smithi@nimnet.asn.au>
To:        Perry Hutchison <perryh@pluto.rain.com>
Cc:        freebsd-questions@freebsd.org, Warren Block <wblock@wonkity.com>
Subject:   Re: "gpart add" falsely claiming "No space left on device"
Message-ID:  <20160907000551.F91459@sola.nimnet.asn.au>
In-Reply-To: <mailman.109.1473163202.26682.freebsd-questions@freebsd.org>
References:  <mailman.109.1473163202.26682.freebsd-questions@freebsd.org>

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
In freebsd-questions Digest, Vol 640, Issue 2, Message: 5
On Tue, 06 Sep 2016 00:21:08 -0700 perryh@pluto.rain.com (Perry Hutchison) wrote:

 > I copied the 10.3-RELEASE memstick.img to a 4GB flash drive, then used
 > "gpart recover" to resize the partition table to the media.  After that
 > "gpart show" reports:
 > 
 > # gpart show da2
 > =>      3  7811067  da2  GPT  (3.7G)
 >         3       32    1  freebsd-boot  (16K)
 >        35  1348832    2  freebsd-ufs  (659M)
 >   1348867     2048    3  freebsd-swap  (1.0M)
 >   1350915  6460155       - free -  (3.1G)
 > 
 > but "gpart add" refuses to add a second freebsd-ufs partition in that
 > supposedly-free space:
 > 
 > # gpart add -t freebsd-ufs -l pkgs -f x da2
 > gpart: index '4': No space left on device
 > 
 > # gpart add -t freebsd-ufs -l pkgs -f x -b 1350915 -s 6460155 da2
 > gpart: index '4': No space left on device
 > 
 > All of these partitions are unmounted.
 > 
 > What am I doing wrong?

Hi Perry,

How did you 'copy' the memstick.img to the flash drive?

root@x200:~ # ll /dev/da*
crw-rw----  1 root  operator  0x8c Sep  6 19:12 /dev/da0
crw-rw----  1 root  operator  0x8d Sep  6 19:12 /dev/da0a

root@x200:~ # 
gpart show da0
=>      0  1974272  da0  BSD  (964M)
        0  1523248    1  freebsd-ufs  (743M)
  1523248   451024       - free -  (220M)

That's a 10.3 memstick.img dd'd to a 1G stick.  For some bizarre reason, 
maybe 10? years on, these are still being made as pseudo-floppy images, 
here as da0a, rather than something sane like da0s1a, where you could 
merrily add more (MBR) partitions and use boot0cfg to choose between 
them - as PC-BSD has been doing for years - or with GPT, at least extra 
data partition/s as you want here, useful in itself.

It's actually a bodgy image; here's what fdisk makes of that 1G stick:

root@x200:~ # fdisk /dev/da0
******* Working on device /dev/da0 *******
parameters extracted from in-core disklabel are:
cylinders=973 heads=255 sectors/track=63 (16065 blks/cyl)

parameters to be used for BIOS calculations are:
cylinders=973 heads=255 sectors/track=63 (16065 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
<UNUSED>
The data for partition 2 is:
<UNUSED>
The data for partition 3 is:
<UNUSED>
The data for partition 4 is:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 0, size 50000 (24 Meg), flag 80 (active)
        beg: cyl 0/ head 0/ sector 1;
        end: cyl 1023/ head 254/ sector 63

Most of which is nonsense, except that it does start at sector 0, while 
imcorporating an MBR and a BSD disklabel, and of course size is bogus.

Sadly, nobody has yet duplicated something like boot0cfg for GPT, so 
multibooting from GPT seems to require GPL stuff like GRUB, or maybe 
the more complicated (for me, anyway) Boot Environments and such.

Trying to solve this, I've used Darren Pilgrim's dvd1_to_memstick.sh 
successfully to make bootable memsticks from dvd1 images, though never 
solved the 'bsdinstall / bsdconfig can't find the packages' issue, for 
which the release notes for 10.3 at least, and 11, have a workaround.
I've run out of puff to try incorporating that this time around.

FWIW, here's my (excessivey paranoid) adaptation of Darren's script; but 
it still uses MBR layout and winds up as /dev/daXa when mounted|booted.

Perhaps you or Warren or someone could adapt it for GPT, though myself 
I'd still prefer it as MBR sliced, so you could boot, say, 10.3 or 11.0, 
i386 or amd63, with the DVD packages, from say one 8- or 16GB stick.  It 
should be clear that after the tar poipeline, there's scope to play.

cheers, Ian  (please cc me, I take the digest)

=======
#!/bin/sh
#% originally by Darren Pilgrim 17/12/13 from http://pastebin.com/fzgVaCgW
#% smithi@nimnet.asn.au 22/2/14 for FreeBSD 8.2-R (no makefs label option)
#% compaction & extra paranoia 23/6/14; rm 8.2 hack, quit() tidyup 11/9/14

PATH=/bin:/usr/bin:/sbin:/usr/sbin
export PATH

if [ -z "$*" ]; then
    echo `basename $0 [dvd1 img] [dvd1 dir] [memstick img] [memstick dir]`
    echo ' [dvd1 img] is the dvd1 image to convert'
    echo ' [dvd1 dir] is the mountpoint for the dvd1 image'
    echo ' [memstick img] is name of the memstick image file to create'
    echo ' [memstick dir] is temporary work directory for memstick contents'
    exit 1
fi

quit() { echo "$1" ; exit 1 ; }

[ `id -u` -ne 0 ] && quit "This script must be run as root"
[ ! -f $1 ] && quit "Source dvd1 image $1 does not exist"
[ ! -d $2 ] && quit "dvd1 dir mountpoint $2 must be a directory"
[ -e $3 ] && quit "Memstick img file $3 already exists"
[ ! -d $4 ] && quit "Memstick dir $4 not an existing directory"
[ `du -sm $4 | awk '{print $1}'` -gt 2 ] && quit "Memstick dir $4 not empty"

unit=`mdconfig -f $1` || quit "dvd1 img mdconfig fail"
mount_cd9660 /dev/$unit $2 || quit "mount_cd9660 fail"

tar cf - -C $2 . | tar xpf - -C $4 || quit "tar pipeline fail"

umount $2 && mdconfig -d -u $unit || quit "Could not umount dvd1"

echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > $4/etc/fstab
makefs -B little -o label=FreeBSD_Install $3 $4 || quit "makefs fail"

unit=`mdconfig -f $3` || quit "memstick img mdconfig fail"
gpart create -s BSD $unit || quit "gpart create -s BSD fail"
gpart bootcode -b $4/boot/boot $unit || quit "gpart bootcode fail"
gpart add -t freebsd-ufs $unit || quit "gpart add -t freebsd-ufs fail"

mdconfig -d -u $unit
echo "Memstick image $3 created:" ; ls -l $3
=======



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?20160907000551.F91459>