The Linux Thread - The Autist's OS of Choice

Oh woe is the eternal Linux user that I am. I nuked my home directory by accident when I set the mount point for my extra hard drive as "/home/", thankfully those files are backed up on an external SSD. For some reason it was constantly mounting and unmounting itself. On the bright side, I am more familiar with post install set up since I went scorched earth and did a full reinstall with the extra hardrive as a target. It's just got a small flock of empty folders I could probably delete but to be on the safe side I will simply let them stay there since everything automagically goes to sda1 and not sdb1/man 6 or whatever.
If you mount a drive over a folder it won't wipe the contents of that folder, just make it inaccessible until you either unmount or symlink the folder (or it's containing folder I forget) to a different location.
 
Of course not, it's 5 extra letters to type. Running everything as root is much better.
Which is what I was doing as at the time I was moving a bunch of files around that belonged to user accounts that dont exist on this system
 
Why would it? The entire point of SELinux is to prevent processes writing to shit they have no business writing to. Running tar as root doesn't fall in that category.
Speaking of SELinux..

mac_security_sesamestreet.jpg
 
Which is what I was doing as at the time I was moving a bunch of files around that belonged to user accounts that dont exist on this system
Which is why we now have an informative discussion here. See? You did good.
 
  • Thunk-Provoking
Reactions: DavidS877
True, however after fucking up repeatedly you'd like to think they'd take a step back and re-evaluate their approach
To be fair, I started the server transfer at like 8pm and didn't finish until 6am, and half of that was spent trying to get the bios to work right and getting clonezilla and copying using gparter to work
 
  • Like
Reactions: Vesperus
heres the script:
Bash:
#!/bin/sh
##check if we are running as root as we need it
if [ `id -u` -ne 0 ]
    then printf "Error: script must be run as root \n" 
    exit
fi

##set variables
kernel=true
busybox=true
image=true
qemu=true

##check enviroment we are running in

#get arguments and set variables acordingly
while getopts "-:" opt; do
    case $opt in
        -)
            case "${OPTARG}" in
                help)
                    printf "advailable commands: \n"
                    printf "    --kernel to compile kernel \n"
                    printf "    --busybox to compile busybox \n"
                    printf "    --image to ready image by making the image \n"
                    printf "    --qemu to test the image in qemu \n"
                    exit
                    ;;
                kernel) kernel=true busybox=false image=false qemu=false ;;
                busybox) kernel=false busybox=true image=false qemu=false ;;
                image) kernel=false busybox=false image=true qemu=false ;;
                qemu) kernel=false busybox=false image=false qemu=true ;;
                *)
                    printf "Invalid command: --${OPTARG} \n"
                    exit
                    ;;
                esac
            ;;
    esac
done

##show us the options we have selected
printf "options we have decided on: \n"
printf "\n"
printf "    [building kernel]: ${kernel} \n"
printf "    [building busybox]: ${busybox} \n"
printf "    [making image]: ${image} \n"
printf "    [running qemu]: ${qemu} \n"
printf "\n"

##kernel
if $kernel
then
    printf "[Building Kernel]: \n"
    cd linux
    #make defconfig
    cp ../.config_kernel .config
    make -j23
    cd ..
else
    printf "    [Skipping kernel] \n"
fi


##busybox
if $busybox
then
    printf "[Building busybox]: \n"
    cd busybox
    make defconfig
    sed 's/^.*CONFIG_STATIC[^_].*$/CONFIG_STATIC=y/g' -i .config
    make -j23
    make ..
else
    printf "    [Skipping buxybox] \n"
fi


