shell command returning an sg device size (Linux) - linux

I need a shell command that would return an sg device size for me.
I am searching for it over the Internet for almost two hours without any success.
I can do it by writing a program but there has to be a way to get it through a command! I simply cannot find it!
Unfortunatelly, on the dell server I work, sg_inq, and sginfo return Dell's PERC information, and not the device I try to get the information of.
I tried to use the smartctl but it returns a static (and not true) infomation about the device (SSD,) for the number of bytes it returns divided by 512 shows bigger number of sectors that I can access (sic!)
Any [shell command] hint would be greatly appreciated!

I am putting an answer here for anyone looking for it.
The ultimate way to either write own program or use smartctl (http://sourceforge.net/projects/smartmontools/files/smartmontools/6.0/) and call the following command:
#>./smartctl -a /dev/sdc
smartctl 6.0 2012-10-10 r3643 [x86_64-linux-2.6.18-274.18.1.el5] (local build)
Copyright (C) 2002-12, Bruce Allen, Christian Franke, www.smartmontools.org
Vendor: DELL
Product: PERC H710P
Revision: 3.13
User Capacity: 179,443,728,384 bytes [179 GB]
Logical block size: 512 bytes
Logical Unit id: --------------------------------
Serial number: --------------------------------
Device type: disk
Local Time is: Tue Sep 24 17:54:13 2013 EDT
Device does not support SMART
Error Counter logging not supported
Device does not support Self Test logging

use #fdisk -l /dev/sg2
or # parted -l /dev/sg2

Related

What do device (character special) file sizes mean?

Using ls -l normally results in a long listing that includes the file size...
-rw-r--r--# 1 user1 staff 881344 Sep 1 15:35 someFile.png
On macOS 10.13.5, and Ubuntu 20.04, character special (device) file sizes are very different...
crw------- 1 root wheel 31, 0 Aug 30 16:11 autofs
In this case, what does the "31, 0" mean?
what does the "31, 0" mean?
It's the major/minor numbers of character device.
See these:
https://unix.stackexchange.com/questions/97676/how-to-find-the-driver-module-associated-with-a-device-on-linux
https://www.ibm.com/support/knowledgecenter/linuxonibm/com.ibm.linux.z.lgdd/lgdd_c_udev.html
Read carefully the documentation of ls(1) then about inode(7)
31 is a major device number, 0 is a minor device number.
Remember that ls(1) would use stat(2) (you might check using strace(1)...), so read Advanced Linux Programming then syscalls(2)
Sometimes, ls might be some shell alias or function. So read documentation of GNU bash. Try also /bin/ls --help
On GNU Linux, read documentation of coreutils. And it is free software, you could download and study its source code !
On MacOSX, the operating system kernel might have different system calls.
Be however aware of udev (on Linux).

How can we change RAPL power limits in Haswell CPU?

I am trying to change the power limits defined in the RAPL registers of my system. It is a Haswell CPU.
I have tried two approaches:
Using the MSR regsiters:
I try to use the rdmsr (as root) command to read the contents of the 0x610 regsiter in which the power limits are defined. Then I am using the wrmsr command to write to it. I try to change the first bit of this register from 1 to 0 to unlock the power limits.
rdmsr -p0 0x610 returns: 8042828a001a8208
wrmsr -p0 0x610 0x0042828a001a8208 executes without any error message
Then i read the register again using: rdmsr -p0 0x610
It prints: 8042828a001a8208
As you can see, i am trying to change the first hexabit from 8 to 0. The rest is same. but it won't change the bit.
The other approach I tried to change the power limits was to edit the system powercap files. I migrate to the directory /sys/class/powercap/intel-rapl/intel-rapl:0
Here we have these two files:
-rwxr-xr-x 1 root root 4.0K Nov 21 15:45 constraint_0_power_limit_uw and
-rw-r--r-- 1 root root 4.0K Nov 21 15:42 constraint_1_power_limit_uw
As you can see I have changed the privileges of the first file. The first one has value 65000000 and the second one has value 81250000. i try to change the value of the first to (say) 62000000 but when I try to save it the file trows an FSync failed (E667)error. I unset Fsync using 'set nofsync' command but then it throw filesystem full error(E514) . I reduce my file consumption and even rebooted the system but then it throws E509.
What am I doing wrong? I need to manipulate the RAPL power limits to regulate my system's TDP. Is there any other way to change RAPL limits?
Please guide me. Thanks in advance.

Linux Major and Minor Number

I got to know that linux has major and minor number. But, now my question is, is there any command or way to find what are the major number and minor number being used for which device.
Thanks in advance.
ls -l will list it.
$ ls -l /dev/urandom
crw-rw-rw- 1 root root 1, 9 Sep 27 20:59 /dev/urandom
1 is the major number, 9 is the minor
you may try uname -a to list all the info. If you only need the kernel version, uname -r.
Majors and minors are documented here: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/devices.txt
But I don't know to what extend this still does apply. Especially minors are allocated dynamically today, AFAIK. I don't know if that follows any particular system.
If your device is /dev/sda1, then try:
stat /dev/sda1
You should get output looking like this:
File: ‘/dev/sda1’
Size: 0 Blocks: 0 IO Block: 4096 block special file
Device: 5h/5d Inode: 1217 Links: 1 Device type: 8,1
Access: (0660/brw-rw----) Uid: ( 0/ root) Gid: ( 6/ disk)
The "Device: 5h/5d" are the major and minor number respectively for the device.
Hope this helps.

What is the significance of the numbers in the name of the flush processes for newer linux kernels?

I am running kernel 2.6.33.7.
Previously, I was running v2.6.18.x. On 2.6.18, the flush processes were named pdflush.
After upgrading to 2.6.33.7, the flush processes have a format of "flush-:".
For example, currently I see flush process "flush-8:32" popping up in top.
In doing a google search to try to determine an answer to this question, I saw examples of "flush-8:38", "flush-8:64" and "flush-253:0" just to name a few.
I understand what the flush process itself does, my question is what is the significance of the numbers on the end of the process name? What do they represent?
Thanks
Device numbers used to identify block devices. A kernel thread may be spawned to handle a particular device.
(On one of my systems, block devices are currently numbered as shown below. They may change from boot to boot or hotplug to hotplug.)
$ grep ^ /sys/class/block/*/dev
/sys/class/block/dm-0/dev:254:0
/sys/class/block/dm-1/dev:254:1
/sys/class/block/dm-2/dev:254:2
/sys/class/block/dm-3/dev:254:3
/sys/class/block/dm-4/dev:254:4
/sys/class/block/dm-5/dev:254:5
/sys/class/block/dm-6/dev:254:6
/sys/class/block/dm-7/dev:254:7
/sys/class/block/dm-8/dev:254:8
/sys/class/block/dm-9/dev:254:9
/sys/class/block/loop0/dev:7:0
/sys/class/block/loop1/dev:7:1
/sys/class/block/loop2/dev:7:2
/sys/class/block/loop3/dev:7:3
/sys/class/block/loop4/dev:7:4
/sys/class/block/loop5/dev:7:5
/sys/class/block/loop6/dev:7:6
/sys/class/block/loop7/dev:7:7
/sys/class/block/md0/dev:9:0
/sys/class/block/md1/dev:9:1
/sys/class/block/sda/dev:8:0
/sys/class/block/sda1/dev:8:1
/sys/class/block/sda2/dev:8:2
/sys/class/block/sdb/dev:8:16
/sys/class/block/sdb1/dev:8:17
/sys/class/block/sdb2/dev:8:18
/sys/class/block/sdc/dev:8:32
/sys/class/block/sdc1/dev:8:33
/sys/class/block/sdc2/dev:8:34
/sys/class/block/sdd/dev:8:48
/sys/class/block/sdd1/dev:8:49
/sys/class/block/sdd2/dev:8:50
/sys/class/block/sde/dev:8:64
/sys/class/block/sdf/dev:8:80
/sys/class/block/sdg/dev:8:96
/sys/class/block/sdh/dev:8:112
/sys/class/block/sdi/dev:8:128
/sys/class/block/sr0/dev:11:0
/sys/class/block/sr1/dev:11:1
/sys/class/block/sr2/dev:11:2
You should also be able to figure this out by searching for those numbers in /proc/self/mountinfo, eg:
$ grep 8:32 /proc/self/mountinfo
25 22 8:32 / /var rw,relatime - ext4 /dev/mapper/sysvg-var rw,barrier=1,data=ordered
This has the side benefit of working with nfs as well:
$ grep 0:73 /proc/self/mountinfo
108 42 0:73 /foo /mnt/foo rw,relatime - nfs host.domain.com:/volume/path rw, ...
Note, the data I included here is fabricated, but the mechanism works just fine.

Get details of RAID configuration on Linux

How to get the details of RAID configuration in Linux ?
mdadm -D /dev/mdxx will give you detail of raid configuration.
cat /proc/mdstat will give detail about raid algorithm,level and chunk size etc .
This is real if this RAID is sofware....
In case of RAID hardware, you could type this command :
lspci -vv | grep -i raid
01:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 2208 [Thunderbolt] (rev 01)
Kernel driver in use: megaraid_sas
Kernel modules: megaraid_sas
If you're talking about a running array:
cat /proc/mdstat
If you're talking about the mdadm config file, it's usually in /etc or /etc/mdadm depending on the distribution you're running on. The following command should find it in any event:
find /etc -name '*mdadm*'
ETA: Also, I would strongly recommend that you carefully study the mdadm man page so that you are very familiar with that utility. Knowing that utility well will save your bacon at some point.
mdadm --detail /dev/md0
(or whatever /dev/mdXXX you are using)

Resources