NetBSD: Utilisation d’une clef USB comme partition swap.

Afin de pouvoir mettre à jour NetBSD sur mon soekris en passant par sysupgrade, j’ai eu un besoin urgent d’un espace swap.
N’ayant sous la main qu’une clef USB, je me suis mis en quête de la transformer (du moins en partie) en espace d’échange.
Les lignes qui vont suivre ne sont pas commentés et me servent surtout d’aide mémoire pour une prochaine fois.
Je sais qu’il y a certainement d’autres façons de faire mais celle-ci me paraissait la plus adapté à mes besoins.

  1. On détecte sa clef

# dmesg
umass0 at uhub1 port 1 configuration 1 interface 0
umass0: vendor 0x13fe USB DISK 2.0, rev 2.00/1.00, addr 2
umass0: using SCSI over Bulk-Only
scsibus0 at umass0: 2 targets, 1 lun per target
sd0 at scsibus0 target 0 lun 0: <, USB DISK 2.0, PMAP> disk removable
sd0: 3825 MB, 960 cyl, 255 head, 32 sec, 512 bytes/sect x 7834944 sectors

2. On crée les slices kivonbien.

# fdisk -u /dev/rsd0d

Disk: /dev/rsd0d
NetBSD disklabel disk geometry:
cylinders: 960, heads: 255, sectors/track: 32 (8160 sectors/cylinder)
total sectors: 7834944

BIOS disk geometry:
cylinders: 961, heads: 255, sectors/track: 32 (8160 sectors/cylinder)
total sectors: 7834944

Partitions aligned to 8160 sector boundaries, offset 32

Do you want to change our idea of what BIOS thinks? [n] n

Partition table:
0: NetBSD (sysid 169)
start 2048, size 7832896 (3825 MB, Cyls 0/64/1-960/41/32)
PBR is not bootable: Bad magic number (0x0000)
1: <UNUSED>
2: <UNUSED>
3: <UNUSED>
No active partition.
Drive serial number: 1621135445 (0x60a09055)
Which partition do you want to change?: [none] 0
The data for partition 0 is:
NetBSD (sysid 169)
start 2048, size 7832896 (3825 MB, Cyls 0/64/1-960/41/32)
PBR is not bootable: Bad magic number (0x0000)
sysid: [0..255 default: 169] return
start: [0..960cyl default: 2048, 0cyl, 1MB] return
size: [0..960cyl default: 7832896, 960cyl, 3825MB] return
bootmenu: [] return
The bootselect code is not installed, do you want to install it now? [n] n

Partition table:
0: NetBSD (sysid 169)
start 2048, size 7832896 (3825 MB, Cyls 0/64/1-960/41/32)
PBR is not bootable: Bad magic number (0x0000)
1: <UNUSED>
2: <UNUSED>
3: <UNUSED>
No active partition.
Drive serial number: 1621135445 (0x60a09055)
Which partition do you want to change?: [none] return

Installed bootfile doesn’t support required options.
Update the bootcode from /usr/mdec/mbr? [n] return

We haven’t written the MBR back to disk yet. This is your last chance.
Partition table:
0: NetBSD (sysid 169)
start 2048, size 7832896 (3825 MB, Cyls 0/64/1-960/41/32)
PBR is not bootable: Bad magic number (0x0000)
1: <UNUSED>
2: <UNUSED>
3: <UNUSED>
No active partition.
Drive serial number: 1621135445 (0x60a09055)
Should we write new partition table? [n] y

# disklabel -i -I sd0
partition> i
Filesystem type [?] [MSDOS]: 4.2BSD
Start offset (‘x’ to start after partition ‘x’) [0c, 0s, 0M]: return
Partition size (‘$’ for all remaining) [960.1647058823529050641809590160846710205c, 7834944s, 3825.65625M]: $
partition> W
Label disk [n]? y
Label written partition> Q

  3. On crée le FS dessus

# newfs /dev/rsdoi

/!\ la device est rsd0i et non pas sd0i (r pour raw)

  4. Ensuite on monte la partition et on crée une image qui nous servira comme swap

# mount /dev/sd0e /mnt/usbstick/
# dd if=/dev/zero bs=1m count=2048 of=/mnt/usbstick/swap
# chmod 600 /mnt/usbstick/swap
# swapctl -a -p 1 /mnt/usbstick/swap

5. Vérification, un petit cat /proc/meminfo

# cat /proc/meminfo
Swap: 2147483648 0 2147483648
SwapTotal: 2097152 kB
SwapFree: 2097152 kB

Et voilà !

Lien utile: NetBSD Documentation #swap