Linux info about partitions

How do I view all available HDD’s/partitions?

I found a 6 GB IDE HDD in my basement. I want to plug it in and see what might be on it. The drive seems to be recognized in BIOS. I can’t find it in Ubuntu to view files, and Ubuntu is the only OS on that particular computer. I was wondering if Ubuntu has an equivalent to the Windows feature «My Computer», which lists all available drives/storage devices. Typically, My Computer shows C:, which can be opened to view all of your directories and files. At this point, it is very similar to Ubuntu’s Home Folder. How to view/select all available partitions of that drive or all available HDD’s without formatting or tampering with the contents in any way?

Use Gparted, but with care! This can be a dangerous tool. If you just look at the partitions it’s fine

df -h —human-readable is a nice, short way of doing it. (Point out any errors that I may have) Thanks! Best wishes to the future //Will

11 Answers 11

There are many ways but my favorite is lsblk . Here is a demonstration:

sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL 

That would show the following:

NAME FSTYPE SIZE MOUNTPOINT LABEL sda 111.8G ├─sda1 swap 121M [SWAP] └─sda2 ext4 111.7G / sdb 2.7T └─sdb1 ext4 2.7T xtreme sdc 3.7T └─sdc1 ext4 3.7T titan 
  • The name of the drive and the partitions it has.
  • The type of file system.
  • The size the whole drive has and the size each partition has.
  • The mount point and if available, the label for them.

You can play around with the options by first looking at the ones available with lsblk —help . I like lsblk because of the friendly way of showing the information if compared for example with fdisk or parted .

    to check which drives your system can see:

If your drive is in the list, you’ll be able to see what partitions are on the drive, like this:

Disk /dev/sda: 160.0 GB, 160041885696 bytes . Device Boot Start End Blocks Id System /dev/sda1 * 63 208844 104391 83 Linux /dev/sda2 208845 2313359 1052257+ 82 Linux swap / Solaris /dev/sda3 2313360 312576704 155131672+ 83 Linux 

Then create a directory somewhere and mount one of the partitions. For example, to mount a FAT32 partition located at dev/sda3 read-only into directory /media/my_test_mount you can do

sudo mount -t cifs -o ro /dev/sda3 /media/my_test_mount 

This approach gives you more control, as you can use different mount options, for example mount the partition read-only.

See man mount for details.

I second Luis in that lsblk(8) is probably the most straightforward and concise solution. It’s very easy to visualize what is there and gives you all of the information needed quickly:

sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL 

For your convenience, here is a list of all available columns that can be used.

Available columns: NAME device name KNAME internal kernel device name MAJ:MIN major:minor device number FSTYPE filesystem type MOUNTPOINT where the device is mounted LABEL filesystem LABEL UUID filesystem UUID RO read-only device RM removable device MODEL device identifier SIZE size of the device STATE state of the device OWNER user name GROUP group name MODE device node permissions ALIGNMENT alignment offset MIN-IO minimum I/O size OPT-IO optimal I/O size PHY-SEC physical sector size LOG-SEC logical sector size ROTA rotational device SCHED I/O scheduler name RQ-SIZE request queue size TYPE device type DISC-ALN discard alignment offset DISC-GRAN discard granularity DISC-MAX discard max bytes DISC-ZERO discard zeroes data 

To list the hard drives/disks, I use

Model: ATA Samsung SSD 850 (scsi) Disk /dev/sda: 250GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 256MB 255MB primary ext2 boot 2 257MB 120GB 120GB extended 5 257MB 120GB 120GB logical lvm Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/ubuntu--vg-swap_1: 8573MB Sector size (logical/physical): 512B/512B Partition Table: loop Number Start End Size File system Flags 1 0.00B 8573MB 8573MB linux-swap(v1) Model: Linux device-mapper (linear) (dm) Disk /dev/mapper/ubuntu--vg-root: 111GB Sector size (logical/physical): 512B/512B Partition Table: loop Number Start End Size File system Flags 1 0.00B 111GB 111GB ext4 

And then to list the partitions as other people have already suggested you can use:

Читайте также:  Kali linux блокировка экрана

Which will tell you the file system partition types

parted gives me the hardware information and lsblk gives me the partition information. Looks like what I needed. Too bad there’s no single command to document everything to support disaster recovery. Thank you!

Use the following command lines, that together will give you a good overview of the partitions (location, sizes, free space and mount points),

df -h sudo parted -ls sudo lsblk -f sudo lsblk -m 

If your terminal window is wide enough (for example 130 characters), you can combine the lsblk commands to

Nautilus (where you view your home folder) will show all mounted drives on the system. If the drive is recognized by the computer you can mount it and begin to use it.

Directions and information about mounting drives can be found here: https://help.ubuntu.com/community/Mount

The solution below is very easy, clear, a GUI approach and it shows you exactly what you have laid out on your HDD:

  1. Go to: «System tools» in your main launch list
  2. Launch «GParted»
  3. Enter your password (should be your log on password if you are the admin.) You will be shown your HDD layouts, partitions sizes and amounts used.
  4. Quit the GParted application

CAUTION: Do not change ANYTHING unless you know what you are doing!

(building on previous advise in regards to lsblk ).

For the lazy typist (and if you don’t need the sizes) you can use:

which is same as using -o NAME,FSTYPE,LABEL,MOUNTPOINT

NAME FSTYPE LABEL MOUNTPOINT sda └─sda1 ntfs TOSHIBA sdb └─sdb1 LVM2_member └─root-root (dm-0) ext4 / 

I have created some regex to help those who want to read this data into some application.

Читайте также:  Get all listening ports linux

