LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   blkid help needed (https://www.linuxquestions.org/questions/linux-newbie-8/blkid-help-needed-911255/)

rng 11-01-2011 08:37 AM

blkid help needed
 
I need help regarding following:

1. How can I get a tabulated output of blkid?

2. The command 'sudo blkid' gives details of all drives. How can I get output of only one device (say /dev/sda) with blkid? If I type 'sudo blkid /dev/sda' it does not produce any output and exits silently.

MensaWater 11-01-2011 08:59 AM

You'll have to explain what you mean by tabulated output - an example of what you want to see would help.

blkid shows you what type of device the block device (e.g. swap, filesystem) so unless you had formatted all of /dev/sda to be a filesystem or swap device it won't show you /dev/sda. It will show you partitions of sda (e.g. /dev/sda1, /dev/sda2) if you have made any of those and they are formatted to be swap or filesystem.

Also note that on occasion systems may not have a /dev/sda. For example I have an old Compaq RAID card in one server so it shows the RAID drive as /dev/cciss/c0d0 instead of /dev/sda as other systems using DELL PERC RAID cards do.

If you run df -h you'll see the devices that blkid is going to report on generally. Of course running blkid without arguments will also show you the devices. If you only want to see a list of devices you can run:
Code:

blkid | awk -F: '{print $1}'

kilgoretrout 11-01-2011 09:22 AM

Assuming you have more than one hard drive and you just want information on all the partitions on sda, then running:
Code:

blkid | grep /dev/sda
should print out only the info for partitions on sda.

rng 11-01-2011 10:47 AM

Thanks everyone for your help.

boot_info_script ( http://bootinfoscript.sourceforge.net/ ) produces following table which is very clear:

Quote:

Device UUID TYPE LABEL

/dev/sda1 AE9282BD92828A13 ntfs first-part
/dev/sda2 c806bc6c-ce7e-4110-ab62-a4d30fabcf74 ext4 sec-partition
/dev/sda3 066AFB216AFB0C65 swap
It is a proper aligned table but it is not coming properly on this post.
What command can be used to make this or similar output.

Regarding selecting only one device, I can easily understand the grep command: blkid | grep /dev/sda ; but that means blkid itself cannot be made to show all partitions of one device.

MensaWater 11-01-2011 11:47 AM

Apparently you didn't read what I wrote. The blkid command is not a disk parsing utility - it is a utility to identify what you have layed out on a given device as far as known types. Therefore it DOES show you /dev/sda1, /dev/sda2 & /dev/sda3 because you HAVE layed out filesystems on them. If does NOT show you /dev/sda because that is the entire disk not a specific device with a layout.

For example on a test system I see:
fdisk -l

Disk /dev/sda: 146.1 GB, 146163105792 bytes
255 heads, 63 sectors/track, 17769 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 65 522081 83 Linux
/dev/sda2 66 17769 142207380 8e Linux LVM

Disk /dev/sdb: 898.3 GB, 898319253504 bytes
255 heads, 63 sectors/track, 109214 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 109214 877261423+ 8e Linux LVM

Note that it shows /dev/sda1 has a Linux (filesystem) type so is likely a device as blkid understands it. It then shows /dev/sda2 is a Linunx LVM so /dev/sda2 is NOT a device as blkid understands it. However the logical volumes I created on the system in that second partition's VG (and the second disk's first partition, /dev/sdb1) ARE devices as understood by blkid so it shows me the LVs:

blkid
/dev/mapper/VolGroup00-LogVol05: TYPE="swap"
/dev/mapper/VolGroup00-LogVol04: UUID="c9794d8c-1d91-4e40-816a-0b2ce454db2f" TYPE="ext3"
/dev/mapper/VolGroup00-LogVol03: UUID="244edcb1-6716-43cb-bad6-1d9377123f88" TYPE="ext3"
/dev/mapper/VolGroup00-LogVol01: UUID="110ba6b5-bd1c-449c-868f-00734881ec7f" TYPE="ext3"
/dev/mapper/VolGroup00-lvopenv: UUID="52667549-cdd2-4dcc-b1c4-777501369aa1" TYPE="ext3"
/dev/mapper/VolGroup00-LogVol02: UUID="aa99e392-ad64-429a-9930-03fe0f2f796c" TYPE="ext3"
/dev/mapper/VolGroup00-LogVol00: UUID="1b342bc7-8d8d-4617-8d75-985183e1aa58" TYPE="ext3"
/dev/sda1: LABEL="/boot" UUID="77326fc1-39aa-47a0-bd64-502355f72c13" TYPE="ext3"
/dev/hda: LABEL="RHEL/5.4 x86_64 DVD" TYPE="iso9660"
/dev/VolGroup00/LogVol00: UUID="1b342bc7-8d8d-4617-8d75-985183e1aa58" TYPE="ext3"
/dev/VolGroup00/LogVol05: TYPE="swap"
/dev/mapper/vgvision-lvoracle: UUID="3f6580f6-381c-49c9-ba36-aa8e006f803c" TYPE="ext3"

Similarly if you were using software RAID (meta disks) those meta disks should show up in blkid output.

So if you are interested in finding out what is in partitions of a device you should use tools like fdisk or gparted. If you are interested in finding out what swap/filesystems devices exist then you use blkid on those.

If in fact all of your partitions on sda had filesystem or swap directly (not meta disks or LVs) then you could run:
blkid /dev/sda*

rng 11-01-2011 07:34 PM

Thanks for explaining. I read what you wrote earlier but could not understand.

'blkid /dev/sda*' is the command I needed. I works perfectly when I need info on one disk only (like external hard disk) and do not want other disks to be listed.

I am not able to understand LVM. I tried seeing other links on it, eg http://en.wikipedia.org/wiki/Logical...er_%28Linux%29. It seems a useful but complex feature. Simple partitioning is clearly understood and I currently stick to that.

MensaWater 11-02-2011 10:01 AM

Quote:

I am not able to understand LVM. I tried seeing other links on it, eg http://en.wikipedia.org/wiki/Logical...er_%28Linux%29. It seems a useful but complex feature. Simple partitioning is clearly understood and I currently stick to that.
I wasn't suggesting you use either LVM or Meta Disks but simply noting that blkid would read information for filesystems/swap devices configured on them as it does for partitions.

One CAN format an entire drive (/dev/sda) as a filesystem and usually would for an external drive as you have mentioned. That is why you can see it with blkid. If you run fdisk -l /dev/sda on that external drive you probably don't see any partitions.

Now that you mentioned it though: LVM has some benefits over partitioning:
1) You can combine multiple disks into a single VolGroup (VG - think of it as a logical disk).
With standard paritioning you can't have anything larger than a single disk.

