The small linux problem thread

On related note what are the common good practices in upper/lower case of variables and function names in Bash?
I’ve seen a lot different styles and wonder what is the most used one.

1 Like

Afaik, there is no absolute rule, but in general, environmental variables are uppercase, so you should use lowercase in your scripts to avoid colliding with an environmental variable and to easily discern between the two.

Also, AFAIK, there is no universal style guide for any shell scripting (Like PEP 8 for Python), but you can find some style guides around and use one that suits you.

Here’s Google’s:

I do recommend always using {} around your variables whenever they are included in a string, and quote them unless there’s a compelling reason not to.

1 Like

Thanks! Will check it definitely.

Have another question. I want to get all files in folder but the find gets them in random order.
I tried with different sorting methods, but can’t get the syntax right:

txt="$(echo $(find . -maxdepth 1 -type f -name "*.txt") | sort -z)"

This gives me warning: command substitution: ignored null byte in input
What is the easiest way of putting in array all files of one type but sorted in alphabetical order?

There’s no guarantee a Blu-ray player can read CDs:

Even if the manufacturer tries to make it work well, some CD compositions may have particular difficulty being read by a Blu-ray drive.

In addition, optical drives are mechanical devices like any other, which can wear out and fail over time. If yours worked with this disc before, it could just be failing.

That echo is unnecessary, and I don’t think the -z option to sort does something you want… Try:

TXT="$(find . -maxdepth 1 -type f -name '*.txt' | sort -n)"
2 Likes

It’s a new CD. If it were failing I would expect it to be failing for all discs, not one in particular. I was also under the impression that Blu Rays, DVDs and CDs used different lasers. The lack of compatibility would be from it having a blue laser for BRD, but not an infra red one for CDs. This would imply that either a drive would be incapable of reading CDs at all, or it could read all CDs.

Noob question about kvm/qemu/virt-manager, what permissions do my .qcow2 files/directory need if I want them to be in a different location than /var/lib/libvirt/images/? My SSD for the root fs is small and I want to keep them on a different disk. Can anyone help me out with an example fstab entry or something?

1 Like

If you are using VMM / virt manager, then have a look at the Edit menu, then Connection details**, then in the box which opens, click the tab on the right for Storage.

** for me, the “Connection Details” menu item was greyed out, until I clicked the “QEMU/KVM” category in the main body of the app

You should be able to click one of the (plus? your DE may vary) icon at the bottom of that page to “add a pool location” which is basically a directory in whatever disk you want.

the files themselves seem to be owned by either root, or libvirt-qemu.
I don’t think it matters much, as long as libvirt group can write to them.

I would say, add a “pool” (directory on the new drive) copy the file to the new location, then edit the machine, and change the location on it’s storage to the copy. Test, and then remove the old copy.

You might have to copy the file as either Root, or with an elevated copy of the system browser (opening a terminal simply to type sudo files is a hacky way to do it, but simpler)

This presumes you already have an additional drive added to the OS.

Do you need help adding the extra drive to the fstab too, or was that just in case you need it for virt-manager to find it?

1 Like

Thanks for the help. I probably should have started at the beginning. Currently I already have some of the images in a pool that is on an external disk that I just mount by clicking the entry in dolphin (ends up as something like /run/media/user/disk). The .qcow2 files in this pool have the permissions shown below.

-rw-r--r-- 1 nobody kvm 101G Dec 15 21:41 Whonix-Gateway.qcow2
-rw-r--r-- 1 nobody kvm 101G Dec 15 21:48 Whonix-Workstation.qcow2
-rw------- 1 root   100  11G Dec 15 21:32 linux2020-2.qcow2
-rw------- 1 nobody kvm 101G Nov 16 00:11 win10-2.qcow2

When I try to start one of them after mounting the disk and launching virt-manger I get the following error:
libvirt.libvirtError: Cannot access storage file '/run/media/user/VMs/new/Whonix-Gateway.qcow2' (as uid:65534, gid:992): Permission denied

The super hacky way that I get around this is to start virt-manager as root and create a new VM in that pool. Choosing to create a custom .qcow2 disk image in that pool leads to a message saying the following:
The emulator may not have search permissions for the path '/run/media/user/VMs/new/linux2020-3.qcow2'. Do you want to correct this now?

Selecting yes on this popup fixes the permissions and I close the root instance of virt-manager, then relaunch as my user and am able to start VMs in that pool with no issues. I figured that the error was something to do with the fact that the mounting was done by the distro instead of me manually inputting an entry to fstab with some specific options.

1 Like

Okay, cool, so from the start, yeah, I’d add the other drive to fstab, with a more permenant location.
I just use /home/trooper_ish/VMStores/

The permissions might (or might not) be to do with the way the drive was mounted, and it’s file permissions.
If the drive is NTFS, for example, it might not have the permissions metadata the linux file systems have.

So to start off, check the details of the partiton you are gonna add, then add it to fstab, for example:

$ lsblk -o Name,UUID,MountPoint,FSType | grep VMs

should give

/dev/sdb2    2374832743-234    /run/media/user/VMs  NTFS

To get the info,
then copy all that the useful bits to fstab (sudo /etc/fstab), with options and passes after.
I would suggest using UUID instead of “name”

UUID=2374832743-234 /home/grando/VMs NTFS nofail,errors=remounr-ro 0 0

more info

[the UUID is the unique identifier of the partition, and does not change if the drive is re-ordered/ removed. the mountpoint can be whatever folder you like. the NTFS is whatever format/ partition type holding the data. the nofail (I just moved forwards) is so if the drive is not there when booting, the system does not freak out and refuse to boot. the errors=remount-ro is if the drive plays up, it will load read only, if it can. the 0 and 0 after are to do with the system ordering, and might benefit from being 0 and 1, I can;t remember, but shouldn’t cause an issue]

and to test, I would

$ mkdir /home/grando/VMs
$ sudo umount /run/media/user/VMs
$ sudo mount -a

if it gives an error about the target location not being empty, then the mkdir was a problem (sorry) , rm/delete the folder, run mount -a again, then chown grando:grando /home/grando/VMs

Does that make sense so far?

1 Like

This did it. Works perfectly after creating the fstab entry and modifying the XML for the new path of the image files. Thanks a bunch!

1 Like

No worries.

If the VM starts fine, I personally would shutdown the computer, and make sure it starts back up all in the right place…

I have an abundance of trust, as you can see…

2 Likes

What distro are you using. Popos for example has a disks utility that is more straightforward with mounting drives and drive mount locations.

2 Likes

Manjaro KDE. I’m down with manually inputting fstab entries, I just wasn’t sure if I needed any specific options. The ones suggested by @Trooper_ish make sense and I’m glad to know about them.

1 Like

Ensure to add uid and gid of user you want to have access to fstab. Should grant access to your user. uid=1000, Etc

1 Like

I forgot about the files app…

looking at it’s mount options, it really does have sane defaults… in Ubu anyway

1 Like

anyone else having issues with VLC and scrambled video?

local files/remote files… doesnt matter
audio always works, but video looks like below

v3.0.16

VLC is… not great with some video formats and/or codec options.

Have you tried mpv to see if it’s the same there? It’s usually a lot more reliable.

1 Like

its just mp4… and for the longest time vlc worked great even for yt videos

but since a couple months ago… its been doing this scramble crap

I mean, I’m sure you’re aware, but mp4 is not a codec. So it may or may not be that youtube changed something on their encoding side? I don’t know, I just stopped using VLC years ago when I ran into similar issues (although there’s more especially with HDR videos).