output
stringlengths 9
26.3k
| input
stringlengths 26
29.8k
| instruction
stringlengths 14
159
|
---|---|---|
The magic(5) manual page says only (referring to this as a datatype):
beid3 A 32-bit ID3 length in big-endian byte order. leid3 A 32-bit ID3 length in little-endian byte order.and libmagic's associating the ID3 tags with mp3 has been noticed, e.g., Discussion: libmagic for MP3 can go horribly wrong, since the feature was added in 2008:
2008-11-06 18:18 Christos Zoulas <[emailprotected]> * Handle ID3 format files.The ID3 format stores the tag length as a special 32-bit integer (which is the length you are asking about):
The ID3v2 tag size is stored as a 32 bit synchsafe integer (section
6.2), making a total of 28 effective bits (representing up to 256MB).
Further reading:Why are there Synchsafe Integer?
|
The man pages of the file command/libmagic are talking about a datatype called "ID3 length".
The only explanation i found was:
A 32-bit ID3 length
So what is this for a type ? Is it related to the ID3-Tag in mp3s ?
|
file/libmagic: What is the "ID3 length"?
|
Convert the number to hex (in this case A) and then do:
echo -en '\xA' > file
|
I would like to create a file that just contains a binary number. I think that touch can be used to create an empty file, but is there any way I can fill it with a binary number e.g. 10 (ten)? And how can I validate that the file contains the binary value of ten?
See also How can I check the Base64 value for an integer?
|
How can I create a file that just contains a binary number?
|
ls itself won't show this information.
You can pipe the output of the find to file -f -, as follows:
$ find /usr/local/bin | file -f -
/usr/local/bin: directory
/usr/local/bin/apt: Python script, ASCII text executable
/usr/local/bin/mint-md5sum: ASCII text
/usr/local/bin/search: Bourne-Again shell script, ASCII text executable
/usr/local/bin/gnome-help: Python script, ASCII text executable
/usr/local/bin/office-vb.sh: ASCII text
/usr/local/bin/pastebin: Python script, ASCII text executable
/usr/local/bin/highlight: POSIX shell script, ASCII text executable
/usr/local/bin/yelp: Python script, ASCII text executableNote that find is used instead of ls as it will print the full path, whereas ls will only print the file name. Therefore, if you simply need to do this with the files in your current directory, then:
ls | file -f -would work.
|
I have been trying to list files in directory using ls and passing it different options.
Does it have the ability to list types of files as well ? I want to know which ones are executable , sharedlibs or just ascii files without doing file command on individual files.
|
How to list files on terminal so that we can see the file types such executable, ascii etc?
|
Read man file and use file -l.
file inspect the first few bytes of a file to determine the "type". Note that Unix/Linux filenames treat "extensions" as just part of the filename. The use of the ".ext" extensions are just tradition, not a requirement.
|
The file -b <path> command seems useful for scripting (filtering file types, not necessarily by extension). But for that you have to know the actual string output for your target filetype(s)
If I want to match certain file types, but don't have all of them handy, is there a list of all the possible outputs?
I found docs for the magic file - using cat /usr/share/misc/magic.mgc | grep -a 'pattern' sort of works, but it's awkward and you have to know exactly what you're looking for.
is there any documentation of the recognized file types somewhere?
Thanks!
|
List of all file command outputs?
|
Take a look at the man page for the file command:$ man file
...
file tests each argument in an attempt to classify it.
There are three sets of tests, performed in this order: filesystem
tests, magic tests, and language tests. The first test that succeeds
causes the file type to be printed.It's the third test (language tests) that file performs that's categorizing this file as a C++ file.Once file has determined the character set used in a text-type file,
it will attempt to determine in what language the file is written.
The language tests look for particular strings (cf. #include
) that can appear anywhere in the first few blocks of a file. For example, the keyword .br indicates that the file is most likely a
troff(1) input file, just as the keyword struct indicates a C program.
These tests are less reliable than the previous two groups, so they are performed last. The language test routines also test for some
miscellany (such as tar(1) archives).C# files most closely match to C++ files and so file "guesses" that the .cs file is a C++ file.
Example
$ more blah.cs
// A Hello World! program in C#.
using System;
namespace HelloWorld
{
class Hello
{
static void Main()
{
Console.WriteLine("Hello World!"); // Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}Checking with file:
$ file blah.cs
blah.cs: ASCII C++ program text
|
I used the file command on a c# source file, and linux thought it was a c++ file. What is the reason for this?
|
Why does linux recognise a C# .cs file as a C++ source file?
|
Folder /usr/share/mime/magic has a database/table that will give me what are the current possible file formats (outputs that I can get when I type "file" command and follow it by a file).Correct except that /usr/share/mime/magic is not the directory that file uses: this file is only used for the MIME type database.
From file's manpage: "The information identifying these files is read rom the compiled magic file /usr/share/file/misc/magic.mgc, or the files in the directory /usr/share/file/misc/magic if the compiled file does not exist."
And in fact, in my Arch Linux system, that file belongs to the file package.Whenever "file" command output contains the word "text" it refers to something that you can read with a text viewer, and anything without "text" is some kind of binary.Looks correct (I tried to find a counterexample but was unable to).
|
Please let me know if below two statements are correct or not:
Folder /usr/share/mime/magic has a database/table that will give me what are the current possible file formats (outputs that I can get when I type the file command and follow it by a file name).
Whenever the file command output contains the word "text" it refers to something that you can read with a text viewer, and anything without "text" is some kind of binary.
|
File command database and identifying text files
|
Instead of
attachmenttype='file $attachment | cut -d\ -f2'you should write :
attachmenttype=$(file "$attachment" | cut -d' ' -f2)See http://wiki.bash-hackers.org/syntax/expansion/cmdsubstor to get mime-type :
$ file -i "$attachmenttype" | cut -d' ' -f2
text/plain;and decide what you want to do with the file depends of the type.
|
I am trying to make a check to see if the file being attached to the email is a text file, and if it is not it returns an error. However during testing, I provide a valid text.txt and it returns the "Invalid Attachment" message.
send_email()
{
message=
address=
attachment=
validuser=1
echo "Enter the email address: "
read address
echo ""
getent passwd | grep -q $address
if [ "$?" = "0" ]
then
echo -n "Enter the subject of the message: "
read message
echo "" echo "Enter the file you want to attach: "
read attachment
attachmenttype='file $attachment | cut -d\ -f2'
if [ $attachmenttype = "ASCII" ]
then
mail -s "$message" "$address"<"$attachment"
press_enter
elif [ $attachmenttype = "cannot" ]
then
mail -s "$message" "$address"<"$attachment"
press_enter
else
echo "Invalid attachment"
press_enter
fi
else
echo "Invalid username"
press_enter
fi}
|
Check if a file is a text file in bash
|
Those are fairly new features, documented in magic(5):use
Recursively call the named magic starting from the
current offset. If the name of the referenced
begins with a ^ then the endianness of the magic is
switched; if the magic mentioned leshort for example, it is treated as beshort and vice versa. This
is useful to avoid duplicating the rules for different endianness.
clear
This test is always true and clears the match flag
for that continuation level. It is intended to be
used with the default test.By "fairly new":
2014-11-27 18:40 Christos Zoulas
* Allow setting more parameters from the command line.
* Split name/use and indirect magic recursion limits.2013-04-22 11:20 Christos Zoulas
* The way "default" was implemented was not very useful
because the "if something was printed at that level"
was not easily controlled by the user, and the format
was bound to a string which is too restrictive. Add
a "clear" for that level keyword and make "default"
void. This way one can do: >>13 clear x
>>13 lelong 1 foo
>>13 lelong 2 bar
>>13 default x
>>>13 lelong x unknown %x
|
I am currently writing a parser for the libmagic database (used by the file command) and i don't found any information on the 'use' and 'clear' type (second column in the magic file).
Can someone explain to me what this types should do ?
|
libmagic (file) database "use" and "clear" type
|
Thanks to link provided by @Patrick I understood that file has nothing to do with shared-mime-info and its database is in /usr/share/misc/magic.mgc. So I googled for a ~/.magic file with a fix and found it here. The lines there are lacking spaces so I adduce it here
4 byte 0x47
>5 beshort 0x4000
>>7 byte ^0xF
>>>196 byte 0x47
>>>>388 byte 0x47
>>>>>580 byte 0x47 M2TS MPEG transport stream, v2
!:mime video/MP2T
|
I need to define mime type of various video files and I got a problem with .m2ts files. Before I stumbled on this, I used file utility with -iL keys and parsed the output with sed. Today I found that file 5.15 defines mime type of .m2ts files as ‘application/octet-stream’. O-okay, I updated the package and now it calls them just ‘binary’. When I expected video/something.
Reading about utilities doing similar job, I’ve tried xdg-mime query filetype. The problem with xdg-mime is that it looks only at the extension of the file. It defines .m2ts as ‘video/mp2t’, but shows it for any, even an empty text file with such extension.
Maybe it was correct to call .m2ts files a stream because it is actually a stream, but then why in the mime database the extension is bound to ‘video/mp2t’?
$ grep m2ts /usr/share/mime/video/mp2t.xml
<glob pattern="*.m2ts"/>
|
`file` doesn’t show proper mime-type for .m2ts files
|
You can use awk to search for files containing ASCII text:
less $(file * | awk -F: '$2 ~ "ASCII text" {print $1}')This actually works also for directories containing several text files.
|
So I have a directory where I wish to open the only file in that directory that is human readable. I use file * to print the type of each file, and one file shows as ASCII-text. How can I redirect that specific file to cat or less to display its content?
EDIT:
Y'all are awesome. I'm trying each.
|
How to open a file based on the output of the `file` command
|
The file utility determines the filetype over 3 ways:
First the filesystem tests: Within those tests one of the stat family system calls is invoked on the file. This returns the different unix file types: regular file, directory, link, character device, block device, named pipe or a socket. Depending on that, the magic tests are made.
The magic tests are a bit more complex. File types are guessed by a database of patterns called the magic file. Some file types can be determined by reading a bit or number in a particular place within the file (binaries for example). The magic file contains "magic numbers" to test the file whether it contains them or not and which text info should be printed. Those "magic numbers" can be 1-4Byte values, strings, dates or even regular expressions. With further tests additional information can be found. In case of an executable, additional information would be whether it's dynamically linked or not, stripped or not or the architecture. Sometimes multiple tests must pass before the file type can be truly identified. But anyway, it doesn't matter how many tests are performed, it's always just a good guess.
Here are the first 8 bytes in a file of some common filetypes which can help us to get a feeling of what these magic numbers can look like:
Hexadecimal ASCII
PNG 89 50 4E 47|0D 0A 1A 0A ‰PNG|....
JPG FF D8 FF E1|1D 16 45 78 ÿØÿá|..Ex
JPG FF D8 FF E0|00 10 4A 46 ÿØÿà|..JF
ZIP 50 4B 03 04|0A 00 00 00 PK..|....
PDF 25 50 44 46|2D 31 2E 35 %PDF|-1.5If the file type can't be found over magic tests, the file seems to be a text file and file looks for the encoding of the contents. The encoding is distinguished by the different ranges and sequences of bytes that constitute printable text in each set.
The line breaks are also investigated, depending on their HEX values:0A (\n) classifies a Un*x/Linux/BSD/OSX terminated file
0D 0A (\r\n) are file from Microsoft operating systems
0D (\r) would be Mac OS until version 9
15 (\025) would be IBMs AIXNow the language tests start. If it appears to be a text file, the file is searched for particular strings to find out which language it contains (C, Perl, Bash). Some script languages can also be identified over the hashbang (#!/bin/interpreter) in the first line of the script.
If nothing applies to the file, the file type can't be determined and file just prints "data".
So, you see there is no need for a suffix. A suffix anyway could confuse, if set wrong.
|
I would like to know how file types are known if filenames don't have suffixes.
For example, a file named myfile could be binary or text to start with, how does the system know if the file is binary or text?
|
How are file types known if not from file suffix?
|
There may be different mechanisms to handle these default settings. However, other answers tend to focus on complete desktop environments, each of them with its own mechanism. Yet, these are not always installed on a system (I use OpenBox a lot), and in this case, tools such as xdg-open may be used.
Quoting the Arch Wiki:xdg-open is a desktop-independent tool for configuring the default applications of a user. Many applications invoke the xdg-open command internally.At this moment, I am using Ubuntu (12.04) and xdg-open is available. However, when you use a complete desktop environment such as GNOME, xdg-open acts as a simple forwarder, and relays the file requests to your DE, which is then free to handle it as it wants (see other answers for GNOME and Nautilus, for instance).Inside a desktop environment (e.g. GNOME, KDE, or Xfce), xdg-open simply passes the arguments to that desktop environment's file-opener application (gvfs-open, kde-open, or exo-open, respectively), which means that the associations are left up to the desktop environment.... which brings you back to the other answers in that case. Still, since this is Unix & Linux, and not Ask Ubuntu:When no desktop environment is detected (for example when one runs a standalone window manager, e.g. Openbox), xdg-open will use its own configuration files.All in all:
|-- no desktop env. > handle directly.
User Request > xdg-open > --|
|-- desktop env. > pass information to the DE.If the first case, you'll need to configure xdg-open directly, using the xdg-mime command (which will also allow you to see which application is supposed to handle which file). In the second case...
|-- GNOME? > gvfs-open handles the request.
|
Info. from xdg-open > --|-- KDE? > kde-open handles the request.
|
|-- XFCE? > exo-open handles the request.... you'll need to configure the file-opener associated with your desktop environment. In some cases, configuration made through xdg-mime may be redirected to the proper configuration tool in your environment.
|
If a file tells the OS its file format, how does the OS choose which application to open it by default?
In Windows, is the association stored in the registry table?
How does Linux choose which application to open a file?
I used to use Nautilus a lot, but now I change to terminal. Is it true that in terminal, we always have to explicitly specify which application to open a file? Does the settings of which application to open a file of a certain format by default belong to the file manager (e.g. Nautilus), and it is not an issue when we are living in terminals?
|
How does Linux choose which application to open a file?
|
xdg-open .
xdg-open is part of the xdg-utils package, which is commonly installed by default in many distributions (including Ubuntu). It is designed to work for multiple desktop environments, calling the default handler for the file type in your desktop environment.
You can pass a directory, file, or URL, and it will open the proper program for that parameter. For example, on my KDE system:xdg-open . opens the current directory in the Dolphin file manager
xdg-open foo.txt opens foo.txt in emacsclient, which I've configured to be the default handler for .txt files
xdg-open http://www.google.com/ opens google.com in my default web browserThe application opens as a separate window, and you'll get a prompt back in your terminal and can issue other commands or close your terminal without affecting your new GUI window.
I usually get a bunch of error message printed to stderr, but I just ignore them.
Edit:
Adding the arguments xdg-open . >/dev/null 2>&1 redirects the errors and the output. This call won't block your terminal. Binding this to an alias like filemanager='xdg-open . >/dev/null 2>&1' can come in handy.
|
My current directory is buried deep in multiple subfolder layers from my home directory. If I want to open this directory in a gui-based file browser, I have to double click folder after folder to reach it. This is very time consuming. On the other hand, with very few key strokes and several times hitting the tab button, it is very easily reachable via a terminal.
I want to know if there is a way to open the current directory in a terminal onto a a file browser. What is the command to do this?
For reference, I have an ubuntu system, but I'd like to know what the commands are across the various distributions of linux.
|
Opening current directory from a terminal onto a file browser?
|
The primary purpose of OSX's open command is to open a file in the associated application. The equivalent of that on modern non-OSX unices is xdg-open.
xdg-open index.htmlxdg-open doesn't have an equivalent of OSX's open -a to open a file in specific application. That's because the normal way to open a file in an application is to simply type the name of the application followed by the name of the file. More precisely, you need to type the name of the executable program that implements the application.
sublime_text index.htmlLinux, like other Unix systems (but not, as far as I know, the non-Unixy parts of OSX) manages software by tracking it with a package manager, and puts individual files where they are used. For example, all executable programs are in a small set of directories and all those directories are listed in the PATH variable; running sublime_text looks up a file called sublime_text in the directories listed in PATH. OSX needs an extra level of indirection, through open -a, to handle applications which are unpacked in a single directory tree and registered in an application database. Linux doesn't have any application database, but it's organized in such a way that it doesn't need one.
If running the command sublime_text shell doesn't work for you, then Sublime Text hasn't been installed properly. I've never used it, and apparently it comes as a tar archive, not as a distribution package (e.g. deb or rpm), so it's possible that you need to do an extra installation step. It's really the job of the makers of Sublime Text to make this automatic, but if they haven't done it, you can probably do it yourself by running the command
sudo -s …/sublime_text /usr/local/binReplace … by the path where the sublime_text executable is, of course.
The open command you encountered is an older name for the openvt command (some Linux distributions only include it under the name openvt). The openvt command creates a new virtual console, which can only be done by root and isn't used very often in this century since most people only ever work in a graphical window environment.
|
Why can't I run this command in my terminal:
open index.htmlWasn't it supposed open this file on my browser? Also can't I run this command: open index.html -a "Sublime Text". The result of these commands are:
$ open index.html
Couldn't get a file descriptor referring to the console$ open index.html -a "Sublime Text" -
open: invalid option -- 'a'
Usage: open [OPTIONS] -- command
|
`open` command to open a file in an application
|
There isn't a command that I've ever seen that will act as "open with..." but you can use the command xdg-open <file> to open a given <file> in the application that's associated with that particular type of file.
Examples
Opening a text file:
$ xdg-open tstfile.txt
$Resulting in the file tstfile.txt being opened in gedit:Opening a LibreOffice Writer document:
$ xdg-open tstfile.odt
$Resulting in the file tstfile.odt being opened in Writer:What apps get used?
You can use xdg-mime to query the system to find out what applications are associated to a given file type.
$ xdg-mime query default $(xdg-mime query filetype tstfile.txt)
gedit.desktop calibre-ebook-viewer.desktop$ xdg-mime query default $(xdg-mime query filetype tstfile.odt)
libreoffice-writer.desktop calibre-ebook-viewer.desktopThis is a 2 step operation. First I'm querying for the mime-type of a given file, xdg-mime query filetype tstfile.txt, which will return text/plain. This is then used to perform another lookup to find out the list of applications that are associated with this mime-type. As you can see above I have 2 apps associated, gedit and calibre, for .txt files.
You can use xdg-mime to change the associations too. See man xdg-mime for more details.
|
Does the command line have a way to get a recommended list of programs used to open a particular file, based on the file type? For example, a .pdf file would have an open with... recommendation using the programs Evince and Document Viewer.
I use the command line for most things, but sometimes I forget the name of a program that I want to use to open a particular type of file.
BTW I am using Ubuntu 13.10.
pro-tip
Thanks to @slm 's selected answer below, I made the following bash script in a file called openwith.sh:
xdg-mime query default $(xdg-mime query filetype $1)Add as an alias or execute directly as an openwith command.
|
Is there an "open with" command for the command line?
|
Strange, it works like that out of the box on my Debian. Try running it in the background:
xdg-open http://www.google.com &You can make this into a function by adding these lines to your ~/.bashrc file:
function open () {
xdg-open "$*" &
}You can then simply run open http://www.google.com and it will run in the background.
|
I'm starting to experiment with Crunchbang (which is based on Debian, and uses terminator) as a web development environment, and one of the things I am struggling with is the behaviour of xdg-open. I come from an OSX background, so forgive me if this question comes off as dense.
I would like to be able to open a url with xdg-open http://www.google.com and then continue to use the same terminal window to work (it's how open functions in OSX). Right now, using xdg-open occupies the current tab/session until I close browser window, or manually end things with ctrl + c. I'd much prefer it start a new process, that way I can open up a URL, refer to data on the page, and use it in the same tab/window without needing to open an additional one.
|
Use xdg-open to open a url with a new process
|
A link to a “similar question” (xdg-open default applications behavior – not obviously related, but some experimentation showed that the behaviour is indeed equivalent to the one of xdg-open) led me deeper down the rabbit hole. While Firefox does not rely on, or inherit rules from, xdg-open, it uses the MIME specification files just as xdg-open does.
On a user basis, the MIME opening behaviour is configured by the specification file ~/.local/share/applications/mimeapps.list.
For me, this file contains just a few reasonable protocols and HTML (and similar) files connected to userapp-Firefox-??????.desktop, but you could easily add a line like
application/pdf=evince.desktopto solve that problem on a per-user basis. If the file does not exist yet, make sure to add a section header, such as
[Default Applications]
application/pdf=evince.desktopDeeper down, the mime types are defined in /usr/local/share/applications/mimeinfo.cache (this may be /usr/share/… if you are not on a FreeBSD system), which does list application/pdf=inkscape.desktop;evince.desktop;. Both evince.desktop and inkscape.desktop in that folder contain MimeType=[…]application/pdf;[…].
The mimeinfo.cache is automatically generated from the mime types listed in the .desktop files without any well-defined order, so you will have to either remove the PDF mime type from Inkscape and regenerate the cache using update-mime-database, or generate a mimeapps.list (either globally in /usr/local/share/applications/, or for your user in ~/.local/share/applications/mimeapps.list).
|
By default, the Firefox (33.0) on my FreeBSD 11.0-CURRENT has the default application for opening PDF files set to Inkscape. Firefox does remember my previous choice, evince, in the “What should Firefox do with this file?” dialog, so until recently I was just confused where this configuration came from, but mostly ignored it because it did barely concern me.
I have however recently started using Zotero as my literature database. Zotero runs as a firefox plugin, and ignores the choices made in my Firefox preferences to open PDF files with evince or ask me what to do with them, and just opens them using Inkscape. This made me try to follow up on this particular configuration item of Firefox, but I could not find where that default is set.
I could not find the string Inkscape (or inkscape) in any Firefox-related file in my home directory.
|
Where does firefox get the “default” applications for opening files from?
|
The GVFS documentation has a file about Controlling What is Shown in the User Interface. In short, you have two ways to do this:If it's in /etc/fstab, add x-gvfs-hide as one of the options (or, for older versions of udisks2, comment=gvfs-hide).
Configure udev to set the $ENV{UDISKS_IGNORE}="1" for the relevant device. For example, here is how I hide logical volumes on my system (which are all things I don't want to mount via the GUI):
ENV{DM_VG_NAME}=="Zia", ENV{UDISKS_IGNORE}="1"For a partition on a disk, reasonable things to match on would include $ENV{ID_WWN} or $ENV{ID_SERIAL} along with $ENV{ID_PART_ENTRY_NUMBER}. So, for example:
ENV{ID_WWN}=="0x5000c5001c33a889", ENV{ID_PART_ENTRY_NUMBER}=="1", ENV{UDISKS_IGNORE}="1"should match the first partition on one of my disks and set it ignored. ID_FS_UUID would be another possibility.If you're running udisks v. 1 (e.g, in Debian Wheezy), the udev environment variable to set is ENV{UDISKS_PRESENTATION_HIDE}="1". and it appears from Gilles' testing that the /etc/fstab method does not work reliably. Note that it's possible to be running both v. 1 and v. 2, in which case you'll have to set both.
|
When I open the Gtk file dialog, there is a box called “Places” on the left-hand side which lists “Search”, “Recently Used”, a bunch of directories, and several things that appear to be volumes. I don't care about any of these entries, but for the most part I don't mind, except for one.
One of the volumes is on an external hard disk that spends most of its time spun down. Opening the Gtk file dialog makes this disk wake up (presumably because the application reads the disk size or label and that information isn't in the cache). I want this to stop.etch200808 is the label of a mounted filesystem. I have two 500MB filesystems mounted, one of them is on the external disk that I don't want to spin up. I'm not sure what the 412 GB one is: I have no filesystem anywhere near this size; I do have an LVM physical volume that's the right size. I have no idea why these are displayed and not any other volume of various types on this system.
How can I force this volume (or all volume, or all directories) off the “Places” box? Note that this isn't just about not being listed, this is about the mount point not being accessed, so that my disk doesn't spin up just because I wanted to open or save a file from a Gtk application.
I'm running Debian wheezy, but I want to know the answer for other distributions and generations as well —if only because this machine will be upgraded to jessie soon.
|
Prevent the Gtk file dialog from listing mount points
|
KDE uses freedesktop.org's standard mimeapps.list files for associating MIME types (file types) to applications.The lookup order for this file is as follows:$XDG_CONFIG_HOME/$desktop-mimeapps.listuser overrides, desktop-specific (for advanced users)$XDG_CONFIG_HOME/mimeapps.listuser overrides (recommended location for user configuration GUIs)$XDG_CONFIG_DIRS/$desktop-mimeapps.listsysadmin and ISV overrides, desktop-specific$XDG_CONFIG_DIRS/mimeapps.listsysadmin and ISV overrides$XDG_DATA_HOME/applications/$desktop-mimeapps.listfor completeness, deprecated, desktop-specific$XDG_DATA_HOME/applications/mimeapps.listfor compatibility, deprecated$XDG_DATA_DIRS/applications/$desktop-mimeapps.listdistribution-provided defaults, desktop-specific$XDG_DATA_DIRS/applications/mimeapps.listdistribution-provided defaultsIn this table, $desktop is one of the names of the current desktop, lowercase (for instance, kde, gnome, xfce, etc.)
This is determined from taking the ascii-lowercase form of a component the environment variable $XDG_CURRENT_DESKTOP, which is a colon-separated list of names that the current desktop is known as.Note that:$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.
$XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used.These are plaintext, ini-style files that can be searched for a program of interest.
|
I had a program installed on my Kubuntu system that was able to open a lot of different graphics file types and registered as default program for many of those file types. I have unistalled the program, but in the file associations it is still present and every now and then as I try to open a file from the file manager, it tries to launch the no longer existing program.
I could remove that association for the most often used file types via the file associations dialogue in KDE's settings menu. Unfortunately, in this dialog I can only search for a file type and see/edit the associated programs, but in this case, I would need to search for the program and see all file types that it is associated to.
Is there a way to achieve this? If not via the settings, maybe in some config file, where I can just remove all hints to that program?
|
How to find/remove file associations for a certain program in KDE
|
Linux doesn't use file extensions to decide how to open a file, but Linux uses file extensions to decide how to open a file.
The problem here is that “Linux” can designate different parts of the operating system, and “opening a file” can mean different things too.
A difference between Linux and Windows is how they treat application files vs data files. On Windows, the line between the two is blurred; there are a few types of executable files, and they are determined by their extension (.exe, .bat, etc.), but in most contexts you can “execute” any file (e.g. by clicking in Explorer), and this executes the executable that is associated with that file type, where the file type is entirely determined by the extension (so executing a .doc file might start c:\Program Files\something or other\winword.exe, executing a .py file might start a Python interpreter, etc.).
On Linux, there is a notion of executable file which is independent of the file name. Executables generally have no extension, because they're meant to be typed by the user. The type of the file is irrelevant, all the user wants to do is execute the file. The kernel determines how to execute the file from the file contents: it knows some file types natively, and the shebang mechanism allows a file to declare any other executable file¹ as its interpreter.
On the other hand, data files usually do have an extension that indicates the type of data. The general idea here is that the type of data is not synonymous with what application to use to open the file with. You may want to view a PDF in Okular, or in Evince, or in Xpdf, or in Acroread, or in Mupdf, etc.
There are many tools that do however allow opening a data file without having to explicitly specify what application to use. These tools almost exclusively base their decision on the file extension. The file extension and the file's content are the only information that these tools have at their disposal: Linux does not store any meta information regarding the file format. So when you click on a .pdf file in a file manager (or when you run the .pdf file on a suitably-configured zsh command line, etc.), the file manager consults a database to find what application is the preferred one for .pdf file. This database may be structured in two sections, one that associates extensions to MIME types (/etc/mime.types, ~/.local/share/mime) and one that associates MIME types to applications (/etc/mailcap, ~/.local/share/applications), but even so the origin is the extension. While it would often be possible to figure out the application from the file content, this would be slower, and not always possible (many formats look just like text files, a .jar is a type of .zip, etc.).
Linux doesn't need file extensions, and it doesn't use them to determine how to run an executable file, but it does use them to determine which program to use to open a data file.
¹ That file has to be a native executable, a shebang executable can't point to another shebang executable to avoid potentially unending recursion.
|
I have a text file as- abc.text and it has its contents as Hi I'm a text file.
If I double click to open this file, then the files is opened in gedit editor.
Whereas, if I rename the file to abc.html (without changing any of its contents) then by default it opens in Chrome.
This sort of behavior is acceptable on a Windows machine, since Windows uses file extensions to identify file types. But as far as I've read, Linux doesn't need file extensions.
So why does changing file extensions in Linux changes the default program that opens it?
|
Why does linux use file extension to decide the default program for opening a file though it's independent of file extensions
|
A file manager is responsible for invoking applications to open a file. It has no control over what the application does with the file, and in particular whether the application will open a new window if you open the same file twice.
Having the same file open in multiple windows can be useful, for example when you want to see different sections from the same document. So systematically refusing to open more than one window on the same document would be bad. Which behavior is the default is mostly a matter of taste. Some applications default to opening a new window, others default to focusing the existing window.
Okular defaults to opening a new window. If you start all instances with okular --unique, then the second time you run that command, it doesn't open a new window (though it doesn't focus the existing window, at least if you aren't running KDE). Note that the first instance must have been started with --unique as well as the second one.
Evince, the Gnome PDF viewer, defaults to the behavior you want: if you open the same document a second time, it focuses the existing window. It doesn't have a command line option to open a separate window, you have to do this through the GUI (menu “File” → “Open a Copy” or Ctrl+N).
|
I have always been confused why the file manager in Linux cannot stop applications from opening a single file twice at the same time?
Specifically, I want to stop the PDF file reader Okular from opening the file A.pdf again when I have already opened it. I need to get an warning or just show me the opened copy of the file A.pdf.
More generally, I would like this to happen with any application, not just Okular. I want to make the document management behavior in Linux the same as in Windows.
|
If I open the same file twice in Okular, switch to the existing window
|
mimeopen -a 'picture.jpg'This is what you need
It will give you output like this
Please choose an application 1) Shotwell Viewer (shotwell-viewer)
2) Firefox Web Browser (firefox)
3) Image Viewer (eog)
|
Let's say I have a file thesis.pdf or picture.jpg
Is there a command which returns a program to open this file with?
I am aware of the command file, but it just returns the correct type of the file (I know that this is not specified by its extension in Linux) and not a program.
I am expecting something like:
$ program 'picture.jpg'
gimp, gwenview, eog
|
How to find out which program can open a given file?
|
xdg-open is the safest bet. Not everyone will necessarily have gnome or gvfs installed. xdg-open, on the other hand, is not tied to any desktop environment or toolkit.
|
I have a Java program that runs on Linux, and from within the program, I want to open files (e.g. PDF files) with the system's native viewer. There are various programs available for this purpose: gnome-open, gvfs-open, xdg-open, ...
Which one(s) should I use to cover as many Linux distributions as possible?
|
What program to use to open files? (gnome-open, gvfs-open, xdg-open, etc.)
|
First make .desktop application for lynx:
[Desktop Entry]
Type=Application
Name=Lynx
Exec=gnome-terminal -e 'lynx %u'And save it to application directory e.g /usr/share/applications/ naming like lynx.desktop and give it execution permission (chmod +x /usr/share/applications/lynx.desktop).
Then set it as default web browser by using:
xdg-settings set default-web-browser lynx.desktopNow try to Open link and it will be open with lynx in the terminal.
Note: lynx is command-line web-browser and hence it needs terminal so-that I've used gnome-terminal in my example Exec command. Your terminal application may be different. This works for me with my current system.
|
I'm on Linux Mint Olivia. I just installed Lynx.
How do I set Lynx as my browser, so when I open links from the terminal, they open in that terminal with Lynx?
|
Change default web browser to lynx from terminal
|
According to Freedesktop.org “Association between MIME types and applications” specifications, KDE should look at these locations:/usr/share/applications/mimeapps.list
/usr/share/applications/kde-mimeapps.list
$HOME/local/share/applications/mimeapps.list (deprecated)
$HOME/local/share/applications/kde-mimeapps.list (deprecated)
/etc/xdg/mimeapps.list
/etc/xdg/kde-mimeapps.list
$HOME/.config/mimeapps.list
$HOME/.config/kde-mimeapps.listKDE 5
KDE well read them. It also well edits $HOME/.config/mimeapps.list to save customizations from File Association configuration module (ComponentChooser) or file browser (Dolphin).
However, KDE does not stores its default associations to mimeapps.list, but seems to use directly MimeType keys from *.desktop files.
To choose the best one, it also uses InitialPreference keys, provided by the applications themselves (or their package maintainer). Since this is KDE-only feature, in most cases, it is only set for KDE applications.
Configuration from *.desktop files are compiled and cached to Sycoca.
MimeTypes which do not have any configuration get theirs from Shared MIME Info database.
Note that *.desktop files are stored inside:/usr/share/applications/
/usr/local/share/applications/
$HOME/.local/share/applications/KDE 6
Kde 6.0 should provide default applications in /etc/xdg/kde-mimeapps.list, deprecating InitialPreference system. So KDE will be consistent with other desktop environments.
|
With the 15.04 release of Kubuntu, I switched from Gnome (Ubuntu) to KDE/Plasma. I did a clean install, while keeping my home directory. Now, libreoffice (mostly Calc) seems to be associated with every unknown file-type. Instead of manually fixing the associations for every file I encounter, I'd rather understand what went wrong and fix it by looking at the corresponding config file that KDE/Plasma uses. Which config-file is it?
|
Which config-file stores file associations in KDE/Plasma?
|
There is already an external command for this. There is nothing new that needs to be written. The command is xdg-open. It will open a file based on its MIME type association. Here is an example:
xdg-open file.png
|
I have made a Java program that could open any application. Suppose there is a file name "*.jpg", the it would allow the OS to recognize the type of application and then open the default application. Another example: Suppose the file's name is "*.flv", then it would open up the default media player just like when you click an icon in nautilus but the only difference was that it was in command line. Here is the java program for that:
import java.awt.*;
import java.io.*;
public class OpenFile{
public static void main(String args[]){
try{
String filename = args[0];
System.out.println(args[0]);
Desktop.getDesktop().open(new File(filename));
}
catch(Exception e){
System.out.println("Sorry an exception occured. Could not perform the operation.");
}
}
}Now this script leads to performance issues. Now I want to write a BASH script to do this task ??
|
Open any kind of application with BASH
|
Here is my solution for playing all files in a directory and all subdirectories with mplayer2 and ranger in random order. It's is not exactly the answer to the question, but maybe you can expand it.
First I wrote a shell script called ptv:
#!/bin/shif [[ -z "$1" ]]; then
echo "usage: $(basename $0) directory [count]"
else
if [[ ! -z "$2" ]]; then
SHUFPARAM="-n$2"
fi
PLAYLIST="/tmp/playlist-$(whoami)"
CWD="$(realpath "$1")"
find "$CWD" -type f -iname \*.mkv -or -iname \*.mp4 -or -iname \*.avi | shuf $SHUFPARAM > $PLAYLIST && \
mplayer2 --playlist=$PLAYLIST && rm -f $PLAYLIST
fiThis script finds all my movie files in a given directory, creates a random ordered playlist and calls mplayer2 with this generated playlist. Leave the shuf command out, if you want a sorted list.
Next step is to edit rifle.conf in your settings directory (~/.config/ranger). Add this line:
directory, label pseudoTV, has mplayer2, flag f = /path/to/ptv "$@"Now you can use the script to open_with (mapped to key: r) with mplayer2. In mplayer2 you can navigate with < and > between the playlist items.
TIP: Copy your directories directories to the yank_buffer and save it in ranger. Then expand ptv to find files in all your selected directories...
|
I use the file explorer called ranger and I wonder if it is possible to open many files in different directory with mplayer?
What I can already do is to select all the files (pressing v) from one directory and then press Enter. Mplayer is launched and all the files in that directory are played one after the other.
But what if I want to play a list of files that are in different directories?
EDIT: To be more general, I'd like to know how to run a command that takes files from different directories as arguments.
|
ranger: open many files with mplayer
|
The viewer should be the same as that chosen when you use xdg-open or simply double click a pdf in a file manager. The default file associations are set in either /usr/share/applications/defaults.list (global) or one of ~/.local/share/applications/mimeapps.list or ~/.local/share/applications/defaults.list.
For example, this is what I have on my system:
$ grep -i pdf /usr/share/applications/defaults.list
application/pdf=evince.desktop;atril.desktopAssuming you have the corresponding .desktop file in the right location (/usr/share/applications/ for example), emacs should just find it and open with the right viewer.
|
I'm starting to use org-mode to export text to LaTeX.
My problem is that it opens the generated PDF with ebook-viewer (it is a EPUB, CHM reader) instead of using evince.
Question
Does anyone know how to change this behaviour and configure evince to be the default viewer?
|
Configuring Org-mode to open PDFs with evince
|
xdg-open is just a shell script that detects Desktop Environment and call the corresponding program (gvfs-open for gnome , exo-open for XFCE, mate-open, etc.)
So the limitations for launching an executable are derived from the corresponding launcher of each DE, which is gvfs-open in your case.
Looking at gvfs-open man page, this app (similar to the other DE apps) just calls the default application registered per file type as it is defined by gvfs-mime settings.
In your case , gvfs-open tries (and fails) to find a corresponding application to launch a firefox file.
If you run xdg-open (or gvfs-open) with an html link like https://www.google.com , then should work correctly; gvfs-open will search mime database to find how to handle the html link, mime will advise to call firefox, and firefox will be called.
Looking at xdg-open shell script functions, there are some functions that extract the Exec entry out of the corresponding .desktop file and under some Desktop Environments the command found in Exec section of .desktop file is just executed as it is by xdg-open.
In other words, you do not have to call xdg-open or gvfs-open to launch executables like firefox.
Just launch "firefox" and should be executed (i.e popen "/usr/bin/firefox")
PS: Or you might even need to call (exec firefox &)
You could even extract Exec entries by all .desktop files with a grep loop like this:
for file in $(find /usr/share/applications/ -type f -name '*.desktop'); do
executable=$(grep -m1 "^Exec=" "$file") #some files have more than one Exec entry
echo "$file - $executable"
done
|
I am trying to write a function launchSystemFile which works like windows ShellExecuteEx from the command line or from C++.
If I ShellExecuteEx a blah.txt it opens it in the default editor.
If I ShellExecuteEx a firefox.exe it launches the executable.
I have been doing from C++ popen "xdg-open blah" and it works great except for executables.
Is there anyway to make xdg-open execute an executable? Such as Firefox at path /usr/lib/firefox/firefox?
I tried xdg-open "/usr/lib/firefox/firefox" but this fails with the error message:gvfs-open: /usr/lib/firefox/firefox: error opening location: No application is registered as handling this file
|
Launch executable with xdg-open
|
Create a custom mime type e.g. text/x-twig (and - optionally - use a custom icon1 for that particular mime type) via a new source xml file:
~/.local/share/mime/packages/text-x-twig.xmlwith the following content:
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/x-twig">
<comment>twig files</comment>
<glob pattern="*.twig"/>
<icon name="text-x-twig"/>
</mime-type>
</mime-info>then update your mime database
update-mime-database ~/.local/share/mime1:Keep in mind that the "icon name" must match the actual icon name(s) sans extension from your icon theme; default location for mime type icons is /path/to/your/icon/theme/${SIZE}/mimetypes (where sizes are e.g. 16x16, 24x24 etc so for each size you should have a corresponding icon unless you opt to use a svg icon for all sizes)
|
I generally give Twig files a "twig" extension. As I understand it these Twig files are usually recognised as HTML like files by Linux using some sort of scan algorithm. So Nemo for example represents these files with a web icon and clicking on properties shows the file type as "Text (text/html)". However sometimes when there is no actual HTML near the top of the file Linux recognises the file as plain text instead. On such files I tried adding a HTML comment as the first line:
<!-- Twig file -->Which works OK for Twig macro files, but not for regular templates as it causes an error:
Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'A
template that extends another one cannot have a body in "std.twig" at line
1.' in /var/www/html/vendor/twig/twig/lib/Twig/Parser.php:379 Stack trace:
...I know that it is possible to put a "html" extension after the "twig" extension, so the full file name is for example:
foo.twig.htmlBut that is cumbersome.
So I was wondering if instead it is possible to give Linux (Mint in my case) a new file type, and perhaps have a different icon in Nemo from either the text or HTML icons?
|
Can I add the Twig file type to Linux?
|
The default text editor on a system is usually stored in the $EDITOR environmental variable. For example, on my system I have:
$ echo $EDITOR
/usr/bin/emacsSo, you can simply run
$ $EDITOR test.txtNOTE: This is not necessarily the same editor defined in the graphcial environment's settings. Use the method below to get that.
Alternatively, if the system is configured to use it, you can launch the default program associated with a mime type with xdg-open (open on OSX):
$ xdg-open test.txtBut that will not hold the terminal until the command closes. However, you can use the mime setup to find out what program would be opened and then call the program yourself. To do this, get the program associated with the text mime type:
$ xdg-mime query default text/plain
pluma.desktop;sublime_text.desktopSo, now you can parse that line to get the program name:
editor=$(xdg-mime query default text/plain | sed 's/\..*//')
$editor test.txtNOTE: This assumes that the .desktop file has the name of the actual executable. A safer way might be to locate the desktop file itself and grep the executable from it. Then, launch the program you found. You can do the whole thing with this command:
editor=$(grep -i ^exec $(locate -n 1 $(xdg-mime query default text/plain |
cut -d';' -f 1)) |
perl -pe 's/.*=(\S+).*/$1/')
$editor test.txt
|
I want to open a text file from the command line with the default application. During that time the default app is opened, the terminal must be disabled (cannot execute another command). For example, I use KDE and the default .txt reader is Kate, then I want to execute kate test.txt and the terminal is disabled until I terminate Kate.
What I want?execute a command that starts the default text editor
meanwhile the c++ program is waiting at that specific point which executes the command described above
when the user is ready, saves the document, exit the default text editor(terminates) and the the execution of the c++ program continues
|
Open file with default program and wait until the app is terminated [closed]
|
An easy way to establish file/url associations without messing around with the GUI, and that works on all Freedesktop.org compliant DE/DM/WM is using xdg-query.
With xdg-query you can, query what application is associated with a determined MIME/file/URL, change it, and install new ones. Since you want to change your associations the most effective method is:Discover which is the MIME type your file is known of. This can be done with xdg-mime query filetype FILE for files. URL's don't need this. Lets say text/html.
Check the application that is associated with:
xdg-mime query default text/html
userapp-Iceweasel-41IAMX.desktopNow to change it. You need to know the name of the .desktop file you want to associate the file with (and probably install it if it doesn't exist). The .desktop files are normally found in /usr/share/applications/, so you must make sure the desired .desktop file exist (locate .desktop | grep app may help). I will change mine to emacs:
xdg-mime default emacs.desktop text/htmlNow, checking:
xdg-mime query default text/html
emacs.desktopNow, I have changed my default application for all files that match the text/html mimetype.
This would work with any application that follows Freedesktop.org MIME Applications Associations standard, which is almost all the populars ones.
|
I have installed several Desktop Managers and Window Managers, and changing the file association can become a mess. I need some foolproof method which can allow me to change my user or system file association without having to swim through the GUI, and fine control over what gets associated with what. Is such method available?
|
How to change my file/url association across all my DM/WM without using the GUI?
|
Found a solution on emacs wiki that will enhance ffap to pick the line number too and go to that file number after finding the file.
;
; have ffap pick up line number and goto-line
; found on emacswiki : https://www.emacswiki.org/emacs/FindFileAtPoint#h5o-6
; (defvar ffap-file-at-point-line-number nil
"Variable to hold line number from the last `ffap-file-at-point' call.")(defadvice ffap-file-at-point (after ffap-store-line-number activate)
"Search `ffap-string-at-point' for a line number pattern and
save it in `ffap-file-at-point-line-number' variable."
(let* ((string (ffap-string-at-point)) ;; string/name definition copied from `ffap-string-at-point'
(name
(or (condition-case nil
(and (not (string-match "//" string)) ; foo.com://bar
(substitute-in-file-name string))
(error nil))
string))
(line-number-string
(and (string-match ":[0-9]+" name)
(substring name (1+ (match-beginning 0)) (match-end 0))))
(line-number
(and line-number-string
(string-to-number line-number-string))))
(if (and line-number (> line-number 0))
(setq ffap-file-at-point-line-number line-number)
(setq ffap-file-at-point-line-number nil))))(defadvice find-file-at-point (after ffap-goto-line-number activate)
"If `ffap-file-at-point-line-number' is non-nil goto this line."
(when ffap-file-at-point-line-number
(goto-line ffap-file-at-point-line-number)
(setq ffap-file-at-point-line-number nil)))
|
emacs can be run from the command line to open a file at line n with a +n command line argument like so :
$ emacs +n fileI'd like to do the same from a running emacs instance, either via find-file or other means. Is that possible ?
|
How do I open a file at specific line in a running emacs?
|
I found the records:
mimeopen when no desktop environment is specified saves the records in:
$HOME/.local/share/applications/defaults.list
|
I associated pdf with Okular using mimeopen. Then I became curious where it had saved the configuration. My first guess was:
$HOME/.config/mimeapps.list
but it didn't contain the right entry. So I searched:
updatedb && locate mime | xargs egrep -e "okular" 2> /dev/nulland found nothing. So which file is used mimeopen to save associations?
update
I started digging, following a clue from cas's comment, and I found a file:
$HOME/.local/share/okular-usercreated-1.desktop.
with the content:
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Name=okular
NoDisplay=true
Exec=okularWhich strangely does not have a MimeType record
My guess:
Since I use openbox, which doesn't set $DE environmental variable mimeopen had been forced to create a new .desktop file when I used it. Which is inconvenient.
I read it is possible to run openbox inside other desktop environments. I will give it a try.
|
Where mimeopen saves default app config?
|
You might be thinking of xdg-open:xdg-open opens a file or URL in the user's preferred application. If a URL is provided the URL will be opened in the user's preferred web browser. If a file is provided the file will be opened in the preferred application for files of that type. xdg-open supports file, ftp, http and https URLs. The Arch Wiki lists some alternative tools.
|
For example , there are two files a.ppt and b.jpg .
And I can call a magic method to open them appropriately just like :
magic_method a.ppt
magic_method b.jpgAnd it open libreoffice writer and image viewer or something that fit the file type .
Is there any command or script for that?
|
Is there any way to detect file type and open it with GUI in terminal in Fedora? [duplicate]
|
If you click on the location bar or press Ctrl-L it will become editable. In Dolphin you can also press F6. This is on KDE 4.14, but as far as I remember it worked in the earlier versions too.
|
I want to copy the file path from a file open dialog, but can't because of breadcrumb-style navigation. There's no option in the dialog itself to switch between breadcrumb and address bar.
I want to disable the breadcrumbs system wide so that the file browser, open dialogs, etc., all use the address bar.
This is KDE on Red Hat.
|
Disable breadcrumb navigation in KDE
|
For desktop environments that implement the freedesktop.org xdg-utils tools, you should be able to use xdg-open:Name
xdg-open — opens a file or URL in the user's preferred application
Synopsis
xdg-open { file | URL }
xdg-open { --help | --manual | --version } Description
xdg-open opens a file or URL in the user's preferred application. If a
URL is provided the URL will be opened in the user's preferred web
browser. If a file is provided the file will be opened in the
preferred application for files of that type. xdg-open supports file,
ftp, http and https URLs.
xdg-open is for use inside a desktop session only. It is not
recommended to use xdg-open as root.
Options
--help
Show command synopsis.
--manual
Show this manual page.
--version
Show the xdg-utils version information.
|
Almost every desktop environment has a mechanism for determining what to do when you (double)-click a file in file manager/explorer windows. This can be based on the extension, or on whatever file does, etc.
Now, suppose I have a terminal window open within a desktop session and I'm at some folder. Is there some binary or script - hopefully valid across multiple desktop environments common to Linux - which, when executed with a filename as its argument, uses this mechanism and has the same effect as (double)-clicking that file would?
If there isn't a single multi-desktop-environment way to do this - are there a bunch of desktop-environment-specific binaries/scripts with this functionality? If so, can you list such a bunch?
On Windows I think this exists in the form of the start command (although, of course, they can assume a single desktop environment.)
|
Canonical way to simulate a file manager "open item" from the command line
|
Nothing will work for any application. Not even inside the same graphic environment. Take for example Gnome. If you were to change that value via dconf-editor you'd find that for evince you need to set:
org.gnome.Evince document-directorybut for gnome-screenshot you need to set:
org.gnome.gnome-screenshot auto-save-directoryin libreoffice you'd have to set a preference:
Menu/Tools/Options/LIbreoffice/Paths/MyDocumentsand so on ...
If you always get the same Open File dialog among the applications you are interested in, you might be able to create a shortcut inside it and add it to the navigation bar.
|
Description
I'd like to point a folder so any application will start its "File Open Dialog" in it. How can I do that?
Rationale
I'm naturally using many applications while working on a project, like FreeCAD, LibreCAD, VLC, SimpleScan, etc. It's frustrating to navigate to my work folder for every single one of those applications. If I could set such a path, any application will start that dialog within my work folder, so I can easily handle my files.
|
How to set Open File Dialog path explicitly?
|
Everything under /proc is covered in the man proc. This section covers anon_inode.For file descriptors for pipes and sockets, the entries will be symbolic links whose content is the file type with the inode. A readlink(2) call on this file
returns a string in the format:
type:[inode]For example, socket:[2248868] will be a socket and its inode is 2248868. For sockets, that inode can be used to find more information in one of the files under
/proc/net/.
For file descriptors that have no corresponding inode (e.g., file descriptors produced by epoll_create(2), eventfd(2), inotify_init(2), signalfd(2), and
timerfd(2)), the entry will be a symbolic link with contents of the form
anon_inode:<file-type>In some cases, the file-type is surrounded by square brackets.
For example, an epoll file descriptor will have a symbolic link whose content is the string anon_inode:[eventpoll].For more on epoll I discuss them here - What information can I find out about an eventpoll on a running thread?.
For additional information on anon_inode's - What is an anonymous inode in Linux?. Basically there is/was data on disk that no longer has a filesystem reference to access it. An anon_inode shows that there's a file descriptor which has no referencing inode.
|
While looking through /proc/[PID]/fd/ folder of various processes, I found curious entry for dbus
lrwx------ 1 root root 64 Aug 20 05:46 4 -> anon_inode:[eventpoll]Hence the question, what are anon_inodes ? Are these similar to anonymous pipes ?
|
What is anon_inode in the output of "ls -l /proc/[PID]/fd"?
|
You can use mimeopen with -d option:
man mimeopen :
DESCRIPTION
This script tries to determine the mimetype of a file and open it with
the default desktop application. If no default application is
configured the user is prompted with an "open with" menu in the
terminal.-d, --ask-default
Let the user choose a new default program for given files.Example:
mimeopen -d file.mp4sample output:
Please choose a default application for files of type video/mp4 1) VLC media player (vlc)
2) Other...Verify it:
xdg-open file.mp4
|
I have 150 Debian Jessie machines that open ODS files in Gnumeric when double-clicked despite LibreOffice Calc being installed. I know it is possible to change this by right-clicking the ODS file and changing its default program from the Properties window, but getting 150 users to do this is not an option. They all use xfce4 and thunar.
I need to do this via CLI so I can do it across all workstations remotely. I have looked in /usr/share/applications and ~/.local/share/application/mimetypes.list with no luck - comparing the files before and after changing it via GUI revealed no changes here.
How can I use bash to make these workstations open ODS files with LibreOffice Calc by default?
EDIT: Unlike the answers to this question, my Jessie installs do not have ~/.config/mimeapps.list or /usr/share/applications/defaults.list
|
Setting default application for filetypes via CLI?
|
One approach would be to make use of ls to give us a list of the files, but we want this list to be guaranteed to show only 1 file or directory per line. The -1 switch will do this for us.
$ ls -1
dir1
dir2
dir3
fileA
fileB
fileCExample
Create the above sample data in an empty directory.
$ mkdir dir{1..3}
$ touch file{A..C}Check it:
$ ls
dir1 dir2 dir3 fileA fileB fileCNow to count you can use wc -l to count the number of lines, which correspond to a file or directory in the ls -1 output.
$ ls -1 | wc -l
6(note however that it doesn't include the hidden files)
Counting files or directories, just not together
To count either files or directories you need to change your tactic slightly. In this case I'd use ls -l since it shows what's a directory and what's a a file.
Example
$ ls -l
total 12
drwxrwxr-x 2 saml saml 4096 Nov 16 09:48 dir1
drwxrwxr-x 2 saml saml 4096 Nov 16 09:48 dir2
drwxrwxr-x 2 saml saml 4096 Nov 16 09:48 dir3
-rw-rw-r-- 1 saml saml 0 Nov 16 09:49 fileA
-rw-rw-r-- 1 saml saml 0 Nov 16 09:49 fileB
-rw-rw-r-- 1 saml saml 0 Nov 16 09:49 fileCThen we can use grep to filter out directories or not-directories like so:
# directories
$ ls -l | grep "^d"
drwxrwxr-x 2 saml saml 4096 Nov 16 09:48 dir1
drwxrwxr-x 2 saml saml 4096 Nov 16 09:48 dir2
drwxrwxr-x 2 saml saml 4096 Nov 16 09:48 dir3# regular files
$ ls -l | grep "^-"
-rw-rw-r-- 1 saml saml 0 Nov 16 09:49 fileA
-rw-rw-r-- 1 saml saml 0 Nov 16 09:49 fileB
-rw-rw-r-- 1 saml saml 0 Nov 16 09:49 fileCNow just use wc -l again to count the above:
# directories
$ ls -l | grep "^d" | wc -l
3# regular files
$ ls -l | grep "^-" | wc -l
3Though, you can avoid wc altogether, and use grep's -c option:
$ ls -l | grep -c '^d'(again, hidden files are not included. Note that directories and regular are two types of files. There are many more like named pipes, symbolic links, devices, sockets...).
Recursion
If you need to find the files and directories recursively under /usr/bin then you'll likely want to change tactics entirely and make use of another tool called find.
Example
$ find /usr/bin | wc -l
4632(though above /usr/bin itself is included in the count)
The same techniques I used above could be employed use ls to do something similar but ls is generally not a good tool to parse the output. find on the other hand was built for this, and offers switches to find either files or directories.
# find files
$ find /usr/bin -type f# find directories
$ find /usr/bin -type d(note that this time, find is including hidden files (except . and ..)).
newlines?
I've never figured out why a newline character is a legal character to use when creating file names or directory names. So the methods discussed above using wc and ls would not contend with these, so use them with that in mind.
Example
Create a directory & file name with newlines.
$ mkdir $'dir4\n5'
$ touch $'fileD\nE'ls shows them correctly:
$ ls -1
dir1
dir2
dir3
dir4?5
fileA
fileB
fileC
fileD?EBut wc counts the directories and files that contain newlines as 2 items, not one.
$ ls -1 | wc -l
10One method to get around this, if using the GNU implementation of find is to make use of find's ability to print something else in place of each file that it finds and then count those instead.
Example
$ find . -printf . | wc -c
9Here we're finding everything in the current directory (except ..), and printing a dot (.) for each, and then counting the dots using wc's ability to count bytes instead of lines, wc -c.
Referencesbash - What is the best way to count find-results?
|
How can I use word counter (wc) and piping to count how many files or directories are in the /usr/bin directory?
|
How to use wc and piping to find how many files and directories are in a certain directory?
|
Your file is full of nulls, rather than empty. A regular cat will print the nulls to standard output, but your terminal will generally display them each as nothing, while cat -v represents them as ^@. ^@ represents a null byte because the byte value of "@" (0x40, or 64) xor 64 (flip bit 7) is zero.
Why it's suddenly full of nulls, we can't tell from here.
This related question may be informative about the caret representation: Are ASCII escape sequences and control characters pairings part of a standard?
|
My team is working on a CI environment.
A ko file, named x.ko, is always generated from the CI environment at a regular time everyday and its type is ELF 64-bit LSB relocatable.
Today, I found that the type of this ko file became data.
I'm trying to figure out the reason.
I try to cat this ko file but the output is nothing. Then, I try to cat -et x.ko, and it gives me lots of ^@^@^@^@^@^@^@^@^@^@^@^@^@^@...
Do you know what ^@^@^@^@^@^@^@^@^@ means?
|
cat shows nothing
|
In Unix a file is just a sequence of bytes, however some files have more structure. The file command can look at the sequence of bytes and tell you things.for example if the first 4bytes are \177 E L F then it will tell you it is an elf file. It will then look at more bytes and tell you if it is a core file, an executable or an object file. If the bytes 6 thru 9 are JFIF then it is a picture file and again the program can read more and tell you about it.
A lot of this is driven by data tables rather than being compiled into the program. These data tables are what is in the magic files.
So the reason why you have magic files is to allow you to say file * and get the program to tell you what you have in the current directory.
|
We can create magic files with file -C -m filename. Also there is the /usr/share/file/magic folder with a list of magic files on my OS X machine.
But what is this? Would somebody explain, why should we have magic files? How should we create a magic file?
I read the man pages (man file and man magic), but it is still not clear.
|
Explain please what is a magic file in unix [closed]
|
This is just a question of permissions. If a file has execute permissions, that just means users are allowed to execute it. Whether they will be successful is another matter. In order for a file to be executed, the user executing it must have the right to do so and the file needs to be a valid executable. The permissions shown by ls only affect the first part, permission, and have no bearing on the rest.
For instance:
$ cat file.csv
a,silly,file
$ chmod a+x file.csv
$ ls -l file.csv
-rwxr-xr-x 1 terdon terdon 13 May 29 15:22 file.csvThis file now has execute permissions (see the 3 x in the permissions string -rwxr-xr-x). But if I try to execute it, I will get an error:
$ ./file.csv
./file.csv: line 1: a,silly,file: command not foundThat is because the shell is trying to execute the file as a shell script, and there are no valid shell commands in it, so it fails.
|
I have a number of files showing up green when I run ls. I understand these are executables, and I understand that one can make a file executable with chmod. But they are .csv and .pdf files. I don't understand how one could 'execute' a comma-separated text file or a PDF. So:How can they actually be 'executable'?
And how would I execute them?
And what would happen when I did?
|
Executable common files (*.pdf, etc.)
|
Given that your start-stop-daemon is 4GB in size and dated Dec 31, 1969, I suspect your filesystem may be corrupted...
sudo touch /forcefsckand then reboot to check your filesystem.
The question mark in ls's output here comes from the filetype_letter array (in GNU ls):
/* Display letters and indicators for each filetype.
Keep these in sync with enum filetype. */
static char const filetype_letter[] = "?pcdb-lswd";This corresponds to C_ORPHAN:
#define FILETYPE_INDICATORS \
{ \
C_ORPHAN, C_FIFO, C_CHR, C_DIR, C_BLK, C_FILE, \
C_LINK, C_SOCK, C_FILE, C_DIR \
}and unknown in the filetype enum, and is the default for a file of unknown type:
/* Classify a file of some other type as C_ORPHAN. */
type = C_ORPHAN;(ls implementations are free to add their own characters to those defined by POSIX.)
|
In general, what are the reasons why a filetype might show as unknown (?) in ls output?
See the first bit for the file /sbin/start-stop-daemon, which should indicate - for "regular file", instead is displayed as ? for "unknown".
ts7500:~# ls -alh /sbin/s*
-rwxr-xr-x 1 root root 52K Apr 29 2008 /sbin/sfdisk
-rwxr-xr-x 1 root root 875 Dec 6 2009 /sbin/shadowconfig
-rwxr-xr-x 1 root root 12K Apr 19 2010 /sbin/showmount
-rwxr-xr-x 1 root root 18K Aug 12 2008 /sbin/shutdown
-rwxr-xr-x 1 root root 28K Nov 16 2008 /sbin/slattach
-rwxr-xr-x 1 root root 12K Apr 19 2010 /sbin/sm-notify
-rwxr-xr-x 1 root root 58K Jul 27 2008 /sbin/ss
?rwsrwsrwt 1 65535 root 4.0G Dec 31 1969 /sbin/start-stop-daemon
-rwxr-xr-x 1 root root 19K Aug 12 2008 /sbin/startpar
-rwxr-xr-x 1 root root 9.8K Aug 12 2008 /sbin/sulogin
lrwxrwxrwx 1 root root 6 Jun 9 2011 /sbin/swapoff -> swapon
-rwxr-xr-x 1 root root 17K Apr 29 2008 /sbin/swapon
-rwxr-xr-x 1 root root 11K Aug 6 2009 /sbin/sysctl
|
Unknown Filetype in ls
|
The filetypes reported by ls depends on the capabilities of the underlying filesystem, the operating system, and on the specific implementation of ls.
The l type is the common symbolic link file type.
This is (ought to be) documented in your ls manual.
On OpenBSD (macOS and AIX has the same list, but in another order):
- regular file
b block special file
c character special file
d directory
l symbolic link
p FIFO
s socket linkOn NetBSD (FreeBSD has the same without a and A):
- Regular file.
a Archive state 1.
A Archive state 2.
b Block special file.
c Character special file.
d Directory.
l Symbolic link.
p FIFO.
s Socket link.
w Whiteout.From info ls (i.e. the GNU ls manual):
‘-’
regular file
‘b’
block special file
‘c’
character special file
‘C’
high performance (“contiguous data”) file
‘d’
directory
‘D’
door (Solaris 2.5 and up)
‘l’
symbolic link
‘M’
off-line (“migrated”) file (Cray DMF)
‘n’
network special file (HP-UX)
‘p’
FIFO (named pipe)
‘P’
port (Solaris 10 and up)
‘s’
socket
‘?’
some other file typeOn Solaris 11:
d
The entry is a directory.D
The entry is a door.l
The entry is a symbolic link.b
The entry is a block special file.c
The entry is a character special file.p
The entry is a FIFO (or “named pipe”) special file.P
The entry is an event port.s
The entry is an AF_UNIX address family socket.-
The entry is an ordinary file.
|
usually, the possible file types in the output ls -l command are d and -, which represent directory and regular file respectively.
besides above, I saw another type l in the output on macOS.
drwxr-xr-x 8 yongjia staff 256 Aug 31 06:58 .
drwxr-xr-x 4 yongjia staff 128 Aug 30 11:31 ..
lrwxr-xr-x 1 root wheel 1 Aug 17 07:25 Macintosh HD -> /So, How many possible file types in the output ls -l command?
|
How many possible file types in the output `ls -l` command?
|
PCManFM doesn’t use the same kind of magic file as file does, it uses shared-mime-info. That knows about Apple Keynote 5 files; it identifies them by their “PK” marker (common for all ZIP files), the presence of an index.apxl file inside that ZIP file, and their .key extensions.
file’s current magic library doesn’t know about Apple Keynote 5 files (it does know about Microsoft Office XML files).
To teach file about Keynote files, you can add your own magic entry using the information in the shared MIME database; alternatively, you can use mimetype, which uses that information to extract a file’s MIME type.
I think the best option is to file a bug asking for Keynote recognition in file.
|
I recently realized that file on Debian Bullseye won't recognize some of the file formats I'm dealing with, telling me they are just ZIP files:
user@host:~ $ file file.docx # Correct, not a regular ZIP file
file.docx: Microsoft Word 2007+user@host:~ $ file file.key # Incorrect, also not a regular ZIP file
file.key: Zip archive data, at least v2.0 to extractHowever, if I look at the files with pcmanfm, I see the file types are recognized correctly:
"file.docx" (50.5kB) Word 2007 document
"file.key" (10.4MB) Apple Keynote 5 presentationIs it possible to tell file to use the same magic file than pcmanfm uses, or somehow update the default /etc/magic to make file aware of popular document formats?
|
File types recognized in the GUI, but not on command line
|
Association between MIME types and applications defers to the Desktop Entry Specification, which states thatLines beginning with a # and blank lines are considered comments and will be ignored, however they should be preserved across reads and writes of the desktop entry file.
Comment lines are uninterpreted and may contain any character (except for LF). However, using UTF-8 for comment lines that contain characters not in ASCII is encouraged.
|
I want to add comments in my ~/.config/mimeapps.list file.
How do I do this?
Chapter and verse preferred as errors seem to be silently ignored.
|
Comments in ~/.config/mimeapps.list
|
Use sort | uniq -c to count identical lines:
find "$path" -type f -exec file -b {} + | sort | uniq -c | sort -nr
|
I would like to get a quick overview over the different file types in a directory (including all its subdirectories) using the file tool, e.g. telling me what file type is the most common one there.
It should be implemented as a practical shell script in common shell languages or scripting tools like bash or awk.
Possible nice-to-haves:good performance
dealing with any file name or type
POSIX compatibility(last two points are practically mutually exclusive)
|
Bash script to count file types in a path (including subfolders)
|
Generate the commands without running them.
Use mimetype to generate a list of command strings, which is
thereafter tweaked by GNU sed's substitute s command:
cd ~/messed/up/folder/ # go where the files are...
mimetype -M --output-format 'mv "%f" "%f%m"' *.JPG |
sed 's#\.[^./"]*/\([^./]*"\)$#\.\1#'If some of the file extensions look a little too mime-ish, (i.e.
.jpeg instead of .jpg, etc.), then add as many s commands as
needed between sed ' and s, for example:
sed 's/jpeg"$/jpg"/;s#\.[^./"]*/\([^./]*"\)$#\.\1#'Once the output looks good, run that with the GNU sed's
evaluate e option. (Just put an e before the final '.) So the whole thing might look like:
cd ~/messed/up/folder/ # go where the files are...
mimetype -M --output-format 'mv "%f" "%f%m"' *.JPG |
sed 's/jpeg"$/jpg"/;s#\.[^./"]*/\([^./]*"\)$#\.\1#e'
ls # show results
|
I have a folder with the bulk of files in it of different types, i.e .pdf,.jpg,.png,.tiff etc., but all are named with the extension .JPG. How can I rename all of them with their original extensions? i.e pdf to pdf, tiff to tiff and so on.
I can find the file type by:
file 99.jpg
99.jpg: PDF document, version 1.3Is there any script or program with which I can do this?
|
How to rename misnamed files with their appropriate extensions?
|
The file(1) manpage only tells you how to run the command. For a description of the magic patterns, see magic(5). However, the section on regex isn't especially detailed. A wide range of examples of its use can be found in the pattern files that come with it: https://github.com/file/file/tree/master/magic/Magdir
Your main problem was that the caret needs escaping: \^ for beginning-of-line, \\^ for a literal ^. I haven't worked out what special meaning the unescaped ^ has. Spaces can also be escaped, making the pattern slightly more readable.
You intend to restrict the match to a narrow line range. regex takes a /<length> option (after the word regex, not after the pattern), so that places a limit on where the search ends. If the length is followed by an l, it means lines instead of bytes. In my tests, /1l can only match an empty line -- a non-empty line, even when using the exact start offset, requires at least /2l.
For the start of the search, offset is interpreted as a byte count, even with regex. (Pre-version 5.19, the documentation suggests that it is interpreted as a "line count", but that statement was removed with no matching code change, so I doubt that it was accurate even before then.) You could use offset &0 to start the search from the end of the previous match, but that won't make a lot of difference when the previous match ended in the middle of the first line.
Furthermore, "beginning of line" also matches "beginning of search range" (ie. from offset), regardless of whether that was the start of a line in the file.
So to match things more strictly, you could use a full-line regexp on every line, and use offset &1 on the next match, to skip the previous newline, and be in the right place for the \^ to work as expected. This may be overkill for identifying your custom file types.
Finally, you don't need to repeat the common parts. The level of > indentation means that a pattern should be tried when previous patterns at the same level failed.
Joining that all together:
0 regex/2l \^Project\ Units:.*$
>&1 regex/2l \^Units\ &\ Scale.*$
>>&1 regex/1l \^$
>>>&1 regex/2l \^Object\ Point\ ID Photo Modeler 2D export table
>>>&1 regex/2l \^Id,Name,Photos Photo Modeler 3D export table
|
I am trying to have the file command detect some Windows text files that were never meant to be classified by file... The best choice seems to use regex to match the line content, but I cannot find a single example of its use (the commonality of the keywords 'file', 'magic', and 'regex' does not help in a google-centric world). The man page does not help.
Furthermore, I cannot get the ^ $ to work.
Both files start with
Project Units: <stuff>
Units & Scale - <stuff>
<blank line>Next line is a header that starts
4a) Object point ID,Photo #,
4b) Id,Name,
My attempt at a magic rules for this is:0 string Project\040Units:
>2 regex ^Object\040point\040ID,Photo\040#, PhotoModeler 2D export table0 string Project\040Units:
>2 regex ^Id,Name, PhotoModeler 3D export tablei.e. match 'Project Units:' on the first line, then do a regex attempt to maximum 2+1 lines. Anchor regex to beginning of line for speed.
This is on Ubuntu 14.04, file-5.14.
Example of file type 1 (first 10 lines only):Project Units: meters
Units & Scale - Active, Translate - Active, Rotate - ActiveObject Point ID,Photo #,X (pixels),Y (pixels),Residual X,Residual Y,Residual Vector,Mark Type,Layer,Material,Tagged
2,1,1429.187065,1456.427823,-0.164541,0.182824,0.245964,LSM Circular,Default,White,
2,2,666.583514,1126.807078,-0.168174,0.109780,0.200833,LSM Circular,Default,White,
2,3,716.264669,1196.788962,0.152059,0.082258,0.172882,LSM Circular,Default,White,
2,4,674.145595,442.969428,0.119315,-0.050084,0.129401,LSM Circular,Default,White,
2,5,330.056929,836.292587,0.048372,-0.022235,0.053238,LSM Circular,Default,White,
2,6,1147.101715,39.253316,0.475434,-0.189514,0.511814,LSM Circular,Default,White, Example of file type 2 (first 10 lines only):Project Units: meters
Units & Scale - Active, Translate - Active, Rotate - ActiveId,Name,Photos (used),X (project units),Y (project units),Z (project units),X Precision,Y Precision,Z Precision,Precision Vector Length,Tightness (percent),Tightness (project units),Angle (deg.),Control Name,RMS Residual (pixels),Largest Residual (pixels),Photo Largest Residual,Material,Layer,Tagged,Type,Use In Processing,Frozen,#Constraints,Target Code,Target Bits,Ref. Check Tag,Photos (marked),Color (R),Color (G),Color (B)
2," ","1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21",0.285721,1.143037,-0.000990,0.000044,0.000043,0.000075,0.000097,0.037511,0.000682,85.604862, ,0.261467,0.511814,6,White,Default, ,Regular,yes,no,0,n/a,n/a, ,"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21",255,255,255
3," ","1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21",0.428622,1.143108,-0.000230,0.000044,0.000042,0.000074,0.000096,0.033814,0.000615,86.326354, ,0.222883,0.475602,6,White,Default, ,Regular,yes,no,0,n/a,n/a, ,"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21",255,255,255
4," ","1,2,3,4,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21",0.142979,1.143124,-0.000840,0.000045,0.000044,0.000078,0.000100,0.030045,0.000546,84.468461, ,0.239445,0.374918,16,White,Default, ,Regular,yes,no,0,n/a,n/a, ,"1,2,3,4,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21",255,255,255
5," ","1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21",0.571353,1.143164,0.000784,0.000044,0.000042,0.000074,0.000096,0.027194,0.000494,86.593419, ,0.213540,0.430629,6,White,Default, ,Regular,yes,no,0,n/a,n/a, ,"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21",255,255,255
6," ","1,2,3,4,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21",0.000141,1.143101,-0.000885,0.000046,0.000045,0.000081,0.000103,0.035513,0.000646,82.937166, ,0.291437,0.465014,16,White,Default, ,Regular,yes,no,0,n/a,n/a, ,"1,2,3,4,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21",255,255,255
7," ","1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21",0.714058,1.143134,0.000247,0.000044,0.000043,0.000075,0.000097,0.030057,0.000547,86.326626, ,0.221009,0.426056,6,White,Default, ,Regular,yes,no,0,n/a,n/a, ,"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21",255,255,255
|
magic example using search and/or regex
|
Create a new mimetype for it.
First create a text-rkt.xml file with content:
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="text/rkt">
<comment>rkt text</comment>
<generic-icon name="leafpad"/>
<glob pattern="*.rkt"/>
</mime-type>
</mime-info>Then add this to local mime database:
xdg-mime install text-rkt.xmlThen associate with some program (e.g. leafpad):
xdg-mime default leafpad.desktop text/rktAnd voila: all .rkt files will be opened in leafpad. (and their icon is also leafpad)
|
For a college class, I have to download and open .rkt files. In order to open them with the correct program I have to right-click > open with, and if I set a default program, it becomes the default for all text files. Is there any way to change the default just for files ending in .rkt. (Similar to the way python files open in atom when they end in .py but open in xed when they do not, even though file still recognizes them as python files.)
|
Changing program used to open file based on file extension
|
Your File is not executable. chmod +x /path/to/TeensyduinoInstall.linux64 This is a "security-feature" of Linux.
Dependenting on where the Program installs itselfs, you need granted rights. If it takes place in your $HOME then not.
|
I'm trying to install a program (Teensyduino) on Xubuntu 16.04, but the executable installation file has a .linux64 extension. I've tried running the following commands to open it
sudo ./TeensyduinoInstall.linux64
sudo TeensyduinoInstall.linux64along with simply double-clicking the file. The first two yield errors:
sudo: ./TeensyduinoInstall.linux64: command not found
sudo: TeensyduinoInstall.linux64: command not foundwhile double-clicking just brings up the 'Open With' dialog. When I run:
ls -l TeensyduinoInstall.linux64I get the following output:
-rw-rw-r-- 1 calcium calcium 71934644 Dec 20 20:38 TeensyduinoInstall.linux64(My computer's name is calcium if that's not obvious.) What's the correct way to execute this file?
http://www.pjrc.com/teensy/td_download.html
|
linux64 extension
|
It sounds like there's quite a bit of confusion going on here, but to answer your direct questions:Why would anyone use a binary configuration file?Binary configuration files are probably smaller than a text format. If the configuration file "format" exactly matches your in-memory layout, you can just read the file in without needing a parser.
These days, the disadvantages (the file not being human readable, lack of forward/backward compatibility) almost certainly outweigh the advantages, but the may be some very small embedded systems where it's a sensible tradeoff.Why do I need a special editor to read it?Because a string of hex digits (or binary, or whatever else) isn't generally understandable to a human. Look it at hex dump of a gzipped file and tell me what it says without using a tool to uncompress it.
|
I understand that a binary file is not simple machine code with zeroes and ones. At a meeting yesterday, my colleague stated that we would need a hexdump editor to read binary configuration files for a system. Why would anyone use a binary configuration file? Why do I need a special editor to read it?
|
How are binary files "binary"?
|
You're looking at a manpage that isn't for the version of software you're looking at
The manpage from the doc directory at that github site says:
name Define a ``named'' magic instance that can be called
from another use magic entry, like a subroutine
call. Named instance direct magic offsets are rela-
tive to the offset of the previous matched entry,
but indirect offsets are relative to the beginning
of the file as usual. Named magic entries always
match.
|
From the magic file format manual the format for the rule should be
offset type value messageFor example:
0 string MZ
>0x18 leshort <0x40 MS-DOS executable
>0x18 leshort >0x3f extended PC executable (e.g., MS Windows)Using this context, I am trying to understand magic file such as this one which has rules like
# DIY-Thermocam raw data
0 name diy-thermocam-parser
>0 beshort x scale %d-What does the first rule mean? name is not a valid type from the man page at least. And there is no test component.
|
Magic file format
|
http://www.netmet-solutions.org/download/netMETdistrib-4.5_5.8_20160322.tgz has a redirect enforced to http://www.netmet-solutions.org/Telechargement/Telechargement (a standard HTML page). So basically, you are not downloading the .tgz file, but a simple HTML page. The output of wget confirms the redirect:
➤ wget http://www.netmet-solutions.org/download/netMETdistrib-4.5_5.8_20160322.tgz
--2017-04-14 11:14:43-- http://www.netmet-solutions.org/download/netMETdistrib-4.5_5.8_20160322.tgz
Resolving www.netmet-solutions.org... 193.50.27.134
Connecting to www.netmet-solutions.org|193.50.27.134|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: /Telechargement/Telechargement [following]
--2017-04-14 11:14:44-- http://www.netmet-solutions.org/Telechargement/Telechargement
Connecting to www.netmet-solutions.org|193.50.27.134|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `netMETdistrib-4.5_5.8_20160322.tgz'EDIT: Basically, you have to accept the CeCILL license , in order to download the archive (http://www.netmet-solutions.org/Telechargement/Jaccepte). To do this via wget, you will need to pass the expected cookie, in the header:
wget --no-cookies --header "Cookie: accepted_licence=chocolat" http://www.netmet-solutions.org/download/netMETdistrib-4.5_5.8_20160322.tgz, where the resulted file will be recognized as gzip compressed data:
➤ file netMETdistrib-4.5_5.8_20160322.tgz
netMETdistrib-4.5_5.8_20160322.tgz: gzip compressed data, last modified: Tue Mar 22 12:39:36 2016, from Unix
|
I'm trying to download a .tgz file under debian so I decided to use wget for this. This is my command line :
~$ wget http://www.netmet-solutions.org/download/netMETdistrib-4.5_5.8_20160322.tgzI got the file and I want to tar so I do
~$ tar -zxvf netMETdistrib-4.5_5.8_20160322.tgzand it says that
gzip: stdin: not in gzip formatSo I check the file and this appear
netMETdistrib-4.5_5.8_20160322.tgz: HTML document, ISO-8859 text, with very long lineswget transformed a tgz file in HTML and I don't know why.
Any ideas? Thx
|
wget convert tgz file to HTML
|
PE32+ is a public specification that was chosen for a reason (see the note on page 15 of the UEFI Specification 2.8B).Note:This image type is chosen to enable UEFI images to contain Thumb and Thumb2 instructions while defining the EFI interfaces themselves to be in ARM mode)It has nothing to do with dependency. Many specifications were developed by a company and then adopted as standards. For more info on the competing formats you could start here.
|
On an Ubuntu 20.04 system on Intel hardware:
# cd /boot/efi/EFI/
# file $(find . -name '*.efi')
./ubuntu/grubx64.efi: PE32+ executable …, for MS Windows
./ubuntu/shimx64.efi: PE32+ executable …, for MS Windows
./ubuntu/mmx64.efi: PE32+ executable …, for MS Windows
./BOOT/fbx64.efi: PE32+ executable …, for MS Windows
./BOOT/mmx64.efi: PE32+ executable …, for MS WindowsIt is Ubuntu-only, single-boot.
Unix systems predate Windows by fourteen years.
So why "MS Windows"?
Is there no way of escaping from the world of Microsoft?
(And yes, I know, resistance is futile.)
|
Why do Unix/Linux systems still need to depend on Microsoft?
|
What part of linux goes over assigning filetypes? Did I destroy something by building the gtk version of vim?Under Linux file name extensions have no bearing on the contents of the file. They are often consistent for convenience and software is not meant to take decisions based on extensions.
|
Unsure where to look for this, but since this morning every file I create is of type plaintext.
The last thing I did was remove vim to install the gtk-3 version for python support etc. Just Just before this I did make a python, C# and go file simply by using
touch file.<extension type>What part of linux goes over assigning filetypes? Did I destroy something by building the gtk version of vim?
Update
To further specify what I did before it changed.
Before installing vim gtk-3 I used the following command to remove my old install
sudo apt remove vim vim-runtime gvimthen I installed the gtk version with
sudo apt install vim-gtk3Ran PlugInstall in vim, the plugins.
-YouCompleteMe
-LightLine
-Polyglot
Afterwards I wanted to try it out so I did a
touch test.pyStraight away I noticed the icon was a plaintext, also the description said 'text/plain'. All my old files were still using their respective types. Even when open in a editor the autocomplete suggestions worked.
|
file extensions not working anymore, everything is plaintext
|
Get the output of file separately and then use that in multiple tests, or in a case statement:
for file in ./test2/*; do
filetype=$( file "$file" ) if [[ $filetype == *7z* ]] ||
[[ $filetype == *zip* ]]
then
# skip these
continue
fi # rest of body of loop here
doneOr,
for file in ./test2/*; do
filetype=$( file "$file" ) case $filetype in
*7z*) continue ;; # skip these
*zip*) continue ;; # and these
esac # rest of body of loop here
doneYou may also want to get file to output the MIME type instead of a free form text string. That could be done with file -i and would make the script slightly more portable (if you care about that). See the file(1) manual (man 1 file).
To exclude directories, just use
if [ -d "$file" ]; then
continue
fibefore the call to file.
Alternatively, use short-circuit syntax:
[ -d "$file" ] && continueThe continue statement, in all instances where it's used above, will skip the remainder of the current iteration and continue with the next iteration of the loop. I'm using when I have determined that the current value of $file is something that we don't want to process in this iteration. This is the opposite of what you do, which is to try to craft a set of tests for when the operations should be performed.
A /bin/sh-compatible script would look like this in the end:
#!/bin/shfor file in ./test2/*; do
[ -d "$file" ] && continue filetype=$( file "$file" ) case $filetype in
*7z*) continue ;; # skip these
*zip*) continue ;; # and these
esac # rest of body of loop here
done
|
Want to 7zip all files in root/current folder except for all zip-files AND all 7z/7zip files. I can only get one of these to work at a time in one if ! statement:
for file in ./test2/*
do if ! { `file $file | grep -i zip > /dev/null 2>&1` && `file $file | grep -i 7z > /dev/null 2>&1`; }; then ## Most of the zip utilities contain "zip" when checked for file type.
## grep for the expression that matches your case 7z a -mx0 -mmt2 -tzip "${file%/}.cbz" "$file"
rm -rf "$file" fi
doneI have followed the "list" {list;}; standards from other posts, but no luck. My current solution is to nest if statements, like so:
for file in ./test2/*
do
if ! `file $file | grep -i 7z > /dev/null 2>&1`; then if ! `file $file | grep -i zip > /dev/null 2>&1`; then
## first if its not 7z, now also if not zip. 7z a -mx0 -mmt2 -tzip "${file%/}.cbz" "$file"
rm -rf "$file" fi fidoneOnly thing left is exclude directories. All files go. How to?
|
How to create a 7zip archive of files from a directory, excluding existing archives?
|
Whilst I don't have a MINIX system available, I am sure the problem is that the "mode" doesn't have distinct bits for the various filetypes. You should be using the macros like S_ISDIR rather than comparing to S_IFDIR (S rather than F). Here is the GNU C library.
Here are the old versions from a linux machine. The leading 0 means these values are in octal.
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #define S_IFMT 00170000
#define S_IFSOCK 0140000
#define S_IFLNK 0120000
#define S_IFREG 0100000
#define S_IFBLK 0060000
#define S_IFDIR 0040000
#define S_IFCHR 0020000etc. So your code is testing to see if (mode & 0120000) is non-zero, and it will be if either the 0100000 or the 020000 bit is set, which it will be for S_IFSOCK, S_IFLNK, S_IFREG, S_IFBLK, and S_IFCHR. Your pts will be of type S_IFCHR.
|
I have a simple program which prints whether a pathname argument is either a directory, regular file with execute privileges, a regular file, a symbolic link, or other.
I have the following if statement to determine this (mode_t mode originates from struct stat):
if (mode & S_IFDIR){
mode_s[n] = 'd';
} else if (is_user_exec(mode, ouid, ogid) && (mode & S_IFREG)){
mode_s[n] = 'e';
}else if (mode & S_IFREG){
mode_s[n] = 'f';
} else if (mode & S_IFLNK){
mode_s[n] = 'l';
} else {
mode_s[n] = 'o';
}All works well for the first three, but when I pass what should be classified as "o", it lists it as "l".
Can anyone figure out why my code is causing this?
FYI, I'm compiling and running the program on MINIX 3.2.1 and the troublesome pathname in question is /dev/ptyp8
|
File Stat Program [closed]
|
You did not mention your Linux distro so I can't give you details on what steps to follow to get it on your machine, however most Linux distros have Remmina remote desktop client which can read RDP files. Just install Remmina and open the rdp file with it.
|
My father's company site uses SAP. He's trying to move to Linux (tired of Windows' bugs, problems and viruses) but he can't natively use the site's functionalities. When he tries to open those a popup appears asking whether he'd prefer to save or open filename.rdp.
What is this .rdp extension and how can we use those files?
|
Problem using SAP site
|
I experienced this bug in 1.01 AppImage of Inkscape.
Mike Nealy gives an explanation and workaround in a bug report here
I've copied his workaround below:Simply updating the schema to contain show-type-column isn't enough.Downloading the newer schema file from
https://gitlab.gnome.org/GNOME/gtk/-/blob/c925221aa804aec344bdfec148a17d23299b6c59/gtk/org.gtk.Settings.FileChooser.gschema.xml
and installing it in
/usr/share/glib-2.0/schemas/org.gtk.Settings.FileChooser.gschema.xml,
running "glib-compile-schemas ." in that directory and using Alt-F2 r
to restart gnome-shell seems to resolve the issue with Inkscape 1.0.1.
|
I have repeatedly encountered a problem with several programs that use open/save file dialogues.
Upon initiating these by trying to open or to save a file, the program freezes for about 10 seconds and then crashes. With libreoffice for example, I get the following error message when started from terminal:
Error creating proxy: Error calling StartServiceByName for org.gtk.vfs.UDisks2VolumeMonitor: Timeout was reached (g-io-error-quark, 24)(soffice:1466): GLib-GIO-ERROR **: 19:11:38.289: Settings schema 'org.gtk.Settings.FileChooser' does not contain a key named 'show-type-column'Fatal exception: Signal 5
Stack:A stack trace follows.
I have read about a similar problem on AskUbuntu.SE, but the solution (multiple versions of /usr/share/glib-2.0/schemas/org.gtk.Settings.FileChooser.gschema.xml) does not apply to me.
The file seems to have the appropriate contents (to me). Excerpt about the key mentioned in the error:
<key name='show-type-column' type='b'>
<default>true</default>
<summary>Show file types</summary>
<description>
Controls whether the file chooser shows a column with file types.
</description>
</key>How do I fix this problem?
|
GTK FileChooser causes crashes in several programs
|
You need to install the development package for glib:
yum install glib2-develYou could save yourself the trouble of building Midnight Commander though, it's packaged for CentOS:
yum install mc
|
I am trying to ./configure midnight commander downloaded from http://ftp.midnight-commander.org/mc-4.8.14.tar.bz2
and I get the following:
checking for GLIB... no
configure: error: glib-2.0 not found or version too old (must be >= 2.14)so I got a glib version from ftp://rpmfind.net/linux/sourceforge/r/ra/ramonelinux/Rel_0.99/releases/i686/packages/glib-2.41.2-1.ram0.99.i686.rpm
but when I install it, it clashes with the current version:
...
file /usr/share/locale/zh_CN/LC_MESSAGES/glib20.mo from install of glib-2.41.2-1.ram0.99.i686
conflicts with file from package glib2-2.40.0-4.el7.x86_64
file /usr/share/locale/zh_HK/LC_MESSAGES/glib20.mo from install of glib-2.41.2-1.ram0.99.i686
conflicts with file from package glib2-2.40.0-4.el7.x86_64
file /usr/share/locale/zh_TW/LC_MESSAGES/glib20.mo from install of glib-2.41.2-1.ram0.99.i686
conflicts with file from package glib2-2.40.0-4.el7.x86_64Indeed, I have a valid glib installed:
sudo yum list installed | grep glib
ModemManager-glib.x86_64 1.1.0-6.git20130913.el7 @anaconda
NetworkManager-glib.x86_64 1:1.0.0-14.git20150121.b4ea599c.el7 @base
dbus-glib.x86_64 0.100-7.el7 @anaconda
glib-networking.x86_64 2.40.0-1.el7 @base
glib2.x86_64 2.40.0-4.el7 @base
glibc.x86_64 2.17-78.el7 @base
glibc-common.x86_64 2.17-78.el7 @base
glibc-devel.x86_64 2.17-78.el7 @base
glibc-headers.x86_64 2.17-78.el7 @baseSo why does MC give me bollocks about wrong glib version?
|
trouble with glib while installing Midnight Commander on centOS
|
From the output of dpkg -l 'libglib2.0-0', the ii means the package is installed, and configured.
Since the package is downloaded and installed already, so now more network traffic, that's why the software installer told you 0 bytes downloaded.
To remove the package, use apt-get remove libglib2.0-0. glib is linked with lots of packages, you're likely to ruin your system after this. You can't remove it from software center, because it has other dependencies, e.g important system binaries.
|
I have a fresh install of Debian 6.0.5 (i386) on VMware Player. I was trying to install libglib2.0-0 using this command:
sudo aptitude install libglib2.0-0Unfortunately, I don't remember the exact output from the terminal but I remember there were 0 bytes installed or something. I'm guessing it didn't install correctly, so I want to remove it and try installing from the Software Center instead. However, when I click on remove, it just "greys out" and nothing happens. How do I uninstall it? Is there a command that could remove it from the terminal?
EDIT: The output of:
dpkg -l 'libglib2.0-0'root@vmware:/home/mohamed# dpkg -l 'libglib2.0-0'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Description
+++-==============-==============-============================================
ii libglib2.0-0 2.24.2-1 The GLib library of C routines
root@vmware:/home/mohamed#
|
Unable to uninstall libglib2.0-0 from Software Center
|
The equivalent command is
sudo dnf install glib2-develThis will install the glib 2 development headers, libraries and dependencies.
|
Recently, I switched from Ubuntu to Fedora. Now, I would like to run the Fedora equivalent to the Ubuntu command
sudo apt-get install libglib2.0-dev
Because when I cmake a project (in particular lcm 1.4.0), the error is
Could NOT find GLib2_glib (missing: GLIB2_GLIB_LIBRARY GLIB2_GLIB_INCLUDE_DIR GLIB2_GLIBCONFIG_INCLUDE_DIR)
Thank you!
|
Installation of libglib2.0-dev on Fedora
|
glib is not your problem. This is:
re.c:(.text+0xd6): undefined reference to `print_uppercase_words'What it's saying is you're calling a function print_uppercase_words, but it can't find it.
And there's a reason. Look very closely. There's a typo:
void print_upppercase_words(const gchar *string)After you fix that, you might still have a problem because you are specifying the libraries before the modules that require those libraries. In short, your command should be written
gcc -o re re.o -lglib-2.0so that -lglib-2.0 comes after re.o.
So I'd write your Makefile more like this:
re.o: re.c
$(CC) -I<includes> -o $@ -c $^re: re.o
$(CC) $^ -l<libraries> -o $@In fact, if you set the right variables, make will figure it all out for you automatically.
CFLAGS=$(shell pkg-config --cflags glib-2.0)
LDLIBS=$(shell pkg-config --libs glib-2.0)
CC=gccre: re.o
|
I'm having trouble compiling a simple, sample program against glib on Ubunutu. I get these errors. I can get it to compile but not link with the -c flag. Which I believe means I have the glib headers installed, but it's not finding the shared object code. See also the make file below.
$> make re
gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0 re.c -o re
/tmp/ccxas1nI.o: In function `print_uppercase_words':
re.c:(.text+0x21): undefined reference to `g_regex_new'
re.c:(.text+0x41): undefined reference to `g_regex_match'
re.c:(.text+0x54): undefined reference to `g_match_info_fetch'
re.c:(.text+0x6e): undefined reference to `g_print'
re.c:(.text+0x7a): undefined reference to `g_free'
re.c:(.text+0x8b): undefined reference to `g_match_info_next'
re.c:(.text+0x97): undefined reference to `g_match_info_matches'
re.c:(.text+0xa7): undefined reference to `g_match_info_free'
re.c:(.text+0xb3): undefined reference to `g_regex_unref'
collect2: ld returned 1 exit status
make: *** [re] Error 1Makefile used:
# Need to installed libglib2.0-dev some system specific install that will
# provide a value for pkg-config
INCLUDES=$(shell pkg-config --libs --cflags glib-2.0)
CC=gcc $(INCLUDES)
PROJECT=re# Targets
full: clean compileclean:
rm $(PROJECT)compile:
$(CC) $(PROJECT).c -o $(PROJECT).c code being compiled:
#include <glib.h> void print_upppercase_words(const gchar *string)
{
/* Print all uppercase-only words. */ GRegex *regex;
GMatchInfo *match_info; regex = g_regex_new("[A-Z]+", 0, 0, NULL);
g_regex_match(regex, string, 0, &match_info); while (g_match_info_matches(match_info))
{
gchar *word = g_match_info_fetch(match_info, 0);
g_print("Found %s\n", word);
g_free(word);
g_match_info_next(match_info, NULL);
} g_match_info_free(match_info);
g_regex_unref(regex);
}int main()
{
gchar *string = "My body is a cage. My mind is THE key."; print_uppercase_words(string);
}Strangely, when I run glib-config it doesn't like that command -- though I don't know how to tell bash or make how to just use one over the other when it complains that gdlib-config is in these 2 packages.
$> glib-config
No command 'glib-config' found, did you mean:
Command 'gdlib-config' from package 'libgd2-xpm-dev' (main)
Command 'gdlib-config' from package 'libgd2-noxpm-dev' (main)
glib-config: command not found
|
Linker errors when compiling against glib...?
|
The filter settings are saved as a gsettings scheme: org.gnome.gnome-system-log.filters. You can edit them with dconf-editor (org>gnome>gnome-system-log>filters). Replace the space in the name of the filter with a dash (or some other character), and gnome-system-log will work again.
|
I am unable to launch Gnome System Log Viewer after setting some filters. This is so, even after rebooting and reinstalling this GUI program. I found the following relevant line in /var/log/messages:kernel - [ 2345.123456] traps: logview[1234] trap int3 ip:32682504e9
sp:7fff9123c150 error:0It seems to be some exception error with the kernel. How to deal with it and get the viewer to launch again?
UPDATE:
I tried launching it manually with the following command: gnome-system-log and it gives me a more verbose error:GLib-GIO-ERROR **: g_menu_item_set_detailed_action: Detailed action
name 'win.filter_hide info' has invalid format Trace/breakpoint trapIt appears that the regex I wrote for win.filter_hide has some invalid format. How can I access this and change it manually without the GUI?
UPDATE2:
I tried:
$ gsettings get org.gnome.gnome-system-log filters
@as []
$ gsettings reset org.gnome.gnome-system-log filtersIt doesn't work. I think I am somewhere close, but not sure how to access win.filter_hide from here. From this image, I don't see how installing dconf-editor would help me access that filter.
UPDATE3:
I finally manage to take a peep at the values by logging in as root:
# gsettings get org.gnome.gnome-system-log filters
['hide info:1:::\\tinfo', 'error:0:#efef29292929::\\terr', 'show all:0:#000000000000::\\d']
# gsettings reset org.gnome.gnome-system-log filters
(process:3453): dconf-WARNING **: failed to commit changes to dconf: The connection is closedNot sure where is the problem. But as can be seen, I can't even do a reset when logged on as root. And I can't access those values when logged on as normal user.
UPDATE4:
Finally it is solved. The reason why connection is closed is because the root is logged in the user environment. This should work:
$ su -c "gsettings reset org.gnome.gnome-system-log filters" -
|
Unable to launch Gnome System Log Viewer after setting filters
|
I would suggest installing the new version of glib under /usr/local/lib or /usr/local/lib64 and then utilizing the LD_LIBRARY_PATH environment variable, like you mentioned above.
In fact that appears to be the default location. From the output of ./configure --help in glib-2.33.8:
By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.See this Ubuntu Forum thread for more details.
|
I'm working on a piece of software that needs to compile against a very modern version of glib, but also needs to run on Ubuntu 11.10 (which doesn't come with that version). My first thought was to just backport and replace glib, since the versions are theoretically compatible, but it causes some problems (most noticably with Unity not working right).
I know that the obvious solution is to use Ubuntu 12.04, but I don't have that option right now (working on it though).
Is there any sane way to handle this? Right now I'm looking at just compiling glib, taring it, and then manually setting C_INCLUDE_PATH and LD_LIBRARY_PATH. Unfortunately, I don't think I can't even package the compiled library because glib isn't very specific about its version (it's just glib-2.0.so).
Is the tar method the best I can do in this situation?
|
Compiling against a newer version of glib?
|
The problem is here:
libgmodule-2.0.so.0 => /usr/local/lib/libgmodule-2.0.so.0 (0x00007f1bba2a7000)
libgio-2.0.so.0 => /usr/local/lib/libgio-2.0.so.0 (0x00007f1bb884f000)
libgobject-2.0.so.0 => /usr/local/lib/libgobject-2.0.so.0 (0x00007f1bb7f81000)
libglib-2.0.so.0 => /usr/local/lib/libglib-2.0.so.0 (0x00007f1bb7c64000)
libgthread-2.0.so.0 => /usr/local/lib/libgthread-2.0.so.0 (0x00007f1bb3ef9000)No Debian installation would have those libraries in /usr/local, since it's a Policy violation (since it goes against the FHS specification about directory structure). The package would be rejected. You may have installed something from sources that installed those libraries, and the system prefers /usr/local over /usr/lib since it's the ldconfig preferences.
Remove those libraries (or comment out the /etc/ld.so.conf.d/libc.conf file) to make sure that the linker doesn't try to use them.
|
Just upgraded my dev system from Debian Wheezy to Debian Jessie, by the straight-forward method of changing sources.list and apt-get upgrade/dist-upgrade. Now I'm seeing failures when I try to log in to xdm, and errors coming back from apt-get. This is .xsession-errors
Xsession: X session started for rosuav at Friday 22 May 02:23:12 AEST 2015
localuser:rosuav being added to access control list
GLib-GIO-Message: Using the 'memory' GSettings backend. Your settings will not be saved or shared with other applications.
/usr/bin/x-session-manager: X server already running on display :0
xfce4-session: symbol lookup error: /usr/lib/x86_64-linux-gnu/libxfconf-0.so.2: undefined symbol: g_type_class_adjust_private_offsetAnd when I run some apt-get commands, I get back this:
Processing triggers for man-db (2.7.0.2-5) ...(gdbus call:10631): GLib-GObject-CRITICAL **: gtype.c:2722: You forgot to call g_type_init()(gdbus call:10631): GLib-GObject-CRITICAL **: gtype.c:2722: You forgot to call g_type_init()(gdbus call:10631): GLib-GObject-CRITICAL **: g_type_interface_add_prerequisite: assertion `G_TYPE_IS_INTERFACE (interface_type)' failed(gdbus call:10631): GLib-CRITICAL **: g_once_init_leave: assertion `result != 0' failed(gdbus call:10631): GLib-GObject-CRITICAL **: g_type_add_interface_static: assertion `G_TYPE_IS_INSTANTIATABLE (instance_type)' failed(gdbus call:10631): GLib-GObject-CRITICAL **: gtype.c:2722: You forgot to call g_type_init()(gdbus call:10631): GLib-GObject-CRITICAL **: g_type_interface_add_prerequisite: assertion `G_TYPE_IS_INTERFACE (interface_type)' failed(gdbus call:10631): GLib-CRITICAL **: g_once_init_leave: assertion `result != 0' failed(gdbus call:10631): GLib-GObject-CRITICAL **: g_type_add_interface_static: assertion `G_TYPE_IS_INSTANTIATABLE (instance_type)' failed(gdbus call:10631): GLib-CRITICAL **: g_once_init_leave: assertion `result != 0' failed(gdbus call:10631): GLib-GObject-CRITICAL **: g_object_new: assertion `G_TYPE_IS_OBJECT (object_type)' failed
**
GLib-GIO:ERROR:gdbusconnection.c:6764:get_uninitialized_connection: assertion failed: (ret != NULL)
AbortedIt seems to happen only after "Processing triggers for ...", but which packages' triggers are processed varies. It may be that it's processing triggers for something else and doesn't get to say so.
Poking around with Google has brought up a few things that look similar, but haven't helped, often because they don't have answers.
In case it's significant, I've been having GRUB trouble on this system since the upgrade, and have to manually set some parameters and reinvoke the boot process (from the grub-rescue prompt). I may have to simply buy myself a new hard drive, install fresh, and transfer everything over... but I'd really rather not have to do that, largely because of the geek's preference for actually knowing what's going on :)
EDIT: Per request, here's ldd /usr/bin/xfce4-session:
linux-vdso.so.1 (0x00007ffd85bdc000)
libxfsm-4.6.so.0 => /usr/lib/x86_64-linux-gnu/libxfsm-4.6.so.0 (0x00007f1bbb036000)
libSM.so.6 => /usr/lib/x86_64-linux-gnu/libSM.so.6 (0x00007f1bbae2e000)
libICE.so.6 => /usr/lib/x86_64-linux-gnu/libICE.so.6 (0x00007f1bbac10000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f1bba8cd000)
libxfce4ui-1.so.0 => /usr/lib/x86_64-linux-gnu/libxfce4ui-1.so.0 (0x00007f1bba6ba000)
libxfce4util.so.6 => /usr/lib/x86_64-linux-gnu/libxfce4util.so.6 (0x00007f1bba4aa000)
libgmodule-2.0.so.0 => /usr/local/lib/libgmodule-2.0.so.0 (0x00007f1bba2a7000)
libwnck-1.so.22 => /usr/lib/libwnck-1.so.22 (0x00007f1bba066000)
libgtk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0 (0x00007f1bb9a17000)
libgdk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0 (0x00007f1bb9761000)
libatk-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libatk-1.0.so.0 (0x00007f1bb953a000)
libcairo.so.2 => /usr/lib/x86_64-linux-gnu/libcairo.so.2 (0x00007f1bb9224000)
libgdk_pixbuf-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007f1bb9002000)
libpango-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x00007f1bb8db4000)
libpolkit-gobject-1.so.0 => /usr/lib/x86_64-linux-gnu/libpolkit-gobject-1.so.0 (0x00007f1bb8b97000)
libgio-2.0.so.0 => /usr/local/lib/libgio-2.0.so.0 (0x00007f1bb884f000)
libxfconf-0.so.2 => /usr/lib/x86_64-linux-gnu/libxfconf-0.so.2 (0x00007f1bb863b000)
libdbus-glib-1.so.2 => /usr/lib/x86_64-linux-gnu/libdbus-glib-1.so.2 (0x00007f1bb8413000)
libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007f1bb81cb000)
libgobject-2.0.so.0 => /usr/local/lib/libgobject-2.0.so.0 (0x00007f1bb7f81000)
libglib-2.0.so.0 => /usr/local/lib/libglib-2.0.so.0 (0x00007f1bb7c64000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f1bb7963000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1bb7746000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1bb739c000)
libpangocairo-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007f1bb718f000)
libpangoft2-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0 (0x00007f1bb6f79000)
libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f1bb6d3b000)
libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f1bb6a90000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f1bb688a000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f1bb6668000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f1bb6464000)
libstartup-notification-1.so.0 => /usr/lib/x86_64-linux-gnu/libstartup-notification-1.so.0 (0x00007f1bb6259000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f1bb6051000)
libXRes.so.1 => /usr/lib/x86_64-linux-gnu/libXRes.so.1 (0x00007f1bb5e4d000)
libXcomposite.so.1 => /usr/lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007f1bb5c4a000)
libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007f1bb5a46000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f1bb5840000)
libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f1bb5636000)
libXinerama.so.1 => /usr/lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f1bb5432000)
libXi.so.6 => /usr/lib/x86_64-linux-gnu/libXi.so.6 (0x00007f1bb5222000)
libXrandr.so.2 => /usr/lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f1bb5018000)
libXcursor.so.1 => /usr/lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f1bb4e0c000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f1bb4bfa000)
libpixman-1.so.0 => /usr/lib/x86_64-linux-gnu/libpixman-1.so.0 (0x00007f1bb494c000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f1bb4725000)
libxcb-shm.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007f1bb4521000)
libxcb-render.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007f1bb4316000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f1bb40fb000)
libgthread-2.0.so.0 => /usr/local/lib/libgthread-2.0.so.0 (0x00007f1bb3ef9000)
libthai.so.0 => /usr/lib/x86_64-linux-gnu/libthai.so.0 (0x00007f1bb3cf0000)
libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007f1bb3acc000)
libffi.so.5 => /usr/lib/x86_64-linux-gnu/libffi.so.5 (0x00007f1bb38be000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f1bb3699000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f1bb3482000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1bbb49a000)
libharfbuzz.so.0 => /usr/lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007f1bb322a000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f1bb3001000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f1bb2dfc000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f1bb2bf7000)
libxcb-util.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-util.so.0 (0x00007f1bb29ef000)
libX11-xcb.so.1 => /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007f1bb27ec000)
libdatrie.so.1 => /usr/lib/x86_64-linux-gnu/libdatrie.so.1 (0x00007f1bb25e4000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f1bb23c0000)
libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f1bb20de000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f1bb1e70000)
libgraphite2.so.3 => /usr/lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007f1bb1c53000)
libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f1bb1a41000)And ls -l /lib/*/libglib*:
lrwxrwxrwx 1 root root 23 Nov 13 2014 /lib/i386-linux-gnu/libglib-2.0.so.0 -> libglib-2.0.so.0.4200.1
-rw-r--r-- 1 root root 1207192 Nov 13 2014 /lib/i386-linux-gnu/libglib-2.0.so.0.4200.1
lrwxrwxrwx 1 root root 23 Nov 12 2014 /lib/x86_64-linux-gnu/libglib-2.0.so.0 -> libglib-2.0.so.0.4200.1
-rw-r--r-- 1 root root 1107040 Nov 12 2014 /lib/x86_64-linux-gnu/libglib-2.0.so.0.4200.1I wasn't aware that I had libglib2.0-0:i386 installed; it appears to be a dependency of wine:i386. Since that's not critical to me, I've tried removing it (sudo apt-get purge libglib2.0-0:i386)... apt-get finishes up by processing triggers for man-db, libgc-bin, libglib2.0-0:amd64, and then boom - the same crash sequence.
|
"symbol lookup error: /usr/lib/x86_64-linux-gnu/libxfconf-0.so.2: undefined symbol: g_type_class_adjust_private_offset"
|
I had this problem. Exactly the same issues, to the point - I am running Linux Mint 17.2 Rafaela (ubuntu 14.04/trusty) running Cinnamon2.6.1.3 amd64; except it's an Asus machine.
I am with you, I want my gnome-terminal back. This is what I did to fix it:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgradeThat was it. The problem was that libglib and the other packages were too new to work with gnome-terminal. So a full distro upgrade fixed all the dependencies. This probably happened after a system update and a reboot. Until the system is rebooted, it will still work fine. But only after that it throws the errors.
|
I was trying to build the AWN from source, and I installed a bunch of glib/gio dev packages required by libdesktop-agnostic (also built from source) that affect gsettings.
At some point during this, I rebooted and found that I couldn't launch any gnome-terminal. (Other gnome apps work normally.)
When I use the nemo-extension terminal (that's a gnome-terminal embedded into nemo) I get the following:
(gnome-terminal:11314): GLib-GIO-CRITICAL **: g_settings_get: the format string may not contain '&' (key 'monospace-font-name' from schema 'org.gnome.desktop.interface'). This call will probably stop working with a future version of glib.
**
ERROR:terminal-app.c:1449:terminal_app_init: assertion failed: (app->default_profile_id != NULL)
Aborted (core dumped)I checked 'monospace-font-name' in the schema 'org.gnome.desktop.interface' using dconf-editor, here's what gsettings get says:
~ $ gsettings get org.gnome.desktop.interface 'monospace-font-name'
'Monospace 10'
~ $No ampersands there.
It seems like having some libglib/gio's installed at once also causes the following related, similar gnome error-quarks that break gnome-notifications:[gnome-control-center] notifications: fix invalid format string | mail.gnome.org
gnome-terminal: GLib-GIO-CRITICAL messages from gnome-terminal-server | bugs.debian.orgWhich are great, but I'm kinda a novice at most of linux's technical-ness and I don't know really how (or, importantly, WHERE) to apply said patches.
Before you ask, I don't know which packages are causing this (there are waaaay too many in the libglib namespace) and I can't easily single them out one at a time without breaking lots of things.
Yes, all my repositories are official and yes, everything is up-to-date and in order as far as I can tell.
Linux Mint 17.2 Rafaela (ubuntu 14.04/trusty) running Cinnamon2.6.1.3 amd64 on a Toshiba Satellite p755 (intel, 6gb ram)
(there's nothing of interest in other log files, including .xsession-errors)
|
gnome-terminal broken due to gsettings+libglib
|
I get the impression that if the function at the top of the list references "glib" or "gobject", you have Bad Issues(TM) with libraries that usually shouldn't go wrong.You get the wrong impression, if you mean this indicates the flaw is probably in those libraries. It doesn't mean that; it more likely means that's where an earlier mistake finally blew up. By nature C doesn't have a lot of runtime safeguards in it, so you can easily pass arguments that will compile but aren't validated any further (unless you do it yourself). Simple example:
int main (void) {
char whoops[3] = { 'a', 'b', 'c' };
if (strcmp(whoops, "abcdef")) puts(whoops);Passes an unterminated string to several different string functions. This will compile no problem, and most likely run okay because the memory violation will be very slight, but it could seg fault in strcmp() or puts(). That doesn't mean the strcmp() implementation is buggy; the mistake is clearly right there in main().
Functions like those can't logically determine if an argument passed is properly terminated (this is what I meant WRT runtime checks and C "by nature" lacking them). There's not much point in stipulating the compiler should check, because most of the time the data won't be hard coded like that.
The stuff in the middle of a backtrace doesn't necessarily play a role either, although it could. Generally the place to start looking is the last entry; that's where the problem has been traced back to.
But the bug could always be anywhere. Often comparing a backtrace to errors reported by a mem checker like valgrind can help narrow things down. WRT your examples there may be a lot to sift through though; last I checked valgrind and gtk were not happy playmates.I was thinking of compiling a new version of glib2 (and co.), then statically linking these programs against it.You could, although I don't see any reason to believe anything will work any better because of it. It's grasping at straws. You can't actually debug the problem yourself, which is understandable, so you consider what you could try out of desperation.
Most likely you will be just be wasting a lot of time and frustrating yourself.I'm 99.99% confident the issues I'm looking at are some kind of glitch-out with glib2.I'm 99% confident you are overconfident there.
While again the bug could be anywhere, as a rule of thumb, consider the most widely tested parts the least likely culprits. In this case, glib is pretty ubiquitous, whereas irssi and NetSurf are relatively obscure.
The best thing for you to do is probably file a bug report. Backtraces are usually much appreciated there. Start with irssi and NetSurf; if you go straight to glib they will, reasonably enough, just say there's no reason for them to believe it's their problem unless you can demonstrate it (which all this doesn't). If on the other hand the irssi people determine it is in glib, they'll probably want to pursue that themselves.
|
I don't yet fully understand how segfaults and backtraces work, but I get the impression that if the function at the top of the list references "glib" or "gobject", you have Bad Issues(TM) with libraries that usually shouldn't go wrong.
Well, that's what I'm getting here, from two completely different programs.
The first is the latest build of irssi, compiled (cleanly, without any glitches or errors) directly from github.com.
Program received signal SIGSEGV, Segmentation fault.
0xb7cf77ea in g_ascii_strcasecmp () from /usr/lib/libglib-2.0.so.0
(gdb) bt
#0 0xb7cf77ea in g_ascii_strcasecmp () from /usr/lib/libglib-2.0.so.0
#1 0x08103455 in config_node_section_index ()
#2 0x081036b0 in config_node_traverse ()
#3 0x080fb674 in settings_get_bool ()
#4 0x08090bce in command_history_init ()
#5 0x08093d81 in fe_common_core_init ()
#6 0x0805a60d in main ()The second program I'm having issues with is the NetSurf web browser (which also compiles 100% cleanly) when built against GTK (when not built to use GTK it runs fine):
Program received signal SIGSEGV, Segmentation fault.
0xb7c1bace in g_type_check_instance_cast () from /usr/lib/libgobject-2.0.so.0
(gdb) bt
#0 0xb7c1bace in g_type_check_instance_cast () from /usr/lib/libgobject-2.0.so.0
#1 0x080cd31c in nsgtk_scaffolding_set_websearch ()
#2 0x080d05da in nsgtk_new_scaffolding ()
#3 0x080dafd8 in gui_create_browser_window ()
#4 0x0809e806 in browser_window_create ()
#5 0x080c2fa9 in ?? ()
#6 0x0807c09d in main ()I'm 99.99% confident the issues I'm looking at are some kind of glitch-out with glib2. The rest of my system works 100% fine, just these two programs are doing weird things.
I'm similarly confident that if I tried to build other programs that used these libraries, they would quite likely fail too.
Obviously, poking glib and friends - and making even one tiny little mistake - is an instant recipe to make practically every single program in the system catastrophically break horribly (and I speak from experience with another system, long ago :P).
Given I have absolutely no idea what I'm doing with this kind of thing and I know it, I am loathe to go there; I'd like to keep my current system configuration functional :)
I was thinking of compiling a new version of glib2 (and co.), then statically linking these programs against it. I just have no idea how to do this - what steps do I need to perform?
An alternative idea I had was to ./configure --prefix=/usr; make; make install exactly the same version of glib I have right now "back into" my system, to reinstall it. I see that the associated core libraries all end with "0.3200.4":
-rwxr-xr-x 1 root root 1.4M Aug 9 2012 /usr/lib/libgio-2.0.so.0.3200.4
-rwxr-xr-x 1 root root 1.2M Aug 9 2012 /usr/lib/libglib-2.0.so.0.3200.4
-rwxr-xr-x 1 root root 11K Aug 9 2012 /usr/lib/libgmodule-2.0.so.0.3200.4
-rwxr-xr-x 1 root root 308K Aug 9 2012 /usr/lib/libgobject-2.0.so.0.3200.4
-rwxr-xr-x 1 root root 3.7K Aug 9 2012 /usr/lib/libgthread-2.0.so.0.3200.4Would that possibly work, or break things horribly? :S
If it would possibly work, what version does "0.3200.4" translate to?
What other ideas can I try?
I'm not necessarily looking for fixes for glib itself that correct whatever fundamental error is going on - it isn't affecting me that badly. I just want to get irssi and NetSurf to run correctly.
|
Getting segmentation faults from inside glib and gobject - I THINK I want to build/statically link against an independant version of glib2
|
You set environment variables in a process and they are inherited by all the child processes. Exactly how you go about that depends on where you want it to be available. You don't have to modify any GLib configuration, though.
To set an environment variable for programs started from your shell (I'll assume Bash here), you can write:
export G_SLICE=always-mallocAll programs you start from this shell session after that will have the variable set.
If you want it to be set for every shell you start afterwards, add that line to ~/.profile as well. In that case it will apply to all future shells you start, but not any that are currently running.
To set it for just a single execution of a program (perhaps to debug its effects), precede the command with the variable assignment:
$ G_SLICE=always-malloc gsomethingThose are all for commands you run from the terminal. .profile will generally work for the GUI as well, but that can be broken by system configuration. They're all per-user configuration as well.
If you want it set for every user all the time, you can (likely) add an assignment to /etc/environment. The format is a little different there: just KEY=VAL on separate lines, with no required quoting and none of anything else.
G_SLICE=always-mallocThis is (again, likely — system-dependent) parsed by the pam_env module. There is a per-user ~/.pam_environment file as well, which has the same effect for just the one user, but may or may not be enabled on your distribution. These both require logging out and back in for the change to take effect.
Alternatively, you can add the export statement in ~/.xinitrc (if you use startx) or ~/.xsession (for most login managers). KDE supports a directory ~/.kde/env that can contain as many shell files as you want, which contain export statements as above.
|
I've been told I need to set the following environment variable in order to work around a glib bug:
G_SLICE=always-mallocBut I don't know how to do it, and anywhere I've seen it's use recommended, they just take it for granted you know how to do it (even the gnome documentation: https://developer.gnome.org/glib/stable/glib-running.html).
So I tried setting it as a linux environment variable. I tried setting it in the programming environment I was in (Firefox Add-on SDK), but without success.
It seems to me that I may have to install glib development packages and find some sort of config file. But perhaps someone would help before I go up the wrong path?
|
How set glib environment variable: g_slice
|
? Build glib-1.2.10 : I don't think you can do that with a contemporary OS. The latest packages were built for Ubuntu 7.04? year 2007, probably with gcc-3.4.6 !
Please download from "old ubuntu" → libglib1.2_1.2.10-17build1_i386.deb http://old-releases.ubuntu.com/ubuntu/pool/main/g/glib1.2/libglib1.2_1.2.10-17build1_i386.deb ... and libglib1.2-dev_1.2.10-17build1_i386.deb http://old-releases.ubuntu.com/ubuntu/pool/main/g/glib1.2/libglib1.2-dev_1.2.10-17build1_i386.deb
The packages are installed OK, Ubuntu 21.04 - amd64
sudo apt install ./libglib1.2_1.2.10-17build1_i386.deb
sudo apt install ./libglib1.2-dev_1.2.10-17build1_i386.deb... and ldd confirms libglib-1.2.so.0.0.10 OK.
P.S.: The year 2005 gtk-1.2.10 packages should be usable too http://old-releases.ubuntu.com/ubuntu/pool/main/g/gtk+1.2/
EDIT : libgtk1.2-common:all repacked to :i386 . Link https://drive.google.com/drive/folders/1hRMXw6utPJdpNSZlxiXYIjOK4v3nmIQu?usp=sharing ... then no issues with Ubuntu 21.04
|
I try to install glib 1.2 on Ubiuntu 21.04 to run old c program
After succesfull
./configure --build=i386-linux-gnu --host=i386-linux-gnuI try
makewith error :
make check
Making check in .
make[1]: Wejście do katalogu '/home/a/Pobrane/glib-1.2.0'
/bin/sh ./libtool --mode=link gcc -g -O2 -Wall -D_REENTRANT -o libglib.la -rpath /usr/local/lib -version-info 0:0:0 -release 1.2 garray.lo gcache.lo gcompletion.lo gdataset.lo gdate.lo gerror.lo ghash.lo ghook.lo giochannel.lo giounix.lo glist.lo gmain.lo gmem.lo gmessages.lo gmutex.lo gnode.lo gprimes.lo grel.lo gscanner.lo gslist.lo gstrfuncs.lo gstring.lo gtimer.lo gtree.lo gutils.lo
rm -fr .libs/libglib.la .libs/libglib.* .libs/libglib-1.2.**** Warning: This library needs some functionality provided by -lc.
*** I have the capability to make that library automatically link in when
*** you link to this library. But I can only do this if you have a
*** shared version of the library, which you do not appear to have.
gcc -shared -Wl,-soname -Wl,libglib-1.2.so.0 -o .libs/libglib-1.2.so.0.0.0 garray.lo gcache.lo gcompletion.lo gdataset.lo gdate.lo gerror.lo ghash.lo ghook.lo giochannel.lo giounix.lo glist.lo gmain.lo gmem.lo gmessages.lo gmutex.lo gnode.lo gprimes.lo grel.lo gscanner.lo gslist.lo gstrfuncs.lo gstring.lo gtimer.lo gtree.lo gutils.lo
/usr/bin/ld: gcache.lo: in function `g_bit_nth_lsf':
.../home/a/Pobrane/glib-1.2.0/glib.h:1560: multiple definition of `g_bit_nth_msf'; garray.lo:/home/a/Pobrane/glib-1.2.0/glib.h:1560: first defined here
/usr/bin/ld: gutils.lo: in function `g_bit_storage':
/home/a/Pobrane/glib-1.2.0/glib.h:1578: multiple definition of `g_bit_storage'; garray.lo:/home/a/Pobrane/glib-1.2.0/glib.h:1578: first defined here
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:296: libglib.la] Błąd 1
make[1]: Opuszczenie katalogu '/home/a/Pobrane/glib-1.2.0'
make: *** [Makefile:403: check-recursive] Błąd 1I have googled the error info without result. Is the solution for this ?
========edit===
After glib installation using method by Knud
make
cc -ansi -Wall -g -I /usr/include/glib-1.2 -I /usr/include/gtk-1.2 -I /usr/lib/glib/include -c julia2.c
julia2.c:8:10: fatal error: gtk/gtk.h: Nie ma takiego pliku ani katalogu
8 | #include <gtk/gtk.h>
| ^~~~~~~~~~~
compilation terminated.
make: *** [makefile:16: julia2.o] Błąd 1so no errors from compilation. Additional check :
find . -name '*.so.*' -type f -exec file {} \;
./snap/brave/121/.config/BraveSoftware/Brave-Browser/WidevineCdm/4.10.2209.0/_platform_specific/linux_x64/libwidevinecdm.so.sig: data
./snap/brave/120/.config/BraveSoftware/Brave-Browser/WidevineCdm/4.10.2209.0/_platform_specific/linux_x64/libwidevinecdm.so.sig: data
./Pobrane/hplip-3.21.6/.libs/libhpmud.so.0.0.6: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=02c7f5f977604305c3a6d6167f8f87455922a882, not stripped
./Pobrane/hplip-3.21.6/.libs/libhpipp.so.0.0.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=46158ce64a378404dc4008aaed0b65f67c4bd4a4, not stripped
./Pobrane/hplip-3.21.6/.libs/libsane-hpaio.so.1.0.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=5277f7887124074022671d51263eae68e234588c, not stripped
./Pobrane/hplip-3.21.6/.libs/libhpdiscovery.so.0.0.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=3c4d2def464c65586af097c4e06f3c4b13d8b203, not stripped
./Pobrane/hplip-3.21.6/.libs/libhpip.so.0.0.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=297d1bea4175bb34ba1b989a4219c12b7c615fe1, not strippedbut ldconfig shows libglib 1.2, 2.0 and 2.4 between 1249 shared libraries
ldconfig -p>s.txt...
libglibmm_generate_extra_defs-2.4.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libglibmm_generate_extra_defs-2.4.so.1
libglibmm-2.4.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libglibmm-2.4.so.1
libglib-2.0.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libglib-2.0.so.0
libglib-1.2.so.0 (libc6) => /lib/libglib-1.2.so.0
|
How to install glib 1.2 on new system?
|
You can pass in the required command-line parameters using CPPFLAGS:
make CPPFLAGS="$(pkg-config --cflags glib-2.0)"This will provide the necessary include paths to the compiler.
|
I'm trying to install OpenFlow in my Ubuntu machine. I'm following the steps in link.
When I try to run these commands:
cd utilities/wireshark_dissectors/openflow
make
sudo make installmake gives me the following error:
/usr/include/glib-2.0/glib/gtypes.h:32:24: fatal error: glibconfig.h: No such file or directory
compilation terminated.
<builtin>: recipe for target 'packet-openflow.o' failed
make: *** [packet-openflow.o] Error 1According to this I should do this, but in my case there is a make file.
gcc `pkg-config --cflags glib-2.0` foo.c `pkg-config --libs glib-2.0`What should I do to solve this problem?
|
Installing OpenFlow inside Ubuntu error: glibconfig.h: No such file or directory
|
More searching suggested that logging out and back in to create a new desktop session would resolve the problem. I tried it and it worked.
Apparently, even though gconfd-2 was running, it wasn't hooked up to D-BUS properly.
|
I'm unable to start Tomboy on my Gentoo Linux system. It used to work, but now I just get Unhandled Exception: GLib.GException: Configuration server couldn't be contacted: D-BUS error: Method "GetDefaultDatabase" with signature "" on interface "org.gnome.GConf.Server" doesn't exist and a stack trace.
/usr/libexec/gconfd-2 is running as my user.
I'm not sure what else to look at. How do I fix this?
|
Tomboy won't start: Configuration server couldn't be contacted
|
That's not a symbol in glibc, it's a symbol in GLib. If you build and install GLib 2.30 or later, you should be able to build Firefox 50.
|
I've successfully been able to configure the latest Firefox (source) without errors. All the required dependencies are in place (i.e. GCC 4.9.2 via devtoolset-3, Python 2.7, Yasm, libffi 3.2.1, and on). When I run ./mach build it also successfully configures and starts makeing the binaries... then after about 24 minutes it chokes on
24:40.15 /home/osboxes/firefox-50.0b7/gfx/thebes/gfxFontconfigFonts.cpp: In member function ‘virtual already_AddRefed<gfxFont> gfxPangoFontGroup::FindFontForChar(uint32_t, uint32_t, uint32_t, gfxFontGroup::Script, gfxFont*, uint8_t*)’:
24:40.15 /home/osboxes/firefox-50.0b7/gfx/thebes/gfxFontconfigFonts.cpp:1628:66: error: ‘g_unicode_script_from_iso15924’ was not declared in this scope
24:40.15 (const PangoScript)g_unicode_script_from_iso15924(scriptTag);
24:40.15 ^The pertinent part being‘g_unicode_script_from_iso15924’ was not declared in this scopeI searched online for this error first and the only reference to this is a fixed bug in v52 (ref) which isn't even in the sources repo at this time. This isn't a bug.
How to compile Firefox 50 for a system using GLibc 2.12?Solved: I discovered that g_unicode_script_from_iso15924 is a new symbol in GLib 2.30 (ref). Glib needs to be updated to at least version 2.30.
|
Compiling Firefox 50 under GLibc 2.12
|
I believe the recommended approach is to use grubby:
grubby --update-kernel=ALL --args="mem_sleep_default=deep"will add the given argument to the kernel command line, and
grubby --update-kernel=ALL --remove-args=mem_sleep_defaultwill remove it.
grubby minimises the changes made, and when updating kernel parameters, the above will preserve the other parameters (based on those used to boot the currently-running kernel).
/etc/default/grub isn’t necessarily the reference file for boot parameters; AFAICT on EFI systems you should look at /boot/efi/EFI/fedora/grubenv (or rather, /boot/grub2/grubenv).
See the GRUB 2 wiki page on the Fedora wiki for some complementary information.
|
I'm running Fedora 31 and when I installed it (F29) I added the option mem_sleep_default=deep to GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub. Now I wanted to remove that option but found the file like this:
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX=""
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=trueI remember there have been many more options like rd.lvm.lv or rd.luks.uuid which luckily still are in /boot/efi/EFI/fedora/grub.cfg but I can't find them anywhere else.
I think things might have changed since the upgrade to F30 or F31. Also I noticed that GRUB_ENABLE_BLSCFG=true might mean that things are done different now. I read that I shouldn't use grub2-mkconfig any more but grubby to change kernelopts. But I fear to loose all my kernelopts which I think are important.
So what is the correct way to handle this?
|
What is the correct way to handle default kernelopts in Fedora 31?
|
You have seen that your new kernel Arch Linux, with Linux 5.2.0-rc7-test is the third entry in submenu Advanced options for Arch Linux?
If it's still not showing, then try the following:Press c in the grub menu for the command line
Enter echo $prefix Enter, this should show your partition and path to /boot/grub. Verify that this is the correct partition.
Enter cat $prefix/grub.cfg Enter, this should show your current grub.cfg. If this is a different file, then there's something wrong with your grub installation.Documentation:https://www.gnu.org/software/grub/manual/grub/grub.html#prefix
|
I am trying to compile and install my own kernel (5.2.0-rc7) and everything seems to be working fine until I reboot to actually boot into it and am unable to select it from my GRUB boot menu. I have written a script (and done it manually with no difference) to compile and install for me based on the instructions on the Arch wiki. Everything compiles without errors, make modules_install places the proper file in the /lib/modules folder and the proper images seem to be in the /boot directory. mkinitcpio completes without error and when I run grub-mkconfig it seems like it finds my newly installed custom kernel giving me this output:
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/intel-ucode.img /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
Found linux image: /boot/vmlinuz-5.2.0-rc7-test
Found initrd image: /boot/intel-ucode.img /boot/initramfs-5.2.0-rc7-test.img
doneAnd when I look at the generated grub.cfg file, I see that it does include the newly installed kernel as expected, shown below:
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#### BEGIN /etc/grub.d/00_header ###
insmod part_gpt
insmod part_msdos
if [ -s $prefix/grubenv ]; then
load_env
fi
if [ "${next_entry}" ] ; then
set default="${next_entry}"
set next_entry=
save_env next_entry
set boot_once=true
else
set default="0"
fiif [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
else
menuentry_id_option=""
fiexport menuentry_id_optionif [ "${prev_saved_entry}" ]; then
set saved_entry="${prev_saved_entry}"
save_env saved_entry
set prev_saved_entry=
save_env prev_saved_entry
set boot_once=true
fifunction savedefault {
if [ -z "${boot_once}" ]; then
saved_entry="${chosen}"
save_env saved_entry
fi
}function load_video {
if [ x$feature_all_video_module = xy ]; then
insmod all_video
else
insmod efi_gop
insmod efi_uga
insmod ieee1275_fb
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus
fi
}if [ x$feature_default_font_path = xy ] ; then
font=unicode
else
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,msdos1' --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 9c56060e-d76c-4cea-8c41-137092164107
else
search --no-floppy --fs-uuid --set=root 9c56060e-d76c-4cea-8c41-137092164107
fi
font="/usr/share/grub/unicode.pf2"
fiif loadfont $font ; then
set gfxmode=auto
load_video
insmod gfxterm
fi
terminal_input console
terminal_output gfxterm
if [ x$feature_timeout_style = xy ] ; then
set timeout_style=menu
set timeout=5
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
set timeout=5
fi
### END /etc/grub.d/00_header ###### BEGIN /etc/grub.d/10_linux ###
menuentry 'Arch Linux' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-9c56060e-d76c-4cea-8c41-137092164107' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,msdos1' --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 9c56060e-d76c-4cea-8c41-137092164107
else
search --no-floppy --fs-uuid --set=root 9c56060e-d76c-4cea-8c41-137092164107
fi
echo 'Loading Linux linux ...'
linux /boot/vmlinuz-linux root=UUID=9c56060e-d76c-4cea-8c41-137092164107 rw quiet
echo 'Loading initial ramdisk ...'
initrd /boot/intel-ucode.img /boot/initramfs-linux.img
}
submenu 'Advanced options for Arch Linux' $menuentry_id_option 'gnulinux-advanced-9c56060e-d76c-4cea-8c41-137092164107' {
menuentry 'Arch Linux, with Linux linux' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-linux-advanced-9c56060e-d76c-4cea-8c41-137092164107' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,msdos1' --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 9c56060e-d76c-4cea-8c41-137092164107
else
search --no-floppy --fs-uuid --set=root 9c56060e-d76c-4cea-8c41-137092164107
fi
echo 'Loading Linux linux ...'
linux /boot/vmlinuz-linux root=UUID=9c56060e-d76c-4cea-8c41-137092164107 rw quiet
echo 'Loading initial ramdisk ...'
initrd /boot/intel-ucode.img /boot/initramfs-linux.img
}
menuentry 'Arch Linux, with Linux linux (fallback initramfs)' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-linux-fallback-9c56060e-d76c-4cea-8c41-137092164107' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,msdos1' --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 9c56060e-d76c-4cea-8c41-137092164107
else
search --no-floppy --fs-uuid --set=root 9c56060e-d76c-4cea-8c41-137092164107
fi
echo 'Loading Linux linux ...'
linux /boot/vmlinuz-linux root=UUID=9c56060e-d76c-4cea-8c41-137092164107 rw quiet
echo 'Loading initial ramdisk ...'
initrd /boot/initramfs-linux-fallback.img
}
menuentry 'Arch Linux, with Linux 5.2.0-rc7-test' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.2.0-rc7-test-advanced-9c56060e-d76c-4cea-8c41-137092164107' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,msdos1' --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 9c56060e-d76c-4cea-8c41-137092164107
else
search --no-floppy --fs-uuid --set=root 9c56060e-d76c-4cea-8c41-137092164107
fi
echo 'Loading Linux 5.2.0-rc7-test ...'
linux /boot/vmlinuz-5.2.0-rc7-test root=UUID=9c56060e-d76c-4cea-8c41-137092164107 rw quiet
echo 'Loading initial ramdisk ...'
initrd /boot/intel-ucode.img /boot/initramfs-5.2.0-rc7-test.img
}
}### END /etc/grub.d/10_linux ###### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###### BEGIN /etc/grub.d/41_custom ###
if [ -f ${config_directory}/custom.cfg ]; then
source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f $prefix/custom.cfg ]; then
source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###However, when I reboot my VM, I see that the Grub menu does not list the newly installed kernel only the standard one. According to the Arch wiki, all that needs to be done is to run the grub-mkconfig command to generate a new grub config file and if it is reflected in the config file it should show up but this doesn't seem to be the case.
What am I missing? How can I get my newly installed kernel to show up in the Grub boot menu? Can anyone point me in the right direction? Thanks.
I am doing this on Arch Linux running 5.1.16-arch1-1-ARCH using Virtualbox 6.0.4 r128413
|
Why isn't my compiled kernel showing up in the GRUB boot menu?
|
I ran grub-mkconfig -o /boot/grub/grub.cfg using Ansible, it created the same .new extention.
But when I used grub-mkconfig > /boot/grub/grub.cfg, it ran successfully and created grub.cfg.
-o might not be the same as >.
Looking at the source code after @oldfred 's comment, found out that the .new extension is created when there is an error in either /etc/default/grub or /etc/grub.d/* files. See here:
if test "x${grub_cfg}" != "x" ; then
if ! ${grub_script_check} ${grub_cfg}.new; then
# TRANSLATORS: %s is replaced by filename
gettext_printf "Syntax errors are detected in generated GRUB config file.
Ensure that there are no errors in /etc/default/grub
and /etc/grub.d/* files or please file a bug report with
%s file attached." "${grub_cfg}.new" >&2
echo >&2
exit 1
else
# none of the children aborted with error, install the new grub.cfg
mv -f ${grub_cfg}.new ${grub_cfg}
fi
fi
|
When I run update-grub2 on my Debian Buster server, instead of creating a grub.cfg it creates a grub.cfg.new, even though grub.cfg does not exist.
And because of this my machine boots into a broken grub, because it cannot find grub.cfg.
Is there a way to tell update-grub2 to create grub.cfg instead of grub.cfg.new.
|
update-grub2 creates grub.cfg.new instead of grub.cfg
|
The meaningful part of the error message was cannot find a device for /, because mount command does not output the device entry for /.
What I didn't tell in the question is that I was trying to directly install the rootfs into a BTRFS subvolume. Apparently, chroot can not detect the / device in this scenario.
Here is what I was currently doing: (X is the root partition (device), Y is the boot partition)
host:# mount /dev/X /mnt/mydiskroot
host:# btrfs sub create /mnt/mydiskroot/rootfs
host:# mkdir /mnt/mydiskroot/rootfs/boot
host:# mount /dev/Y /mnt/mydiskroot/rootfs/boot
host:# rsync -avP debian-stretch-rootfs/ /mnt/mydiskroot/rootfs
host:# do-chroot.sh /mnt/mydiskroot/rootfs
root@guest:/# mount | awk '$3 == "/" {print}' # nothing shows up, so update-grub throws the mentioned errorHere is how I solved:
root@guest:/# exit
host:# mkdir /mnt/actual-rootfs
host:# mount -t btrfs -o subvol=rootfs,defaults /dev/X /mnt/actual-rootfs/
host:# umount /dev/Y
host:# mount /dev/Y /mnt/actual-rootfs/boot
host:# do-chroot.sh /mnt/actual-rootfs
root@guest:/# mount | awk '$3 == "/" {print}'
/dev/X on / type btrfs (rw,relatime,space_cache,subvolid=257,subvol=/rootfs)
root@guest:/# update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.9.0-11-amd64
Found initrd image: /boot/initrd.img-4.9.0-11-amd64
done
|
I'm trying to make a Debian installation manually from scratch to an external disk within a live Debian CD.
I created a Debian Stretch rootfs via multistrap by following the instructions from here (44fbcc).
Inside chroot environment, when it comes to Grub installation, I install the Grub2 to MBR:
debian:~# grub-install /dev/sdX --boot-directory=/bootCommand runs without error. When I need to create the /boot/grub/grub.cfg, it throws the following error:
debian:~# grub-mkconfig
/usr/sbin/grub-probe: error: cannot find a device for / (is /dev mounted?).Yes, /dev is mounted along with /sys, /proc and /run here.
How can I generate grub.cfg inside chroot environment?
|
grub-mkconfig gives error in chroot environment
|
If you modified any values for GRUB_CMDLINE_LINUX in /etc/default/grub, then you should run the following, as per the RHEL 9 Docs
# grub2-mkconfig --update-bls-cmdline -o /boot/grub2/grub.cfgFor me, it only fixed the actual state. When updating the kernel, it still used the previous LV name.
The only solution which helped also for kernel updates seems to be grubby:
# grubby --update-kernel=ALL --args="root=/dev/mapper/lvm01-root.vol ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/lvm01-swap.vol rd.lvm.lv=lvm01/root.vol rd.lvm.lv=lvm01/swap.vol"Even after the kernel update, the content of new conf file in the /boot/loader/entries/<machine-id>-<kernel version>.conf looks good and the system boots fine.
In fact, the problem may be related to this RH ticket, which is opened for quite a some time (but I'm not sure):
https://issues.redhat.com/browse/RHEL-4313
|
On the RHEL 9.3 I have renamed the logical volume (LV) /dev/lvm01/root to /dev/lvm01/root.vol. I did everything to make the new name correctly recognized:changed /etc/fstab entry
reloaded systemd configuration
remounted /And I also modified the /etc/default/grub entry:
GRUB_CMDLINE_LINUX="root=/dev/mapper/lvm01-root.vol ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/lvm01-swap.vol rd.lvm.lv=lvm01/root.vol rd.lvm.lv=lvm01/swap.vol"Then I expected the grub2-mkconfig -o /boot/grub2/grub.cfg to do the rest of the job and rebooted. But the system ended up with dracut message that the root partition is not found (or something like that).
After short investigation, I realized the kernel parameters had not been modified as expected. The manual change helped to get the OS booted. Interesting that the /boot/grub2/grub.cfg was updated. But what was not updated was the /boot/loader/entries/* files. And it was the issue.
|
The grub2-mkconfig does not propagate renamed root logical volume on RHEL 9
|
After a lot of trials and errors, I managed to find a solution for my problem. I am leaving it here, in case anyone stumbles upon this problem.
My system turned out to use BRTFS subvolumes and the steps to mount the necessary partitions are different for this type of filesystem. This is why I could not follow the steps in this guide. My particular situation had an EFI partition in /dev/nvme0n1p6 and the root and boot (I know, very odd) partition in /dev/nvme0n1p7. In the latter, there is a root subfolder that has the classic linux folders (bin, home, opt, etc.).
Go to the section Using the GRUB2 boot prompt for the solution that worked for me. For the sake of completeness, the next part explains how to execute the command grub2-mkconfig in a chrooted system that uses BRTFS subvolumes properly.
Chroot into a system with BRTFS subvolumes
By following this lifesaver post and trying out many combinations of mounting procedures out of desperation, I managed to chroot into my system correctly:
sudo mkdir /mnt/sysimage
sudo mount -o subvol=root /dev/nvme0n1p7 /mnt/sysimage
sudo mount -o bind /dev /mnt/sysimage/dev
sudo mount -o bind /proc /mnt/sysimage/proc
sudo mount -o bind /sys /mnt/sysimage/sys
sudo mount -o bind /sys/firmware/efi/efivars /mnt/sysimage/sys/firmware/efi/efivars
sudo mount /dev/nvme0n1p6 /mnt/sysimage/boot/efi
sudo chroot /mnt/sysimageNote: In case you end up without network connection inside the chrooted system, you can follow the steps detailed in the same guide.
After this, I could perform the following commands inside my chrooted system:
dnf reinstall shim-* grub2-efi-* grub2-common
grub2-mkconfig -o /boot/grub2/grub.cfg
sync && exitTo umount everything, just do:
sudo umount /mnt/sysimage/sys
sudo umount /mnt/sysimage/proc
sudo umount /mnt/sysimage/dev
sudo umount /mnt/sysimage/boot/efi
sudo umount /mnt/sysimage/sys/firmware/efi/efivars
sudo umount /mnt/sysimageDoing that, I no longer got the error /usr/sbin/grub2-probe: error: cannot find a device for / (is /dev mounted?), after running grub2-mkconfig -o /boot/grub2/grub.cfg, which was the original purpose of my question. Nevertheless, executing that command did not bring my Fedora back to the grub, even after trying these commands that I found on this gist:
# Check BIOS boot details [ Note: this command won't work if you are inside chroot. ]
efibootmgr -v
# In case you need to create new entry in BIOS
efibootmgr -c -d /dev/nvme0n1p1 -p 1 -L Fedora -l '\EFI\fedora\grubx64.efi' # or, shimx64.efiUsing the GRUB2 boot prompt
The real solution ended up being on this post on Fedora's main documentation, Using the GRUB2 boot prompt. I booted my PC, pressed Esc, got into the BIOS Menu and selected Fedora. Of course, there was not going to be anything there, so it got me to the classic black grub> screen. There, I executed the following commands:
# Show all partitions
grub> ls
(hd0) (hd1) (hd0,gpt1) ...# Try out every one of them until you find your EFI partition and your root partition. Mine was (hd2,gpt6) and (hd2,gpt7), respectively.
grub> ls (hd2,gpt6)/ # Had an EFI folder
grub> ls (hd2,gpt7)/ # Inside was the root folder and inside that, my beloved Fedora# You set root to your EFI partition, mine being (hd2,gpt6)
grub> set root=(hd2,gpt6)# And the following commands starting with the root partition, mine being (hd2,gpt7)
grub> linux (hd2,gpt7)/root/boot/vmlinuz-6.6.9-200.fc39.x86_64 root=/dev/nvme0n1p7 ro rootflags=subvol=root
grub> initrd (hd2,gpt7)/root/boot/initramfs-6.6.9-200.fc39.x86_64.img# This command will finish the session and will boot up the chosen kernel and RAM filesystem
grub> bootNote: You need to find the exact path where the kernel you want to boot up (vmlinuz-...) and the RAM filesystem (initramfs-...-.img) are. For this, you can just do ls <your root partition>/root/ and begin navigating folder by folder. For me, ls (hd2,gpt7)/root/boot/ showed me all the kernels and RAM filesystems I had. I chose the latest one, with the suffix 6.6.9-200.fc39.x86_64. Also, notice the part root=/dev/nvme0n1p7 ro rootflags=subvol=root in the linux command. This is crucial for a BRTFS system; without it the system won't boot up correctly. Naturally, root= has to be set to your own root partition, while the rest should remain the same.
Inside your system
By now, you should have booted up your old lost system. Inside, I opened up a terminal and executed the following commands to recover my grub, so that I didn't have to do the above process everytime I wanted to log into Fedora.
# Back up your current GRUB configuration as a precaution:
sudo cp /boot/efi/EFI/fedora/grub.cfg /boot/efi/EFI/fedora/grub.cfg.bak# Regenerate the GRUB configuration file with:
sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg# Reinstall GRUB to ensure it's properly installed on the EFI partition:
sudo grub2-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=FedoraI then rebooted my PC and, for some odd reason, I did not find Fedora listed on my BIOS Boot Menu (which had not happened until now, it always showed it, except that it only led to the grub> screen). I logged into my Windows, rebooted again, went into the BIOS Boot Menu, and now Fedora was there. I selected it and my PC booted directly into it, without going to the grub menu, which is indeed odd, but it definitely suits me as-is so far. I can now log into my Fedora, without problems.
As always, be careful executing any of these commands and double-check for your particular system and configuration.
|
I was trying to enable fractional scaling in Fedora 39 using ChatGPT and he recommended the following:
# NVIDIA's proprietary driver requires DRM KMS to be disabled for Wayland to work.
# Edit the file /etc/default/grub and ensure the parameter nvidia-drm.modeset=1 is not set.
# If it is, change it to nvidia-drm.modeset=0 or remove it. Then update the grub configuration with:
sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfgI did so and ran the command, only to find my GRUB Menu only showing me the Windows Boot Manager. I can boot into Windows without problems, but now GRUB cannot find Fedora.
Solution I am trying
I created a USB bootable drive with Fedora and, after doing a quick Google search (and more ChatGPT, besides being the culprit), I stumbled upon the following plausible solution (with my /dev partitions already inputted):
# Mount the root filesystem
sudo mount /dev/nvme0n1p7 /mnt/root# Mount the EFI partition
sudo mount /dev/nvme0n1p6 /mnt/root/boot/efi# Bind-mount the virtual filesystems
for dir in /dev /proc /sys /run; do
sudo mount --bind $dir /mnt/root$dir
doneWith that /mnt set up, I run sudo chroot /mnt, which worked as intented. I edited my /etc/default/grub file back to how it originally was, and then I tried to re-generate my grub.cfg file again with the command: grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg. Nevertheless, I keep getting the following error: /usr/sbin/grub2-probe: error: cannot find a device for / (is /dev mounted?).. I have tried several combinations of the mounting procedure without success, such as this one:
sudo mount --bind /dev /mnt/root/dev
sudo mount --bind /dev/pts /mnt/root/dev/pts
sudo mount --bind /dev/shm /mnt/root/dev/shm
sudo mount --bind /dev/disk /mnt/root/dev/disk
sudo mount --bind /proc /mnt/root/proc
sudo mount --bind /sys /mnt/root/sys
sudo mount --bind /run /mnt/root/runI also tried to follow this guide, which attempts to solve a similar problem, and there, the command works. I don't know what I could be doing wrong. Any help is appreciated!
Output of lsblk
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 845151 843104 411.7M EFI System
/dev/nvme0n1p2 845824 878591 32768 16M Microsoft reserved
/dev/nvme0n1p3 878592 783736831 782858240 373.3G Microsoft basic data
/dev/nvme0n1p4 994082816 997033681 2950866 1.4G Windows recovery environmen
/dev/nvme0n1p5 997033984 1000214527 3180544 1.5G Windows recovery environmen
/dev/nvme0n1p6 783736832 785833983 2097152 1G EFI System
/dev/nvme0n1p7 785833984 977303551 191469568 91.3G Linux filesystem
/dev/nvme0n1p8 977303552 994080767 16777216 8G Linux swap
|
Repair Fedora GRUB after grub2-mkconfig gone wrong
|
You are mixing up GRUB Legacy and GRUB2 terminology. The term "stage2" is for GRUB Legacy (i.e. versions 0.9x) only. But I think I understand what you mean.
When i386-pc version of GRUB is installed to the MBR and either the gap between the MBR and the first partition, or to the bios-boot partition, the /boot/grub2/i386-pc/{core,boot}.img files are only used by grub2-install, not by the actual boot process.
Since OS on i386-pc GRUB architecture has no reliable way to get information on how the BIOS last saw the disk ordering at boot time, grub-install basically has two options available on install time if configured to rely on BIOS disk support (as is the usual way):if a /boot/grub[2]/device.map file has been provided, use the information in it to map the OS devices to GRUB device names (which will correspond directly to BIOS disk numbers)
if the device.map file is not available, make a wild guess that the current OS disk order is the same as the BIOS disk detection order. This guess may or may not be correct.(Specifically, when running an installer or live media from USB, it is common to have the USB storage device be detected as the first "disk"; this can throw off the guess of grub-install, because once the installed OS boots on its own, the BIOS-level disk emulation for USB storage will no longer be there, as the BIOS won't be booting from USB media at that point.)
The GRUB boot code embedded in the actual MBR block contains two pieces of information written to it at grub-install time: the boot drive number and the LBA block number that GRUB should read next. In modern versions of GRUB, the drive number is usually encoded as 0xff, meaning "use the same disk BIOS used to read the MBR from".
When on a MBR-partitioned disk, the LBA block number will normally be 0x0000000000000001, pointing to the gap between the MBR and the first partition. On a MBR-partitioned disk, that is where the rest of the GRUB core image, essential modules, and the prefix string (which will point to the location of the /boot/grub directory) will be embedded to. On a GPT-partitioned disks, all of this will be written into the bios-boot partition instead, and the LBA block number embedded in the actual MBR boot code will be higher, as it will point to the beginning of the bios-boot partition.
The first block of the embedded code includes a blocklist that identifies which blocks to read next: when embedded to a MBR-partitioned disk, this will be a contiguous series of blocks starting from LBA block #2. The length of this series will mostly depend on the number and type of essential modules embedded along with the GRUB core image. Most of this embedded code will be LZMA compressed and then protected with Reed-Solomon error-correction codes, so modifying it will usually force you to essentially re-write the whole thing. Unfortunately the prefix string that identifies the location of the /boot/grub[2] directory will definitely be within the compressed part.
On modern systems, the gap between MBR and the start of the first partition is usually exactly 2047 blocks, to align the first partition to start at exactly 1 MiB into the disk. But older systems might have been partitioned with a version of fdisk that did not care about data alignment but instead tried to maintain DOS compatibility, positioning the beginning of partition at the beginning of a disk track (although the classic C/H/S disk geometry has long been just a fiction maintained by the disk firmware). In these cases, the gap between MBR and the start of the first partition can be much smaller. So, to maximize compatibility, the grub-install will need to embed the absolute minimum number of essential GRUB modules together with the core image, to minimize the size of the embedded code. For other relevant limits resulting from PC hardware and BIOS implementation, see GRUB documentation: i386-pc is considered a "heavily limited platform" in this regard.
On a simple RedHat/Debian installation on a MBR-based disk, with /boot as a separate partition that's the first partition on the disk, the typical set of embedded modules would be:biosdisk.mod to use BIOS functions for disk access
part_msdos.mod to understand the MBR partition table
whatever module(s) are required to support the filesystem of the /boot partitionAt minimum (if the /boot partition is initialized as an ext2 filesystem), the required GRUB modules for ext2 filesystem support will be ext2.mod and fshelp.mod. This is a practical configuration that will probably produce one of the smallest embedded code sizes achievable with modern GRUB on i386-pc architecture.
If the GRUB directory is named /grub on a separate /boot filesystem, and /boot is the first partition on the disk, the embedded prefix string will typically be (,msdos1)/grub. Note that the GRUB disk identifier is missing: this means "use the same disk the BIOS read the MBR from". The msdos1 indicates the first MBR-style partition on the disk, and /grub is simply the path of the /boot/grub directory starting from the root of the /boot filesystem.
And so, using only the code embedded in the MBR gap or the bios-boot partition, GRUB will have the capability to read normal.mod at (,msdos1)/grub/i386-pc/normal.mod using BIOS for disk support and the filesystem metadata to find the right blocks. After that, the configuration file will be read from (,msdos1)/grub/grub.cfg respectively.
It is also possible to embed e.g. ahci.mod and search_fs_uuid.mod together with the GRUB core image to give GRUB the capability to access AHCI SATA controllers directly and to identify the right partition/filesystem by UUID, but the ahci.mod is more than 3x the size of biosdisk.mod, which makes hitting the image size limits all the more likely.What is proper way to update the bootloader code in the mbr/bios-boot partition when location of /boot changes"?The only practical answer is "re-write the embedded bootloader code by running grub[2]-install again". When you do so, make sure you have the new /boot mounted as /boot, and if necessary, supply the /boot/grub/device.map file with contents appropriate to what the system configuration will be at the next boot.
On Debian and derivatives like Ubuntu and Mint, the package management system remembers the installation target device for the i386-pc version of GRUB. You can view this information with sudo debconf-show grub-pc, and update it with sudo dpkg-reconfigure grub-pc.
RedHat doesn't seem to have a similar feature in their packaging.
RedHat and derivatives either don't upgrade the embedded boot code.
For comparison, on x86_64-efi GRUB architecture, there is usually no size restrictions to stop you from embedding all the available GRUB modules into the grubx64.efi file, resulting a single UEFI binary that can be signed for Secure Boot and will never need to load any executable code for extra functionality. In practice, this guarantees that as long as the system can read grubx64.efi, all the GRUB normal-mode command-line functionality will be available even if the /boot/grub[2] directory is completely destroyed.
|
Grub2 systems hard-code the location of stage2 files. This info is stored in the bootloader partition. I understand that grub-install will write this and more.
My question is how does grub2-install figure out where the /boot directory (it's own partition) happens to be. grub-mkconfig can figure this out, however, it does not appear that grub-install invokes grub-mkconfig.
I'd really like an in-depth explanation of how this is figured out.
Bottom line question is: "What is proper way to update the bootloader code in the mbr/bios-boot partition when location of /boot changes"?
Pointers to official documentation or wikis would be appreciated.
|
Moving /boot, how to update grub to find new location /boot/grub2/i386-pc/{core,boot}.img
|
Found the solution just now by running:
grep -rni "1280x720,1280x800,auto" / 2>/dev/nullwhich gave:
/etc/default/grub.d/kali-themes.cfg:2:GRUB_GFXMODE="1280x720,1280x800,auto"Commenting this GRUB_GFXMODE line in /etc/default/grub.d/kali-themes.cfg worked.
|
I uncommented /etc/default/grub and changed to following:
GRUB_GFXMODE=2560x1440x32Then, ran sudo update-grub without issues.
Now, the /boot/grub/grub.cfg still contains:
...
if loadfont $font ; then
set gfxmode=1280x720,1280x800,auto
load_video
...As expected, the resolution was 1280x720.
Before someone asks:I didn't touch /boot/grub/grub.cfg so far. Only cated it.
Modifying any other variable like GRUB_TIMEOUT in works correctly.
2560x1440 instead of 2560x1440x32 didn't work either.
Adding GRUB_GFXPAYLOAD_LINUX=keep in /etc/default/grub got updated in /boot/grub/grub.cfg didn't help.
2560x1440 is my native resolution as confirmed by xrandr and works fine. grub also is fine with it as evident below.The only thing that currently works is modifying /boot/grub/grub.cfg on previously mentioned line:
...
if loadfont $font ; then
set gfxmode=2560x1440x32,auto
load_video
...TLDR: update-grub ignores GRUB_GFXMODE when it's updating /boot/grub/grub.cfg.
Is there a way to get verbose output when running update-grub?
I am on kali-linux/Debian dual booted with Windows 11.
|
update-grub ignoring GRUB_GFXMODE only
|
I now managed to determine the problem on my own: I had chosen the wrong partition table type. If you want to install an OS, always partition it as MBR (called „msdos“ in GParted). Now everything works fine and I can start everything even if choosing the same drive in the UEFI.
|
I am running Linux Mint 19.1 on a Samsung 860 EVO 500 GB (dev/sdb) along with Windows 10 on it and recently added a Crucial MX500 1TB (dev/sda) to try out and use more distros, both of them are partitionated. After that installing GRUB on the MX500 failed while installing the other distros (Kali and Parrot), I tried running
sudo update-grubwhich returned the following errors:
/usr/sbin/grub-probe: error: cannot find a GRUB drive for /dev/sda1. Check your device.map.
Found Kali GNU/Linux Rolling (kali-rolling) on /dev/sda1
/usr/sbin/grub-probe: error: cannot find a GRUB drive for /dev/sda1. Check your device.map.
/usr/sbin/grub-probe: error: cannot find a GRUB drive for /dev/sda1. Check your device.map.
/usr/sbin/grub-probe: error: cannot find a GRUB drive for /dev/sda1. Check your device.map.
/usr/sbin/grub-probe: error: cannot find a GRUB drive for /dev/sda3. Check your device.map.
Found Parrot 4.5 (4.5) on /dev/sda3
/usr/sbin/grub-probe: error: cannot find a GRUB drive for /dev/sda3. Check your device.map.Mint and Windows were detected with no errors being returned. The GRUB manual page indeed suggested editing device.map (https://www.gnu.org/software/grub/manual/grub/html_node/Device-map.html), which I do not know how to do (and I also could not find the file in /boot/grub/, it does not appear to be present in GRUB 2 anymore), I also did not understand the instructions at https://www.gnu.org/software/grub/manual/grub/html_node/Device-map.html. I also searched various forums, which e.g suggested deleting grub.cfg and let it be regenerated by updating grub again or running
sudo grub-mkdevicemapAll of this did not work.
A comment asked for the output of lsblk, so here it is:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 157,2M 1 loop /snap/brave/58
loop1 7:1 0 91,1M 1 loop /snap/core/6531
loop2 7:2 0 152,7M 1 loop /snap/brave/44
loop3 7:3 0 34,8M 1 loop /snap/gtk-common-themes/1122
loop4 7:4 0 155,5M 1 loop /snap/brave/57
loop5 7:5 0 89,3M 1 loop /snap/core/6673
loop6 7:6 0 34,6M 1 loop /snap/gtk-common-themes/818
loop7 7:7 0 91M 1 loop /snap/core/6405
loop8 7:8 0 35,3M 1 loop /snap/gtk-common-themes/1198
sda 8:0 0 931,5G 0 disk
├─sda1 8:1 0 326G 0 part
├─sda2 8:2 0 31,3G 0 part
├─sda3 8:3 0 195,3G 0 part
└─sda4 8:4 0 15,9G 0 part
sdb 8:16 0 465,8G 0 disk
├─sdb1 8:17 0 549M 0 part
├─sdb2 8:18 0 239,8G 0 part
├─sdb3 8:19 0 1K 0 part
└─sdb5 8:21 0 225,5G 0 part /
sdc 8:32 0 931,5G 0 disk
└─sdc1 8:33 0 931,5G 0 part sdc is my HDD, no OS installed there. sdb2 is Windows, sdb5 is Mint.
|
Failed finding GRUB drives of recently installed distros on another drive, edit device.map?
|
Ok I installed ntfs-3g and ran o
os-prober. It detected Windows.
|
I installed Arch recently (as in, yesterday). I was able to successfully install Grub in the EFI system Partition with grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=grub --recheck, os-prober and grub-mkconfig -o /boot/grub/grub.cfg.
After booting, though, I had two issues: First, I wanted grub to boot linux and not linux-lts kernel by default and second, I wanted it to select Windows by default and a timeout of 1s.
In the /boot/grub/grub.cfg file, I replaced three instances of linux-lts with linux in the first menuentry.
In the /etc/default/grub file, I set GRUB_DEFAULT as 'Windows Boot Manager on (/dev/nvme0n1p1)' and GRUB_TIMEOUT as 1.
When I ran grub-mkconfig -o /boot/grub/grub.cfg, it did not list Windows 10. Even when I ran os-prober, no results were shown.
On rebooting, Windows entry was not shown but timeout was 1s. So, what should I do? Thank you!
|
os-prober Doesn't Detect Windows 10 in Archlinux [duplicate]
|
By mistake I ran this command grub2-mkconfig -o /etc/default/grub this replaced /etc/default/grub file with /boot/grub2/grub.cfg. So I manually changed /etc/default/grub to:
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet"
GRUB_DISABLE_RECOVERY="true"and now it works fine.
|
I am using centos7 when I run command sudo grub2-mkconfig -o /boot/grub2/grub.cfg I get error /etc/default/grub: line 60: terminal_output: command not found
The lines after 60 of /etc/default/grub file are:
terminal_output console
if [ x$feature_timeout_style = xy ] ; then
set timeout_style=menu
set timeout=5
else
set timeout=5
fi
# END /etc/grub.d/00_header ###
|
/etc/default/grub: line 60: terminal_output: command not found [closed]
|
The description for package centos-release-openstack-xena.noarch reads:yum Configs and basic docs for OpenStack as delivered via the CentOS Cloud SIG.The fact that the package name has the .noarch suffix suggests there is nothing directly bootable in this package, as it means the contents are processor-architecture independent, i.e. only scripts, documentation and/or data.
The name xena also does not refer to Xen as such: it is the release codename of the October 2021 release of OpenStack.
Installing centos-release-openstack-xena.noarch is but the first preparatory step in installing OpenStack. If that's what you are planning, then you should start reading the OpenStack installation guide. You are now in position to begin installing the various OpenStack component services.
But if you are looking for the virtualization hypervisor named Xen, then you have installed a wrong package.
Note that RHEL/CentOS 8 has no support for Xen PV or PVH modes at all, as RedHat favors KVM over Xen. You could run CentOS 8's standard kernel in HVM mode, but I've understood that would probably be less efficient than the PV/PVH modes. Or you could install kernel-ml from ElRepo; that would allow you to run CentOS 8 within Xen, but would be a necessary but not sufficient step in setting up a CentOS 8-based Xen host.
|
Linux localhost.localdomain 4.18.0-394.el8.x86_64 #1 SMP Tue May 31 16:19:11 UTC 2022 x86_64 x86_64 x86_64 GNU/Linuxgrub2-mkconfig (GRUB) 2.03On my centos8, I have installed centos-release-openstack-xena.noarch
But I cannot boot into Xen, please help.
Theoretically, after installing Xen, I should only run
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfgAs my /etc/grub.d has a linux_xen file and antoher large number of files hanging there:
[root@localhost ~]# ls /etc/grub.d/
00_header 01_users 10_linux 11_linux_xen 20_linux_xen 30_os-prober 35_fwupd 41_custom
00_tuned 08_fallback_counting 10_reset_boot_success 12_menu_auto_hide 20_ppc_terminfo 30_uefi-firmware 40_custom README(11_linux_xen is a symlink I created pointing to 20_linux_xen)
Unfortunately, grub.cfg will have nothing in the linux_xen section.
I added echo << EOF and EOF to the linux_xen file and I got some errors, but I wonder if debugging this complexity is the best way forward or if there is something simpler I can do.
/etc/grub.d/11_linux_xen file contents:#! /bin/sh
set -e# grub-mkconfig helper script.
# Copyright (C) 2006,2007,2008,2009,2010 Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB. If not, see <http://www.gnu.org/licenses/>.cat << EOF
prefix="/usr"
exec_prefix="/usr"
datarootdir="/usr/share". "$pkgdatadir/grub-mkconfig_lib"export TEXTDOMAIN=grub
export TEXTDOMAINDIR="${datarootdir}/locale"CLASS="--class gnu-linux --class gnu --class os --class xen"if [ "x${GRUB_DISTRIBUTOR}" = "x" ] ; then
OS="$(sed 's, release .*$,,g' /etc/system-release)"
else
OS="${GRUB_DISTRIBUTOR}"
CLASS="--class $(echo ${GRUB_DISTRIBUTOR} | tr 'A-Z' 'a-z' | cut -d' ' -f1|LC_ALL=C sed 's,[^[:alnum:]_],_,g') ${CLASS}"
fi# loop-AES arranges things so that /dev/loop/X can be our root device, but
# the initrds that Linux uses don't like that.
case ${GRUB_DEVICE} in
/dev/loop/*|/dev/loop[0-9])
GRUB_DEVICE=`losetup ${GRUB_DEVICE} | sed -e "s/^[^(]*(\([^)]\+\)).*/\1/"`
;;
esac# Default to disabling partition uuid support to maintian compatibility with
# older kernels.
GRUB_DISABLE_LINUX_PARTUUID=${GRUB_DISABLE_LINUX_PARTUUID-true}# btrfs may reside on multiple devices. We cannot pass them as value of root= parameter
# and mounting btrfs requires user space scanning, so force UUID in this case.
if ( [ "x${GRUB_DEVICE_UUID}" = "x" ] && [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] ) \
|| ( [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
&& [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ] ) \
|| ( ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
&& ! test -e "/dev/disk/by-partuuid/${GRUB_DEVICE_PARTUUID}" ) \
|| ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then
LINUX_ROOT_DEVICE=${GRUB_DEVICE}
elif [ "x${GRUB_DEVICE_UUID}" = "x" ] \
|| [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ]; then
LINUX_ROOT_DEVICE=PARTUUID=${GRUB_DEVICE_PARTUUID}
else
LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
fi# Allow overriding GRUB_CMDLINE_LINUX and GRUB_CMDLINE_LINUX_DEFAULT.
if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE}" ]; then
GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX_XEN_REPLACE}"
fi
if [ "${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}" ]; then
GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT}"
ficase x"$GRUB_FS" in
xbtrfs)
if [ "x${SUSE_BTRFS_SNAPSHOT_BOOTING}" = "xtrue" ]; then
GRUB_CMDLINE_LINUX="${GRUB_CMDLINE_LINUX} \${extra_cmdline}"
else
rootsubvol="`make_system_path_relative_to_its_root /`"
rootsubvol="${rootsubvol#/}"
if [ "x${rootsubvol}" != x ]; then
GRUB_CMDLINE_LINUX="rootflags=subvol=${rootsubvol} ${GRUB_CMDLINE_LINUX}"
fi
fi;;
xzfs)
rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
;;
esactitle_correction_code=linux_entry ()
{
os="$1"
version="$2"
xen_version="$3"
type="$4"
args="$5"
xen_args="$6"
if [ -z "$boot_device_id" ]; then
boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
fi
if [ x$type != xsimple ] ; then
if [ x$type = xrecovery ] ; then
title="$(gettext_printf "%s, with Xen %s and Linux %s (recovery mode)" "${os}" "${xen_version}" "${version}")"
else
title="$(gettext_printf "%s, with Xen %s and Linux %s" "${os}" "${xen_version}" "${version}")"
fi
replacement_title="$(echo "Advanced options for ${OS}" | sed 's,>,>>,g')>$(echo "$title" | sed 's,>,>>,g')"
if [ x"Xen ${xen_version}>$title" = x"$GRUB_ACTUAL_DEFAULT" ]; then
quoted="$(echo "$GRUB_ACTUAL_DEFAULT" | grub_quote)"
title_correction_code="${title_correction_code}if [ \"x\$default\" = '$quoted' ]; then default='$(echo "$replacement_title" | grub_quote)'; fi;"
grub_warn "$(gettext_printf "Please don't use old title \`%s' for GRUB_DEFAULT, use \`%s' (for versions before 2.00) or \`%s' (for 2.00 or later)" "$GRUB_ACTUAL_DEFAULT" "$replacement_title" "gnulinux-advanced-$boot_device_id>gnulinux-$version-$type-$boot_device_id")"
fi
echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-$version-$type-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
else
title="$(gettext_printf "%s, with Xen hypervisor" "${os}")"
echo "menuentry '$(echo "$title" | grub_quote)' ${CLASS} \$menuentry_id_option 'xen-gnulinux-simple-$boot_device_id' {" | sed "s/^/$submenu_indentation/"
fi
if [ x$type != xrecovery ] ; then
save_default_entry | grub_add_tab | sed "s/^/$submenu_indentation/"
fi if [ -z "${prepare_boot_cache}" ]; then
prepare_boot_cache="$(prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | grub_add_tab)"
fi
printf '%s\n' "${prepare_boot_cache}" | sed "s/^/$submenu_indentation/"
xmessage="$(gettext_printf "Loading Xen %s ..." ${xen_version})"
lmessage="$(gettext_printf "Loading Linux %s ..." ${version})"
sed "s/^/$submenu_indentation/" << EOF
echo '$(echo "$xmessage" | grub_quote)'
if [ "\$grub_platform" = "pc" -o "\$grub_platform" = "" ]; then
xen_rm_opts=
else
xen_rm_opts="no-real-mode edd=off"
fi
insmod ${module_loader}
insmod ${xen_loader}
${xen_loader} ${rel_xen_dirname}/${xen_basename} placeholder ${xen_args} \${xen_rm_opts}
echo '$(echo "$lmessage" | grub_quote)'
${module_loader} ${rel_dirname}/${basename} placeholder root=${linux_root_device_thisversion} ro ${args}
EOF
if test -n "${initrd}" ; then
# TRANSLATORS: ramdisk isn't identifier. Should be translated.
message="$(gettext_printf "Loading initial ramdisk ...")"
sed "s/^/$submenu_indentation/" << EOF
echo '$(echo "$message" | grub_quote)'
insmod ${module_loader}
${module_loader} --nounzip ${rel_dirname}/${initrd}
EOF
fi
sed "s/^/$submenu_indentation/" << EOF
}
EOF
}linux_list=
for i in /boot/vmlinu[xz]-* /vmlinu[xz]-* /boot/kernel-*; do
if grub_file_is_not_garbage "$i"; then
basename=$(basename $i)
version=$(echo $basename | sed -e "s,^[^0-9]*-,,g")
dirname=$(dirname $i)
config=
for j in "${dirname}/config-${version}" "${dirname}/config-${alt_version}" "/etc/kernels/kernel-config-${version}" ; do
if test -e "${j}" ; then
config="${j}"
break
fi
done
if (grep -qx "CONFIG_XEN_DOM0=y" "${config}" 2> /dev/null || grep -qx "CONFIG_XEN_PRIVILEGED_GUEST=y" "${config}" 2> /dev/null); then linux_list="$linux_list $i" ; fi
fi
done
if [ "x${linux_list}" = "x" ] ; then
exit 0
fifile_is_not_sym () {
case "$1" in
*/xen-syms-*)
return 1;;
*)
return 0;;
esac
}xen_list=
for i in /boot/xen*; do
if grub_file_is_not_garbage "$i" && file_is_not_sym "$i" ; then xen_list="$xen_list $i" ; fi
done
prepare_boot_cache=
boot_device_id=title_correction_code=machine=`uname -m`case "$machine" in
i?86) GENKERNEL_ARCH="x86" ;;
mips|mips64) GENKERNEL_ARCH="mips" ;;
mipsel|mips64el) GENKERNEL_ARCH="mipsel" ;;
arm*) GENKERNEL_ARCH="arm" ;;
*) GENKERNEL_ARCH="$machine" ;;
esac# Extra indentation to add to menu entries in a submenu. We're not in a submenu
# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
submenu_indentation=""is_top_level=truewhile [ "x${xen_list}" != "x" ] ; do
list="${linux_list}"
current_xen=`version_find_latest $xen_list`
xen_basename=`basename ${current_xen}`
xen_dirname=`dirname ${current_xen}`
rel_xen_dirname=`make_system_path_relative_to_its_root $xen_dirname`
xen_version=`echo $xen_basename | sed -e "s,.gz$,,g;s,^xen-,,g"`
if [ -z "$boot_device_id" ]; then
boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
fi
if [ "x$is_top_level" != xtrue ]; then
echo " submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
fi
if ($grub_file --is-arm64-efi $current_xen); then
xen_loader="xen_hypervisor"
module_loader="xen_module"
else
if ($grub_file --is-x86-multiboot2 $current_xen); then
xen_loader="multiboot2"
module_loader="module2"
else
xen_loader="multiboot"
module_loader="module"
fi
fi
while [ "x$list" != "x" ] ; do
linux=`version_find_latest $list`
gettext_printf "Found linux image: %s\n" "$linux" >&2
basename=`basename $linux`
dirname=`dirname $linux`
rel_dirname=`make_system_path_relative_to_its_root $dirname`
version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
alt_version=`echo $version | sed -e "s,\.old$,,g"`
linux_root_device_thisversion="${LINUX_ROOT_DEVICE}" initrd=
for i in "initrd.img-${version}" "initrd-${version}.img" "initrd-${version}.gz" \
"initrd-${version}" "initramfs-${version}.img" \
"initrd.img-${alt_version}" "initrd-${alt_version}.img" \
"initrd-${alt_version}" "initramfs-${alt_version}.img" \
"initramfs-genkernel-${version}" \
"initramfs-genkernel-${alt_version}" \
"initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
"initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}" ; do
if test -e "${dirname}/${i}" ; then
initrd="$i"
break
fi
done
if test -n "${initrd}" ; then
gettext_printf "Found initrd image: %s\n" "${dirname}/${initrd}" >&2
else
# "UUID=" magic is parsed by initrds. Since there's no initrd, it can't work here.
if [ "x${GRUB_DEVICE_PARTUUID}" = "x" ] \
|| [ "x${GRUB_DISABLE_LINUX_PARTUUID}" = "xtrue" ]; then linux_root_device_thisversion=${GRUB_DEVICE}
else
linux_root_device_thisversion=PARTUUID=${GRUB_DEVICE_PARTUUID}
fi
fi if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
linux_entry "${OS}" "${version}" "${xen_version}" simple \
"${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}" submenu_indentation="$grub_tab$grub_tab"
if [ -z "$boot_device_id" ]; then
boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
fi
# TRANSLATORS: %s is replaced with an OS name
echo "submenu '$(gettext_printf "Advanced options for %s (with Xen hypervisor)" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
echo " submenu '$(gettext_printf "Xen hypervisor, version %s" "${xen_version}" | grub_quote)' \$menuentry_id_option 'xen-hypervisor-$xen_version-$boot_device_id' {"
is_top_level=false
fi linux_entry "${OS}" "${version}" "${xen_version}" advanced \
"${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}" "${GRUB_CMDLINE_XEN} ${GRUB_CMDLINE_XEN_DEFAULT}"
if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
linux_entry "${OS}" "${version}" "${xen_version}" recovery \
"single ${GRUB_CMDLINE_LINUX}" "${GRUB_CMDLINE_XEN}"
fi list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
done
if [ x"$is_top_level" != xtrue ]; then
echo ' }'
fi
xen_list=`echo $xen_list | tr ' ' '\n' | fgrep -vx "$current_xen" | tr '\n' ' '`
done# If at least one kernel was found, then we need to
# add a closing '}' for the submenu command.
if [ x"$is_top_level" != xtrue ]; then
echo '}'
fiecho "$title_correction_code"EOFError message generated when running grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg :
[root@localhost ~]# grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
Generating grub configuration file ...
losetup: /dev/nvme0n1p3: failed to use device: No such device
/etc/grub.d/11_linux_xen: line 20: make_system_path_relative_to_its_root: command not found
/etc/grub.d/11_linux_xen: line 20: make_system_path_relative_to_its_root: command not found
/etc/grub.d/11_linux_xen: line 20: grub_get_device_id: command not found
/etc/grub.d/11_linux_xen: line 20: gettext_printf: command not found
/etc/grub.d/11_linux_xen: line 20: gettext_printf: command not found
/etc/grub.d/11_linux_xen: line 20: grub_quote: command not found
/etc/grub.d/11_linux_xen: line 20: grub_quote: command not found
/etc/grub.d/11_linux_xen: line 20: gettext_printf: command not found
/etc/grub.d/11_linux_xen: line 20: grub_quote: command not found
/etc/grub.d/11_linux_xen: line 20: gettext_printf: command not found
/etc/grub.d/11_linux_xen: line 20: grub_quote: command not found
/etc/grub.d/11_linux_xen: line 20: prepare_grub_to_access_device: command not found
/etc/grub.d/11_linux_xen: line 20: grub_add_tab: command not found
/etc/grub.d/11_linux_xen: line 20: gettext_printf: command not found
/etc/grub.d/11_linux_xen: line 20: gettext_printf: command not found
/etc/grub.d/11_linux_xen: line 20: grub_quote: command not found
/etc/grub.d/11_linux_xen: line 20: grub_quote: command not found
/etc/grub.d/11_linux_xen: line 158: syntax error near unexpected token `}'This question was also published at: https://xcp-ng.org/forum/topic/6113/booting-into-xen-with-grub2-mkconfig-2-03-on-centos8-x86_64
And: https://forums.centos.org/viewforum.php?f=54
|
Booting into Xen with grub2-mkconfig 2.03 on centos8 x86_64
|
I assume you are using Linux and pam. The delay is probably caused by pam_faildelay.so. Check your pam configuration in /etc/pam.d using pam_faildelay, e.g:
# Enforce a minimal delay in case of failure (in microseconds).
# (Replaces the `FAIL_DELAY' setting from login.defs)
# Note that other modules may require another minimal delay. (for example,
# to disable any delay, you should add the nodelay option to pam_unix)
auth optional pam_faildelay.so delay=3000000To change the time adjust the delay parameter. If you want to get rid of the delay you can delete/comment the complete line.
Another source for the delay may be pam_unix.so. To disable the delay caused by pam_unix.so add the nodelay parameter, and optionally add a line calling pam_faildelay.so to add a (variable) delay instead, e.g.:
auth optional pam_faildelay.so delay=100000
|
After entering an incorrect password at a login prompt, there s an approximately 3-second delay. How can I change that on a Linux system with PAM?
|
How does one change the delay that occurs after entering an incorrect password?
|
One might easily think that users is meant to be assigned to every non-daemon user, but that's not the case. Remember that groups are a mean to control permissions...if that were to be the case wouldn't belonging to users be meaningles? Imagine trying to make use of that group: to keep a file that belongs to group users private, you would need to assign it the same permission bits to the "group" as you would to "others", as every user would be part of that group. Redundant and useless, if not plain annoying.
In reality, the users group exists just to be assigned to users which don't need to belong in any other group, as far as permissions are concerned. It basically exists just because every user must be at least part of a primary group (which you can find in /etc/passwd)...think of users like a "fallback", if no group is assigned to an user. (the useradd utility actually uses it as a fallback, if no group is given and homonym groups are disabled)
For this very same reason, you will find that the users group does not usually get any particular permission on the filesystem: no administrator will ever create a file which is owned by the users group, (if he wanted to allow any user to manipulate a file, he would instead use chmod o+rwx). So, it doesn't matter if you belong to that group or not, it will not give you any special permissions...that's why, unless you have no other group you're being assigned to, there's absolutely no need to assign an user to it (its insignificance, permission-wise, is very similar to that of nogroup).
As for the other group, i don't see it neither in my fresh CentOS 7 installation nor in my Ubuntu 14, so i'm guessing the document you read refers to the other portion of the Discrectionary Access Control bits (the last octal digit you can edit with chmod), or a group created and used by some application...so, asking for the reason for its existence is like asking why the group "www-data", created by nginx, exists: it just depends on what the application that created the group wants to do with it.
|
There is a proprietary document about system hardening/security standard stating that group users, nogroup, other, and some other groups should not contain any user except system administrators. I've found an explanation about nogroup group here. What about the users and other groups? What are they for? Why regular (non-administrator) users should not be member of these groups?
|
What are the groups 'users' and 'other' for?
|
Actually, SELinux seems to allow such configurations:
From the first Howto:This time, you will see all processes on the system regardless of the domain they are in. When in sysadm_t domain, you have access to other domains which the user_t domain does not.From the second Howto:The third line allows staff_t to run ps and see processes in the unprivileged user domains. staff_t is able to run ps and see everything in user_t and other user domains if any, whereas user_t can not.
|
Is it possible to configure process hiding for certain user groups under a linux system?
For example: Users from group X should not see processes owned by users from group Y in ps/top or under /proc.
Is it possible to configure such a setup with SELinux?
(I vaguely remember a similar feature in the funny grsecurity patch set - but IIRC, it was more generic - and besides, I want to configure a stock linux distro without having to maintain a custom kernel.)
Edit: For better illustration, Solaris 10 has a similar feature. The example is not that generic, but one can configure that a user or some users can only see information of their own processes in ps etc.
|
Hide processes from other users based on groups (under Linux)?
|
The purpose is to prevent ordinary users from running the su command (su is similar to sudo, the difference being that sudo executes one command, su starts a new session as a new user, which lasts until that user runs exit)
The default mode of su is 4755 or rwsr-xr-x, the "s" means that the command is set-UID (which means that it always runs as the user who owns it, rather than the user who happens to execute it. In this case su is owned by root, so it always runs with root privileges)
su has its own security measures in place to ensure that the user who executes it has authority to become another user (typically by asking for the other user's password), but it's conceivable that there would be a security vulnerability in su that would allow an attacker to somehow convince it to do something else without authority.
By changing the mode to 4750, it prevents ordinary users (users other than root and those in the sudo group) from even reading or executing it in the first place, so an attacker would need to either change the ownership of that file, or change the mode of the file, or change their own effective UID/GID before they could even attempt to exploit this theoretical vulnerability in su.
The dpkg-statoverride command is useful in this instance because it directs the package manager to use those ownership/mode values for that file, even if it gets replaced by a newer version (i.e. via apt upgrade). In other words, it makes it more permanent than just a chown and chmod.
Here's a general-purpose tactic I recommend for this instance:
Whenever I'm tweaking configuration of su/sudo or any authentication component on a Linux/UNIX machine, I'll open up another ssh/putty session to that server and log in as the root user, and just leave that session open in another window. That way if I do screw something up and lock myself out, I've already got a login session where I can fix anything I broke.
|
I am reading an Ubuntu 14 hardening guide and this is one of the suggestions:It generally seems like a sensible idea to make sure that only users
in the sudo group are able to run the su command in order to act as
(or become) root: dpkg-statoverride --update --add root sudo 4750
/bin/su I looked up the dpkg-statoverride command but I still can’t figure out exactly what the command above is doing?
It seems to imply that Ubuntu 14 by default allows anyone to sudo. To test, I created a new user, logged in as that user, tried to sudo and it failed – which is good.
So what is the purpose of the suggestion above?
|
How to harden su with dpkg-statoverride?
|
So looking through the bugs for harden I found the following two bugs.https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=782978Subject: RM: harden -- RoQA; no longer useful
Date: Sun, 19 Apr 2015 20:12:06 -0400
The maintainer thinks it would be best for it to be removed:https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=760449Hi
I agree with you. I think we should consider to remove the package
altogether.
// OlaSo the answer seems to be that the maintainer didn't think it was useful or functional anymore.
I have never used the package, so I can't provide much beyond linking you to the correct bug reports.
|
These include all the harden packages listed in the Debian automatic hardening documentation (https://www.debian.org/doc/manuals/securing-debian-howto/ch-automatic-harden.en.html), including:harden
harden-tools
harden-servers
harden-clients
etc., etc.Confusingly, it appears that the suite's documentation package will be available for Debian Stretch (9.0), but none of the harden meta-packages are currently slated for that release either.
What gives? Are there alternative replacement packages that I overlooked? If so, what are they?It may be worth noting that I spent a great deal of time searching for the answer to this question online. There seems to be no information on this topic, and I've found nothing in the mailing lists, though I haven't search as thoroughly there.
All I have found is that the packages must have been available for Jessie at some point, but were later removed, as some Google queries still return dead links to Jessie package information pages.
The harden packages were a novice administrator's godsend, though I understand they were never the complete answer to securing a Debian server. Still, it is odd not seeing any explanation for their exclusion in Debian's newest releases.
|
Why is the "harden" suite of packages not available for Debian Jessie (8.0)?
|
When you're using the command-line through a serial port or other character-oriented device, you're doing so through a terminal (tty). Any programs connected to you through that terminal have a connection to that terminal via one or more open file descriptors (typically, their stdin, stdout, and stderr "files" at fd numbers 0, 1, and 2, respectively).
Terminals are actually very complex things that do far more than provide input characters to programs and receive output characters from them. The terminal also accepts commands from any program connected to it (see tcsetattr()). For example, the terminal's default input processing mode is to echo your keystrokes back to you and buffer up your input, allowing you edit the line before you hit ENTER to pass the results to the program. This mode can be changed by any connected program. For example, echoing can be turned on or off and line editing features can be disabled or enabled. ...There are a lot of options. Programs interacting with you through a terminal can also ask for the terminal window dimensions, allowing programs to properly format their output in your window.
A pseudoterminal (pty) is a sort of fake terminal that looks exactly like a terminal from the point of view of the program connected to it. But, instead of the other side being connected to a hardware device, it is connected to another program via a "pty master".
When sudo runs a child process in a separate pty, it creates a pty and pty master and connects the child process to the new pty instead of connecting it directly to the terminal that sudo is itself connected to. While the child process is still alive, sudo relays input, output, and control commands between the child process and sudo's own terminal via the master pty. But, when the child process terminates, sudo stops relaying and closes the pty master.
If the child process forks itself, those grandchildren inherit their parent's file descriptors, including connections to the tty or pty. If sudo had connected its child to your terminal directly, then the grandchildren would also be connected to your terminal, and they could continue to access your terminal even though their parent had terminated and sudo had exited too. But because sudo used a pty instead, and because the master pty was closed, any grandchildren will be unable to interact with your terminal after sudo terminates.
|
As a rule in the Debian 10 hardening guide, and various other audit guides of the Center for Internet Security (CIS), setting the use_pty sudoers option is recommended for the following rationale:Attackers can run a malicious program using sudo which would fork a background process that remains even when the main program has finished executing.In the sudoers man page, it is described that running a background process that retains access to the user's terminal after the main process has finished executing is no longer possible when the commands are run in a separate pseudo-terminal.
I don't really grasp the nuance here.
What does it mean to run the sudo command in a separate pseudo-terminal, and why is the background process attack no longer possible when this flag is set?
What other ramifications does setting use_pty have?
Thank you!
|
How does the use_pty sudoers option prevent a persistence attack?
|
Have a quick read of the more general Hardening Linux question over on Security Stack Exchange
It includes guidance on removal of weak services, maintenance of security, links to SANS guidance etc., and while it is for general Linux, 90% of it will be absolutely appropriate for Debian.
|
So I have thought a bit about hardening a Debian squeeze file & VPN server
lately.
Right now, we've placed the machine behind a firewall only allowing SSH connections from LAN, set a strong root password and installed unattended-upgrades to keep us fresh on those security fixes.
What more should we do?
|
Hardening debian?
|
Background
The primary reason this advice is given when dealing with security is that one of the key pillars in making something more secure is by reducing the "attack surface". That is if you remove paths into your system you're reducing your system's overall potential.
An analogy
When I try to explain why this is so crucial with respect to security I like to use the analogy of a house. If we were thinking of ways to make a house more secure we'd start with things that are obvious. Say the doors and windows. If we do not have a need to build the house with 10 doors, only 2 then it would make sense from a security perspective that the house with only 2 doors is potentially more secure then the house with 10.
The next thing we'd think about is the types of doors and how they're secured. Are they screen doors ore doors made of steel. How they're locked and various other features would go into the considerations of how to make them as well as the entire house "more" secure.
Applying the approach to security
The same things are going on with a system's security. So the removal of unnecessary accounts is just another step in improving a system's overall exposure potential, to being compromised. If these accounts are setup so that they do not allow direct logging in, or if they have 20 character passwords, then their potential has been diminished.
Further still if these accounts have been setup so that they're only allowed to be logged in from a local IP address on the LAN or by applying other methods to lock them down such as only being utilized over SSH, then their risk to being attacked has been reduced such that they're no longer deemed too vulnerable.
Key security concepts
Keep these thoughts in the back of your mind: Security is about balancing the tradeoffs of setting up a system so that you can use it in as safe a manner as possible, without jeopardizing the system to being used in manners that you do not wish it to be.
Security is like layers of an onion. We're trying to add as many as we can to thwart a would be attacker, so that they get tripped up, and give up in trying to compromise our system.Your other questionsQ1. Do these accounts include process and daemon accounts?Yes when the advice is given to secure/disable/remove accounts they're talking about both user and system accounts such as the ones used by daemons.
You wouldn't want to leave user accounts on a system for users that no longer need physical access to the system, nor would you want to leave accounts for daemons that have been disabled or have been removed.Q2. What security problems exist with unnecessary user accounts?As I described above. These accounts are a potential security risk that an attacker "could" use to gain access. However, their presence, if properly secured, is lowered dramatically.Q3. Can attackers damage systems with compromised unnecessary accounts?Only if they're able to gain access to these accounts. If these accounts have been configured so that directly logging into them is disallowed, and there are no daemons/services running under these accounts, then they're effectively very little to no risk from a security perspective.
|
It is recommended in hardening that unnecessary accounts be removed.Do these accounts include process and daemon accounts?
What security problems exist with unnecessary user accounts?
Can attackers damage systems with compromised unnecessary accounts?
|
unnecessary accounts in linux
|
Sounds like a huge pain to me. I don't think you're actually gaining anything in security, either, as those (a) can only be written as root, so already likely game over if someone can write to them; (b) likely load a bunch of shared libraries, which aren't being checked.
The sudoers manpage says the option "may be useful in situations where the user invoking sudo has write access to the command or its parent directory." I'm not sure who thought that setup would be a good idea, or for that matter how sudo does a checksum before exec w/o a race condition.
I suggest looking into a host-based IDS (e.g., samhain, tripwire, ...) instead. Those will attempt to quickly detect and report any tampering with system binaries (including shared libraries), regardless of whether anyone is attempting to sudo.
|
I'm asking myself whether system security substantially increases when I generate a security policy, i.e. sudoers file which contains one or more Cmnd_Alias definitions that enumerate all executable files prefixed by their SHA-2 checksums under directories such as /usr/bin, /usr/sbin etc.
Upon updating the system with packages from a trusted source I would then regenerate the security policy.
Any insights whether this is a good or bad idea?
|
Does it make sudo more secure when indexing all commands by their SHA-2 checksums?
|
This is in process. Going to http://wiki.debian.org/Hardening leads to http://wiki.debian.org/ReleaseGoals/SecurityHardeningBuildFlags, which leads to Raphael Hertzog's message to debian-devel-announce, on behalf of the dpkg developers.
See the para beginning
* dpkg-buildflags now returns hardening build flags by defaultSo, this feature may be in the next release.
|
I heard that every binary that comes with Ubuntu is protected with stack-smashing protection and possibly other gcc features to harden programs against common security threats. What about Debian? I couldn't find any definitive info on the Internet.
|
is stack-smashing protection on on Debian?
|
Security is a tradeoff. As an extreme example, a system powered off, disconnected, and encased in a block of concrete is very secure but completely useless. You decide on which security measures you're willing to pay for (reduced usability, actual dollars spent, etc.) by analyzing how likely a breach is to occur, and how much it'll cost.
Since this is apparently a machine dedicated to the task, I'd personally just stick it in a text file (or, stored only in memory were these more valuable passwords, like bank accounts) and do your step 1 [which you almost always should; turning off unused services is basically free].
If it's possible to drive a web browser running as a different user, I'd do that—web browsers have a huge attack surface. And of course make sure your browser security updates are applied.
BTW: You missed some hardening steps, like iptables. Also, turning off ICMP echo IMO doesn't really give you any security, but makes network troubleshooting annoying. (Anything behind your firewall able to ping it could also do an ARP ping instead, which it has to respond to for Ethernet to work. Or any number of other protocol pings to see it's up.)
|
I'm writing a webpage-monitoring program that, every hour, logs in to a website using Selenium and notifies me if the page has changed in a particular way. For example, this program can monitor my cell phone data usage and warn me if my usage is spiking. However, I'm concerned about having my plaintext password just sitting on a machine that's perpetually connected to the Internet.
Q: What is a responsible way to automate periodic website logins?
I've considered the following precautions, in order of increasing paranoid-ness:"Harden" the Linux distro -- turn off ping responses, CUPS, Java, SSH, Samba, and other unused services.
Encrypt the password on disk and hard-code the key in the program (like, use XOR to obfuscate the password a little).
Store the password only in RAM; that is, enter the password when I start the program. (So the program is always running; can't use cron)
Turn off the machine's network when the program isn't running using ifdown and ifup.
Use a timed electrical outlet to -- once an hour -- physically power up the machine, let it run for a few minutes, and power it down (say, using this Art Controller relay board).(BTW, I have the basic program working on a Raspberry Pi using Python and pyvirtualdisplay as described here, and I'm using Selenium because some websites of interest require JavaScript.)
|
How to securely automate periodic website logins
|
From the manual man 1 crontab:
If the /etc/cron.allow file exists, then you must be listed (one user per line)
therein in order to be allowed to use this command. If the /etc/cron.allow file
does not exist but the /etc/cron.deny file does exist, then you must not be listed
in the /etc/cron.deny file in order to use this command.If neither of these files exists, then depending on site-dependent configuration
parameters, only the super user will be allowed to use this command, or all users
will be able to use this command.If both files exist then /etc/cron.allow takes precedence. Which means that
/etc/cron.deny is not considered and your user must be listed in /etc/cron.allow in
order to be able to use the crontab.Regardless of the existance of any of these files, the root administrative user is
always allowed to setup a crontab. For standard Debian systems, all users may use
this command.I gave it try on Debian 7, and it is working exactly this way.
|
Almost 3 weeks that, in my downtime, I try to find out where the files cron.allow & cron.deny are located in debian7 distro. No way, it seems that by default they are not in the system.
'Just' for hardening purposes, I would have those files available in my system. My question is actually if I can just touch them and use them without have to make other configurations.
root@asw-deb:~# touch /etc/cron.allow
root@asw-deb:~# touch /etc/cron.denyOr if I may have to 'map' those files, maybee editing some cron configuration files, 'saying' where cron can find the two files I created.
Sorry if I sound a little nooby.
|
debian7 cron.allow & cron.deny files
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.