##image
if $image
then
    printf "    [Making image]: \n"
    rm -rf temp
    mkdir temp
    cd temp
  
    #make initrd
    mkdir initrd
    cd initrd
    mkdir -p etc bin dev proc sys
    cd bin
    cp ../../../busybox/busybox ./
    for prog in $(./busybox --list); do
        ln -s /bin/busybox ./$prog
    done
    cd ..
    ##initrd init script
    echo '#!/bin/sh' > init
    echo 'mount -t sysfs sysfs /sys' >> init
    echo 'mount -t proc proc /proc' >> init
    echo 'mount -t devtempfs udev /dev' >> init
    echo 'sysctl -w kernel.printk="3 4 1 3"' >> init
    echo 'echo "Welcome to KFLinux"' >> init
    echo '/bin/sh' >> init
    chmod -R 777 init
    find . | cpio -o -H newc > ../initrd.img
    cd ..
  
    #make disk image, format it, install bootloader and copy kernal and initrd
    mkdir mnt
    dd if=/dev/zero of=boot.img bs=1M count=4000
    mkfs -t fat boot.img
    mount boot.img mnt
    extlinux -i mnt/
    cp ../linux/arch/x86_64/boot/bzImage initrd.img mnt/
  
    #install bootloader extras and set bootloader config
    mkdir -p mnt/etc mnt/bin mnt/dev mnt/proc mnt/sys mnt/boot mnt/boot/syslinux mnt/root
    cp /usr/lib/syslinux/modules/bios/* mnt/boot/syslinux
    echo 'UI menu.c32' > mnt/boot/syslinux/syslinux.cfg
    echo 'PROMPT 0' >> mnt/boot/syslinux/syslinux.cfg
    echo 'TIMEOUT 50' >> mnt/boot/syslinux/syslinux.cfg
  
    echo 'LABEL Normal' >> mnt/boot/syslinux/syslinux.cfg
    echo 'KERNEL /bzImage' >> mnt/boot/syslinux/syslinux.cfg
    echo 'APPEND root=/dev/sda rw' >> mnt/boot/syslinux/syslinux.cfg
  
    echo 'LABEL Initrd' >> mnt/boot/syslinux/syslinux.cfg
    echo 'KERNEL /bzImage' >> mnt/boot/syslinux/syslinux.cfg
    echo 'APPEND initrd=/initrd.img root=/dev/sda rw' >> mnt/boot/syslinux/syslinux.cfg
  
  
  
    echo 'LABEL Syslinux' >> mnt/boot/syslinux/syslinux.cfg
    echo 'KERNEL cmd.c32' >> mnt/boot/syslinux/syslinux.cfg
  
    echo 'LABEL Power off' >> mnt/boot/syslinux/syslinux.cfg
    echo 'KERNEL poweroff.c32' >> mnt/boot/syslinux/syslinux.cfg
  
    echo 'LABEL Reboot' >> mnt/boot/syslinux/syslinux.cfg
    echo 'KERNEL reboot.c32' >> mnt/boot/syslinux/syslinux.cfg
  
    #add busybox and init to base image for useable system without initrd
    cd mnt
    cd bin
    cp ../../../busybox/busybox ./
    for prog in $(./busybox --list); do
        cp ../../../busybox/busybox  ./$prog
    done
    cd ..
    cd etc
    #non-initrd init script
    echo '#!/bin/sh' > init
    echo 'mount -t sysfs sysfs /sys' >> init
    echo 'mount -t proc proc /proc' >> init
    echo 'mount -t devtempfs udev /dev' >> init
    echo 'sysctl -w kernel.printk="3 4 1 3"' >> init
    echo '/bin/sh' >> init
    echo 'echo "Welcome to KFLinux"' >> init
    echo '/bin/poweroff' >> init
    chmod -R 777 init
    cd ../..
  
    #extra things
  
  
  
    umount mnt/
    cd ..
  
  
else
    printf "    [Skiping image] \n"
fi


##qemu
if $qemu
then
    printf "[Running qemu]: \n"
    qemu-system-x86_64 temp/boot.img
else
    printf "    [Skiping qemu] \n"
fi
it assumes you've already got all of the nessery pacages to compile and run this shit, and you've extracted linux 5.15.156 and busybox 1.34.1 to their relevent directorys and have the linux .config i've attached as well. (i know it's a txt file, tor keeps crashing when i try to select other files in the windows file chooser interface thing)
i don't care if you think my code is shit (i know it is and i don't care) so criteic it all you want.
enjoy messing around with the freak i've made.
 

Attachments

New piece of hardware, new me. I already settled on Void as the system, so no distro hopping intended. However, I did try several window managers (no DEs), both tiling and dynamic. dwm didn't feel worth the effort to maintain an out-of-tree package just for a few basic tweaks i.e. keybindings. bspwm uses a binary tree as the tiling scheme and I don't want an esoteric window manager. awesomewm is alright, but Lua config is a pain. Went back to good old Openbox and tint2, lesson learned.
 
  • Like
Reactions: Sperg Coalition
If you mount a drive over a folder it won't wipe the contents of that folder, just make it inaccessible until you either unmount or symlink the folder (or it's containing folder I forget) to a different location.
Wish I saw this sooner but oh well it's all stable now. The other hard drive is properly mounted upon startup. the system is tainted with propitiatory nvidia drivers with multilib compat thrown in and I have already ran a voodoo command of some kind that warped a .deb to a .tgz to keep shitcord up to date. the positive side to all this is I have taken more steps towards leaning personal system administration.
 
  • Like
Reactions: Sperg Coalition
it assumes you've already got all of the nessery pacages to compile and run this shit, and you've extracted linux 5.15.156 and busybox 1.34.1 to their relevent directorys and have the linux .config i've attached as well.
I too rolled my own initrd to play around, but its much more complicated, since its doing bitlocker style disk encryption and storing the key on TPM. It's not even that hard to roll your own /init + udev, but systemd shit is definitely trying to make things hard for everyone if you're trying to keep it small to uclibc and maybe lvm2 + ssh while handling more complicated procedures like trying to look for a specific drive by serial or configure a specific ethernet card by MAC address for fallback iscsi boot. There's also s6 init if you're too lazy to write a real init daemon to handle all the startup dependencies inside your initrd.

"defconfig" is probably fine for a toy system, but expect all the drivers and usual features to be missing. You definitely would want to enable the EFI stuff, since some modern boards don't even do compatibility mode anymore.

i don't care if you think my code is shit (i know it is and i don't care) so criteic it all you want.
It's missing the mandatory /dev/console, so userspace command line programs might not even print until started after the devtmpfs mount. Pull it in from your real /dev/console, or mknod your own for the cpio command.
echo '/bin/sh' >> init
echo 'echo "Welcome to KFLinux"' >> init
The other way around. So you see the text before the prompt shows up, not after you exit the prompt.
You'll also likely find that keyboard sequences like CTRL-C don't work, so you could try something like:
exec /bin/cttyhack /bin/sh
This gives you a shell with PID 1 and functioning keyboard controls, so you can do exec /sbin/init if you want to pass control to another Linux system.
Do not exit the shell however, the kernel will assume something went very wrong if PID 1 ever exits, just call "exec poweroff" to shut down.
 
I have Fedora installed on my laptop (I know, I know evil Red Hat and all). Reason I have it installed is it was the only distro that was able to install on a new laptop, back when I first got it, without issues and I hadn't bothered to switch since.

Anyway, I just wanted to share my experience: Since there was the Fedora 40 version update I wanted to upgrade my system. I used the faster dnf5 to upgrade and install, but for some reason it didn't upgrade KDE because it lacked flags --allowerasing, making me scratch my head until I switched to TTY and looked at the logs. I had to use the regular dnf to get the rest upgraded. Not very user friendly for a Red Hat distro.
 
It's missing the mandatory /dev/console, so userspace command line programs might not even print until started after the devtmpfs mount. Pull it in from your real /dev/console, or mknod your own for the cpio command
funnily enough, /dev/console is actually there both in the initrd and non-initrd systems.
i suspect the kernel is automatically providing it since i am mounting dev and udev onto /dev in the init script.
the only real problem i had was that it used to complain it couldn't find /dev/tyy1, 2, 3 and 4.
i can't remember how i fixed it in a non jank way (i think i screwed up one of the mounts and it was causing the system to freak out) but my old fix was just to echo the files there to shut it up for the time being.
 
  • Like
Reactions: Vecr
funnily enough, /dev/console is actually there both in the initrd and non-initrd systems.
i suspect the kernel is automatically providing it since i am mounting dev and udev onto /dev in the init script.
the only real problem i had was that it used to complain it couldn't find /dev/tyy1, 2, 3 and 4.
i can't remember how i fixed it in a non jank way (i think i screwed up one of the mounts and it was causing the system to freak out) but my old fix was just to echo the files there to shut it up for the time being.
It would appear after mounting /dev, but if you tried to echo some text very early in the /init before /dev was mounted, it likely will not be seen. The /bin/sh shell running the /init would likely not be able to echo anything either, since it requires the program to restart to actually open the device node right.

As for /dev/tty*, you can always mknod them and then pack them into the initrd if you need it early before devtmpfs is mounted.

On my system:
$ ls -l /dev/tty{0..3}
crw--w----. 1 root tty 4, 0 Mar 1 07:06 /dev/tty0
crw-------. 1 user tty 4, 1 Apr 25 10:01 /dev/tty1
crw--w----. 1 root tty 4, 2 Mar 1 07:06 /dev/tty2
crw--w----. 1 root tty 4, 3 Mar 1 07:06 /dev/tty3
That translates into "mknod /dev/tty0 c 4 0", or "mknod /dev/tty0 c 4 1" for tty1 and so on to create it for initrd. This was the old way of managing device nodes before devtmpfs and udev came along. It is still relevant for very early parts during Linux start ups. Might as well also add /dev/null so "command > /dev/null" works as expected anywhere.

If you are planning to only play with the setup with only qemu, you could also use qemu's -kernel and -initrd directly, pointing to the kernel and initrd file respectively, no need to create a fake image.

Lastly, if you do want to use kernel modules in the initrd, it would obviously need to be installed in the initrd, but to actually automatically load it, you need to use udev. You can still manually load them through kmod or busybox modprobe/insmod otherwise, but that would require you to be extremely familiar with which drivers is relevant to your setup.
 
I feel like Linux's way of having every bit of your system as a path in the file system is a very bad idea from the home user standpoint. There should be toggleable abstractions for when you don't have to fuck around with the core Linux, so that / misuse, even accidental, won't lead to you fucking everything up. Have the terminal run in "simple mode" where you have letters for mount points, special paths like Config/ to access /etc and so on. Keep / away from the user whenever the user doesn't need to access it.

Linux distress should copy freebsd and have /etc be for system configuration and /usr/local/etc be for installed application configuration. Users can fuck around to their heart's content and not screw up the system.
 
Linux distress should copy freebsd and have /etc be for system configuration and /usr/local/etc be for installed application configuration. Users can fuck around to their heart's content and not screw up the system.
That's already how it would work for any Linux distribution where you would install applications under /usr/local. Issue is, some distributions' package managers never use /usr/local and hence every application managed with it, installed under /usr, has all its configuration in /etc.
 
Yes, most distro package managers don't follow that convention and put shit all over the place, hence why things would be better if they followed that convention.
 
  • Disagree
Reactions: Sperg Coalition
Back