To do that, The lsblk command it is more usefully when you use the «-P» command. Here a example:

$ lsblk -P -o KNAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL KNAME="sda" FSTYPE="" SIZE="80G" MOUNTPOINT="" LABEL="" MODEL="VBOX HARDDISK " KNAME="sda1" FSTYPE="" SIZE="243M" MOUNTPOINT="/boot" LABEL="" MODEL="" KNAME="sda2" FSTYPE="" SIZE="1K" MOUNTPOINT="" LABEL="" MODEL="" KNAME="sda5" FSTYPE="" SIZE="79.8G" MOUNTPOINT="" LABEL="" MODEL="" KNAME="dm-0" FSTYPE="" SIZE="79G" MOUNTPOINT="/" LABEL="" MODEL="" KNAME="dm-1" FSTYPE="" SIZE="768M" MOUNTPOINT="[SWAP]" LABEL="" MODEL="" KNAME="sr0" FSTYPE="" SIZE="1024M" MOUNTPOINT="" LABEL="" MODEL="CD-ROM " KNAME="sr1" FSTYPE="" SIZE="1024M" MOUNTPOINT="" LABEL="" MODEL="CD-ROM " 

You can read this output usign some regex like

/KNAME=\"(.*)\" FSTYPE=\"(.*)\" SIZE=\"(.*)\" MOUNTPOINT=\"(.)*\" LABEL=\"(.*)\" MODEL=\"(.*)\"/g 

If you don’t need the size of the partition, you can use the mount -l to

$ mount -l /dev/mapper/precise32-root on / type ext4 (rw,errors=remount-ro) proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) none on /sys/fs/fuse/connections type fusectl (rw) none on /sys/kernel/debug type debugfs (rw) none on /sys/kernel/security type securityfs (rw) udev on /dev type devtmpfs (rw,mode=0755) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620) tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755) none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880) none on /run/shm type tmpfs (rw,nosuid,nodev) /dev/sda1 on /boot type ext2 (rw) rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw) /vagrant on /vagrant type vboxsf (uid=1000,gid=1000,rw) 

And read it using some Regex like that

If you are doing that in node, you can convert the string into a array of occurrences using some code like

Источник

Command to show partition scheme

What is the command for looking at the partition scheme of the hard disk on Ubuntu? I know we can see the partition scheme in Gparted, but how can we run it on command line?

3 Answers 3

There are many possible ways. These three below should be the most common. The stuff after # on the command lines are comments explaining what each of them does, you don’t need to copy them.

lsblk

This is probably the most simple tool to get a quick overview of what partitions exist. Nested structures (e.g. disk > partition > LUKS container > LVM container > volume) are also nicely displayed as a tree. Runs as regular user, no sudo needed.

You get (amongst others) information about device name, size, type and mount point (if mounted). With the option -f it will show file system type, label and UUID.

It’s possible to specify a disk, partition or any similar device to only view information about that instead of listing everything.

lsblk # default info about all devices lsblk -f # file system info about all devices lsblk /dev/sda1 # default info about the /dev/sda1 partition and its children only lsblk -f /dev/sdb # file system info about the /dev/sdb disk and its children only 

See man lsblk for more info.

Читайте также:  Arch linux mirrors list

parted

parted is a more powerful command-line tool, similar to its GUI pendant GParted. It can also modify the partitioning layout. Note that this requires elevated privileges ( sudo ) to run.

It will show you information about your disk hardware (model, type, size, sector size, . ) as well as a detailed partition table including start and end positions, size, type, file system, flags, label, .

You can either list everything or specify a disk to print details about.

sudo parted -l # show info about all devices sudo parted /dev/sda print # show info about the /dev/sda disk only 

See man parted for more info.

fdisk

fdisk is very similar to parted . It is also able to make modifications, requires elevated privileges and shows basically the same information as well.

sudo fdisk -l # show info about all devices sudo fdisk -l /dev/sda # show info about the /dev/sda disk only 

See man fdisk for more info.

@WJAndrea Are you sure? I can’t confirm your statement on 16.04, for me both lsblk and sudo lsblk (or lsblk -f and sudo lsblk -f ) show exactly the same amount of information.

fdisk

gives the following output:

Disk /dev/sda: 931,5 GiB, 1000204886016 bytes, 1953525168 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x81fe91a0 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 821247 819200 400M 83 Linux /dev/sda2 821248 1953525167 1952703920 931,1G f W95 Ext'd (LBA) /dev/sda5 823296 391028735 390205440 186,1G 83 Linux /dev/sda6 391030784 1415032831 1024002048 488,3G 83 Linux /dev/sda7 1415034880 1451898879 36864000 17,6G 82 Linux swap / Solaris Disk /dev/sdb: 931,5 GiB, 1000204886016 bytes, 1953525168 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x81fe91a0 Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 1953523711 1953521664 931,5G 5 Extended /dev/sdb5 4096 629149695 629145600 300G 83 Linux /dev/sdb6 629151744 1258297343 629145600 300G 83 Linux 

lsblk

lsblk # apparently no sudo needed 
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 931,5G 0 disk ├─sda1 8:1 0 400M 0 part ├─sda2 8:2 0 1K 0 part ├─sda5 8:5 0 186,1G 0 part / ├─sda6 8:6 0 488,3G 0 part /home └─sda7 8:7 0 17,6G 0 part [SWAP] sdb 8:16 0 931,5G 0 disk ├─sdb1 8:17 0 1K 0 part ├─sdb5 8:21 0 300G 0 part /mnt/freeA └─sdb6 8:22 0 300G 0 part /mnt/freeB sr0 11:0 1 1024M 0 rom 

Источник

Оцените статью
Adblock
detector