• Adding a hardware swap partition

    From bp@3:633/10 to All on Thursday, March 12, 2026 10:00:01
    Is there a "recipe" for adding a hardware swap partition to an
    existing RasPiOS installation? Ideally I'd like a traditional
    layout, with swap situated between / and /usr. I know how to
    do it with FreeBSD during the install process but this particular
    case involves a running, somewhat valuable RasPiOS installation
    and the tools offered on RasPiOS are different enough to warrant
    a study of prior art if it's available.

    What I'd like to do is resize the existing root to roughly its
    present, occupied size, add a swap partition in the freed space
    and then create /usr in the remaining space, copying the old
    /usr to the new, cleaning out usr files from the original root
    partition and mounting the new /usr on the empty mountpoint.

    This needs to be done under single-user mode and I don't know
    how to get at single-user in RasPiOS. It could be done via booting
    from a microSD, but that pitches me into the installer which isn't
    exactly familiar territory.

    In case it matters, this is on an 8GB Pi5 running Bookworm with
    dual monitors and a 1 TB mechanical hard drive. df reports

    Filesystem 1K-blocks Used Available Use% Mounted on
    udev 4081296 0 4081296 0% /dev
    tmpfs 1650304 6512 1643792 1% /run
    /dev/sda2 961067256 61907904 850331260 7% /
    tmpfs 4125728 163136 3962592 4% /dev/shm
    tmpfs 5120 48 5072 1% /run/lock
    /dev/sda1 522230 79520 442710 16% /boot/firmware
    tmpfs 825136 272 824864 1% /run/user/1000

    The need for "real" swap arises when Chromium and Firefox are both
    running with multiple tabs open.

    Thanks for reading, and any suggestions!

    bob prohaska


    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Lawrence D?Oliveiro@3:633/10 to All on Thursday, March 12, 2026 10:00:01
    On Wed, 11 Mar 2026 16:20:15 -0000 (UTC), bp wrote:

    This needs to be done under single-user mode and I don't know
    how to get at single-user in RasPiOS.

    This is done by modifying the kernel command line -- there should be a bootloader option to do this on a one-time basis before actually
    loading the kernel.

    The option ?single? should do the trick, though I think it will prompt
    for the root password before allowing you in.

    Another option to try is ?init=/bin/bash?.

    These options should be common across Linux kernels, independent of architecture or bootloader.

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From The Natural Philosopher@3:633/10 to All on Wednesday, March 11, 2026 16:43:39
    On 11/03/2026 16:20, bp@www.zefox.net wrote:
    Is there a "recipe" for adding a hardware swap partition to an
    existing RasPiOS installation? Ideally I'd like a traditional
    layout, with swap situated between / and /usr. I know how to
    do it with FreeBSD during the install process but this particular
    case involves a running, somewhat valuable RasPiOS installation
    and the tools offered on RasPiOS are different enough to warrant
    a study of prior art if it's available.

    What I'd like to do is resize the existing root to roughly its
    present, occupied size, add a swap partition in the freed space
    and then create /usr in the remaining space, copying the old
    /usr to the new, cleaning out usr files from the original root
    partition and mounting the new /usr on the empty mountpoint.

    This needs to be done under single-user mode and I don't know
    how to get at single-user in RasPiOS. It could be done via booting
    from a microSD, but that pitches me into the installer which isn't
    exactly familiar territory.


    I don't think that is necessarily true.

    If you create a bootable SD card, you can do all you want to the sda
    disk whilst it's online

    You could also create a swap file in / and add that as an alternative



    In case it matters, this is on an 8GB Pi5 running Bookworm with
    dual monitors and a 1 TB mechanical hard drive. df reports

    Filesystem 1K-blocks Used Available Use% Mounted on
    udev 4081296 0 4081296 0% /dev
    tmpfs 1650304 6512 1643792 1% /run
    /dev/sda2 961067256 61907904 850331260 7% /
    tmpfs 4125728 163136 3962592 4% /dev/shm
    tmpfs 5120 48 5072 1% /run/lock
    /dev/sda1 522230 79520 442710 16% /boot/firmware
    tmpfs 825136 272 824864 1% /run/user/1000

    The need for "real" swap arises when Chromium and Firefox are both
    running with multiple tabs open.

    Yaj well no fine

    I'd add a swap file. work of a few minutes only

    $ dd if=/dev/zero of=/path/to/swapfile bs=1M count=1024 # For 1GB swap file
    $ mkswap /path/to/swapfile
    $ swapon /path/to/swapfile



    Thanks for reading, and any suggestions!

    bob prohaska


    --
    Climate is what you expect but weather is what you get.
    Mark Twain


    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Jim Jackson@3:633/10 to All on Friday, March 13, 2026 10:00:02
    Newsgroups: comp.sys.raspberry-pi
    From: Jim Jackson <jj@franjam.org.uk>
    Subject: Re: Adding a hardware swap partition
    References: <10os4nv$17t1j$1@dont-email.me>
    Followup-To:

    On 2026-03-11, bp@www.zefox.net <bp@www.zefox.net> wrote:
    Is there a "recipe" for adding a hardware swap partition to an
    existing RasPiOS installation? Ideally I'd like a traditional
    layout, with swap situated between / and /usr.


    AFAIK modern PIOS versions all use merged /usr, as they are based on
    debian which /usr merged. This means that the /usr directory has to
    reside on the root partition. I usually put my swap partition between
    root and /home partitions.

    I'm assuming your PIOS is running systemd so try looking at

    man systemd.swap

    I remember that on a SYSV init system I think I ran mkswap on the disk partition, then added an entry to /etc/fstab like

    /dev/sda2 none swap sw 0 0

    and just rebooted.

    I tend to use a swap file nowadays.

    cheers
    Jim







    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Lawrence D?Oliveiro@3:633/10 to All on Friday, March 13, 2026 10:00:02
    On Thu, 12 Mar 2026 15:37:29 -0000 (UTC), bp wrote:

    Lawrence D?Oliveiro <ldo@nz.invalid> wrote:

    This is done by modifying the kernel command line -- there should
    be a bootloader option to do this on a one-time basis before
    actually loading the kernel.

    I can understand editing cmdline.txt and rebooting as a way to get
    single user ...

    No, this is using one of the options in the bootloader menu
    (?advanced?, I think it is) to do a one-time edit to the command line
    for that boot. You don?t want to permanently put the system to booting
    into single-user mode every time, do you?

    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From bp@3:633/10 to All on Friday, March 13, 2026 10:00:02
    Lawrence D?Oliveiro <ldo@nz.invalid> wrote:
    On Wed, 11 Mar 2026 16:20:15 -0000 (UTC), bp wrote:

    This needs to be done under single-user mode and I don't know
    how to get at single-user in RasPiOS.

    This is done by modifying the kernel command line -- there should be a bootloader option to do this on a one-time basis before actually
    loading the kernel.

    The option ?single? should do the trick, though I think it will prompt
    for the root password before allowing you in.

    Another option to try is ?init=/bin/bash?.

    These options should be common across Linux kernels, independent of architecture or bootloader.

    I can understand editing cmdline.txt and rebooting as a way to get single
    user, but by the time there's anything visible on the monitor the kernel
    is already starting services and well past any opportunity to intervene.

    It looks as if swap files have their advocates. Just how much slower is
    a swap file? It certainly looks easier and might be a good experiment.

    Thanks to everybody for replying!

    bob prohaska


    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From bp@3:633/10 to All on Friday, March 13, 2026 13:00:01
    Lawrence D?Oliveiro <ldo@nz.invalid> wrote:
    On Thu, 12 Mar 2026 15:37:29 -0000 (UTC), bp wrote:

    Lawrence D?Oliveiro <ldo@nz.invalid> wrote:

    This is done by modifying the kernel command line -- there should
    be a bootloader option to do this on a one-time basis before
    actually loading the kernel.

    I can understand editing cmdline.txt and rebooting as a way to get
    single user ...

    No, this is using one of the options in the bootloader menu
    (?advanced?, I think it is) to do a one-time edit to the command line
    for that boot.

    I'm not familiar with such a menu, how is it invoked?

    You don?t want to permanently put the system to booting
    into single-user mode every time, do you?
    No, but I could edit cmdline.txt, reboot to single-user,
    finish my business, re-edit cmdline.txt and reboot again.

    I was hopeful somebody would respond to my query regarding
    the relative speeds of swapfiles vs swap partitions. If
    they're anywhere close in performance a swapfile seems
    worth trying.

    Thanks for writing!

    bob prohaska


    --- PyGate Linux v1.5.12
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)