How can we detect in Linux a non-formatted disk is been put ?
Linux - HardwareThis forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How can we detect in Linux a non-formatted disk is been put ?
Hi,
I am working on:
SUSE Linux Enterprise Server 10 (ia64)
VERSION = 10
PATCHLEVEL = 2
According to my implementation I need to detect a non-formatted disk.
I have put two disk one having 5 partitions and the other one is non formatted both are SCSI disk.
Is there any command or way which could be implemented to easily differentiate between a formatted and non-formatted disk.
Any Pointers towards the answers will be welcomed and awaited.
Thanks in advance.
Exclusive way to find the diffrence between a formatted and a non formatted disk
It may be possible that formatted disk partitions are mounted or may not be mounted ,That is not what i am concerned in .
I want a command by which i can find if the disk is nonformatted
If I put n disk thay are detected in cat /proc/partitions along with the partions .
How will be a non-formatted disk shown in this case ,Will entry for non-formatted disk be there or not .
If the entry is not there, there must some way or the other which gives me a clear idea of the disk i have put is a non-formatted disk.
What makes a disk unformatted?, the absence of any format. If you manage to mount an ext3 disk in windows it will promise that this disk is unformatted, so despite linux recognizes many formats (ext2,ext3,reiser,nfs,fat16,fat32,ntfs,joliet etc.) any disk with a format other than those included in your kernel will be an "unformatted disk".
parted (or any grpahical gui for it "gparted, kparted, xparted...") will give you some clues about what you want to know.
should list all Drives in the system, their partitions, and the filesystem type.
If there are no partitions or filesystems then it will just list an empty dist
I think you can use the file command on a partition
Code:
it-lenny:~# file -s <device>
Code:
fdisk -l - Should list all drives and partitions no matter if they are formatted, unformatted, mounted or unmounted
Disk /dev/sda: 160.0 GB, 160000000000 bytes
255 heads, 63 sectors/track, 19452 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0e1069f4
Device Boot Start End Blocks Id System
/dev/sda1 * 1 851 6835626 83 Linux
/dev/sda2 852 19452 149412532+ 5 Extended
/dev/sda5 852 1181 2650693+ 82 Linux swap / Solaris
/dev/sda6 1182 19452 146761776 83 Linux
Disk /dev/sdb: 511 MB, 511705088 bytes
33 heads, 32 sectors/track, 946 cylinders
Units = cylinders of 1056 * 512 = 540672 bytes
Disk identifier: 0xf01cd10d
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 947 499696 6 FAT16
--
it-lenny:~# file -s /dev/sda1
/dev/sda1: Linux rev 1.0 ext3 filesystem data, UUID=70165487-7f4f-4a6c-9332-7d907b63976 (needs journal recovery) (large files)
it-lenny:~# file -s /dev/sda2
/dev/sda2: x86 boot sector; partition 1: ID=0x82, starthead 1, startsector 63, 5301387 sectors; partition 2: ID=0x5, starthead 254, startsector 5301450, 293523615 sectors
it-lenny:~# file -s /dev/sda5
/dev/sda5: Linux/i386 swap file (new style), version 1 (4K pages), size 662672 pages, no label, UUID=0-0-0-0-00
it-lenny:~# file -s /dev/sda6
/dev/sda6: Linux rev 1.0 ext3 filesystem data, UUID=24b1bd67-de9-4782-9644-a088a434c562 (needs journal recovery) (large files)
it-lenny:~# file -s /dev/sdb1
/dev/sdb1: x86 boot sector
Sorry I don't have any unformatted partitions to view, but fdisk -l would list the Drive info with no partitions under it.. or it would show unallocated space on a drive with free space
also looks like I'm due for a reboot for some journal maintenance .
Adjust "g" & "19" to values reasonably beyond your expectations.
B) I believe "x86 boot sector, code offset 0x48" indicates an unformatted partition;
while "x86 boot sector; partition 1: ..." is an extended partition.
Yes it's there & already installed -- it's just "hiding" in /sbin, which is no longer in the path of regular users, like fdisk & ifconfig.
Both of those used to be available for informational purposes w/o having to be root.
Anyway, I found blkid & tried it out, & it's definitely good to know about.
still can use em without being root, just have to specify the full path..
Code:
user@it-lenny:~$ /sbin/blkid -L
device fs_type label mount point UUID
-----------------------------------------------------------------------------------------------------------------------------------------
/dev/sda1 ext3 / 70165487-7f4f-4a6c-9332-07d907b63976
/dev/sda5 swap <swap>
/dev/sda6 ext3 /home 24b1bd67-0de9-4782-9644-a088a434c562
/dev/sdb1 vfat USB DISK /media/usbdrive 5CA6-6E33
Interestingly enough fdisk only showed the flash drive the regular user mounted, not the system drive.. so maybe just specifying the full path to the executable won't always cut it, even for just purely informational purposes.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.