Lädt...


🐧 stupid linux tricks - boot a USB stick in "copy to RAM" mode even if it doesn't have that feature (or boot from an SD card when the BIOS doesn't support that)


Nachrichtenbereich: 🐧 Linux Tipps
🔗 Quelle: reddit.com

I often don't want one of my USB ports tied up the whole time I'm using a USB-booted system, and I just realised that I could do this:

  1. Boot from USB as normal, and let it start booting.

  2. At the very beginning of initramfs, yank the USB stick out, and wait until you get an error message and get dumped to the emergency shell.

  3. At this point, stick the USB stick back in and copy it to RAM. You'll need to know the exact size of the important filesystems for this; for example, if your boot stick is a 700 MB .iso file that you dd'd onto your USB stick, do something like "dd if=/dev/sdX bs=1M count=700 of=/run/bootstick.iso" or "head -c700M /dev/sdX > /run/bootstick.iso".

  4. Yank the USB stick out again.

  5. Set up a loop device pointing to that file, e.g. "losetup -rfP /run/bootstick.iso"

  6. Exit the emergency shell.

Surprise! The loop device creation results in all the same /dev/disk/by-X links being created, because the relevant UUIDs, partition labels, etc. are all preset in the loop devices, just as they were on the USB stick.

Some tweaks may be needed, obviously; here are some general hints:

  • This works in EFI mode, so it can be useful for boot sticks that have "copy to RAM" in the CSM mode boot menu but not in EFI (e.g. the Arch Linux installer). (The reason a lot of previous copy-to-RAM boot don't work in EFI is that they operate very early and copy e.g. an ISO file into a RAMdisk before the kernel has even started, then chainload boot to the RAMdisk. That kind of hackery is harder to do in EFI. The method described here works because the kludge-y handoff to RAM is happening well after the BIOS has finished its role in the boot process; by the time the kernel is running stuff from initramfs, Linux has full control of the system already.)

  • How to tell when to yank out the USB stick: To start the early boot process, only two files need to be read: the Linux kernel itself, and the initramfs file. Once you start seeing boot messages that come from things in the initramfs, e.g. udev, the initramfs file is fully in memory, so you can yank the USB stick without worrying about e.g. I/O errors in the middle of reading something.

  • Further to previous, you may need to hit the "edit boot entry" key at the bootloader menu and remove "quiet" from the kernel command line (or add "noquiet"), as a lot of distros like to hide the boot messages by default.

  • The example in step 3 assumes that the initramfs has mounted the /run filesystem as tmpfs or similar, and that it's sufficiently large for this. This isn't guaranteed; you can probably create your own tmpfs mount though, and by default, a simple "mount -t tmpfs tmpfs /mountpoint" will create half the RAM's worth of space. (Note that the size of a tmpfs mount is only a maximum usage limit; a tmpfs filesystem only uses as much RAM as the size of the files in it, so this isn't a waste of memory.)

  • Some initramfs configurations don't seem to automatically create /dev/disk/by-X entries for loop devices - if your system still complains of not being able to find the root filesystem, you can do this manually, e.g.

    mkdir /dev/disk/by-label

    cd /dev/disk/by-label

    ln -s /dev/loopXpY myrootfslabel

How to use this to boot from an SD card when the BIOS doesn't support that

  1. Put the SD card in a USB card reader, and allow the system to start booting as above.

  2. At step 2, yank the SD card reader out, pull the SD card out of the reader, and insert it into the system's SD card slot.

  3. Skip all the RAM copying steps, and just exit the emergency shell now. With a little luck, the initramfs's udev or whatever will find the correct volume again and continue mounting the root filesystem as if nothing odd has happened.

In some systems this will work immediately; in others, it seems that the card reader needs a special driver or something that isn't loaded until later (e.g. an HP laptop I have). To get around this, you'll need to find out which modules make the SD card reader work (probably mmc something?) and ensure they're included when you build your initramfs.

submitted by /u/will_try_not_to
[link] [comments] ...

🔧 Tìm Hiểu Về RAG: Công Nghệ Đột Phá Đang "Làm Mưa Làm Gió" Trong Thế Giới Chatbot


📈 39.47 Punkte
🔧 Programmierung

🐧 Stupid Linux Tricks - walk a btrfs filesystem into RAM and back


📈 36.36 Punkte
🐧 Linux Tipps

🔧 What are different between Normal Copy and Shallow Copy, Deep Copy in JavaScript Object


📈 34.82 Punkte
🔧 Programmierung

📰 Stupid, stupid MacOS security flaw grants admin access to anyone


📈 33.77 Punkte
📰 IT Security Nachrichten

📰 Stupid Is as Stupid Does: XDR Is About the Journey, Not the Destination


📈 33.77 Punkte
📰 IT Security Nachrichten

🎥 HPR3678: "Stupid Users" ... no, not those users, the other "stupid users"


📈 33.77 Punkte
🎥 Podcasts

🍏 Stop using these stupid, stupid passwords immediately


📈 33.77 Punkte
🍏 iOS / Mac OS

📰 Bios doesn't support 'secure boot' what are my options?


📈 31.1 Punkte
📰 IT Security Nachrichten

📰 Sicherheit von mobilen Datenträgern: USB-Stick ist nicht gleich USB-Stick - Funkschau


📈 30.4 Punkte
📰 IT Security Nachrichten

📰 Linux copy and clone USB stick including partitions command


📈 29.25 Punkte
📰 IT Security Nachrichten

🍏 Ad agency zombifies TUAW with AI copy & recycled bylines in stupid SEO play


📈 28.49 Punkte
🍏 iOS / Mac OS

🕵️ Dell Inspiron 7347 BIOS prior A13 UEFI BIOS Boot Services use after free


📈 28.09 Punkte
🕵️ Sicherheitslücken

matomo