2) You can add, remove, extend or reduce logical volumes (LVs - think of them as logical partitions) without having to worry about what other LVs are in place or where they are.
With standard partitioning if you needed to increase the size of say /dev/sda2 but already had an sda3 and sda4 you'd have to actually undo or resize sda3 and possibly sda4 depending on how much space you need in sda2. Also partition resizing on the fly is problematical.

3) There is no limit (or rather an extremely high limit) on the number of LVs you can have so long as you have space left in the VG.
With standard partitioning even when you use extended partitions there is a limit of 15 partitions total.

The thing that originally got me before I started using LVM was that conceptually it didn't make sense - My thought was "Why would you combine disks (into VGs) only to break them up again (into LVs)?" After a few months of using them I understood the benefits above and realized my thinking was limited by having been only used to partitions.

Many will tell you that for home use LVM is overly complex but for business use where storage needs change frequently it makes perfect sense. Even for home systems I'd use it as it really isn't that complex once you're used to it. If the reason you're using Linux is to learn new things I'd certainly encourage you to explore LVM.

rng 11-02-2011 11:59 AM

Thanks for a nice explanation. Just one question. If there is a LVM involving 2 physical hard disks and one of them fails, will the whole file-system get affected? Is it possible one may lose files on the remaining disk also since it was part of the larger system?

chrism01 11-02-2011 06:25 PM

You will lose it all, because the files are distributed as the LVM sees fit at the time and may even be spread across both disks. More importantly, the fs you create on the LVM is one fs, so if part goes missing, it can't run.
Either do frequent backups, or consider some sort of RAID under the VG or just go with RAID on its own.
Remember that the more complex you make a system, the harder it is to fix when it breaks...

Recommend you read up on partitions, filesystems, LVM & RAID carefully before committing to a given soln.
Try wikipedia as a starting pt, also http://tldp.org/HOWTO/LVM-HOWTO/ and http://www.linuxtopia.org/online_boo...ion/index.html.

Note that none of these techniques are a substitute for backups...

rng 11-02-2011 07:56 PM

Thanks. That really clarifies advantages and disadvantages of LVM. If you can similarly give a brief word on RAID also- can I set it up if I have 2-4 hard disks and the major advantage that I will get is automatic backup, so that even if one disk fails, the data can be recovered?

chrism01 11-03-2011 01:00 AM

As I said, start with wikipedia eg https://secure.wikimedia.org/wikipedia/en/wiki/RAID; consider RAID5 or RAID6.
As above, this is NOT a substitute for backups, just higher availability in in case of HW failure (which happens sooner or later).
The Linux built-in SW tool is mdadm http://linux.die.net/man/8/mdadm

MensaWater 11-03-2011 08:56 AM

Essentially the point in (most) RAID types is to protect your data. The two most commonly used are:

RAID1 = Mirroring = For each disk there is a second disk which has exactly the same data. With either disk failing everything still continues to run because it is all on the other disk. In this RAID level you only have half the usable space (e.g. if you have 4 disks then you'd only have the usable space of 2 because the other 2 would be mirrors.)

RAID5 = Striping with parity. The data is written with a parity check bit across all your disks. If you lose a single disk then you don't lose any data because it is presented by the parity and data bits that remain. The parity equates to one full disk but is spread across like the data. This means you have the effective usable space of N-1 disks. (e.g. if you have 4 disks then your effective usable space is 3 disks, if you have 7 disks then your effective usable space is 6 disks.)

Of course many will tell you not to use RAID5 because losing 2 disks can lose all your data so other strategies such as RAID 6 (which provides for 2 parity disks) or RAID 10 (which does striping and mirroring) exist but of course they use up more disks.

RAID is broken down into Software and Hardware types. The meta disks I spoke of earlier are the Linux software RAID implementation.

RAID is definitely something you should do to prevent first line failure. Backups is something you should definitely do to allow recovery whether you're doing RAID or not. If your server were to suddenly catch fire or get zapped by lightning it might not matter how many disks you had in it and a backup allow you to restore to a new system.

rng 11-03-2011 10:55 AM

Thanks for a clear and concise explanation of RAID and for the links. I am sure these will benefit others also.

chrism01 11-03-2011 09:04 PM

Quote:

If your server were to suddenly catch fire or get zapped by lightning it might not matter how many disks you had in it and a backup allow you to restore to a new system.
... and also fat fingering i.e. deleting the wrong stuff; RAID cannot help you there ... ;)


All times are GMT -5. The time now is 02:18 PM.