37

After installing CentOS, I see several lines like /dev/mapper/centos_jackpc--11-swap and /dev/mapper/centos_jackpc--11-root when I issue fdisk -l.

What is the purpose of these? And why do they not show up for Ubuntu?

The full fdisk -l is shown here:

Disk /dev/sda: 250.0 GB, 250000000000 bytes
255 heads, 63 sectors/track, 30394 cylinders, total 488281250 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
Disk identifier: 0x000e3a37

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   287754239   143364096   8e  Linux LVM
/dev/sda3       287756286   434180095    73211905    5  Extended
/dev/sda5       287756288   434180095    73211904   83  Linux

Disk /dev/sdb: 4000.8 GB, 4000787030016 bytes
255 heads, 63 sectors/track, 486401 cylinders, total 7814037168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x6c03e282

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1              63  2147504935  1073752436+  83  Linux
Partition 1 does not start on physical sector boundary.

Disk /dev/mapper/rhel_jackpc-root: 104.9 GB, 104857600000 bytes
255 heads, 63 sectors/track, 12748 cylinders, total 204800000 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
Disk identifier: 0x00000000

Disk /dev/mapper/rhel_jackpc-root doesn't contain a valid partition table

Disk /dev/mapper/rhel_jackpc-swap: 41.9 GB, 41943040000 bytes
255 heads, 63 sectors/track, 5099 cylinders, total 81920000 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
Disk identifier: 0x00000000

Disk /dev/mapper/rhel_jackpc-swap doesn't contain a valid partition table
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Tosh
  • 699
  • 1
  • 6
  • 11

1 Answers1

46

The entries in /dev/mapper are LVM logical volumes. You can think of these as Linux's native partition type. Linux can also use other partition types, such as PC (MBR or GPT) partitions.

Your disk is divided in MBR partitions, one of which (/dev/sda2) is an LVM physical volume. The LVM physical volume is the single constituent of the volume group rhel_jackpc, which contains two logical volumes: root (which is your CentOS system partition) and swap (which is your CentOS swap partition).

Ubuntu is installed directly on an MBR partition, presumably /dev/sda5.

fdisk -l lists information about all the block devices that could contain MBR partitions (or GPT partitions in recent versions of fdisk). It's technically possible, albeit highly unusual and rather pointless, to have PC partitions inside an LVM logical volume, so fdisk -l looks there and reports that it doesn't find a partition table. This is normal.

On Ubuntu, you wouldn't see anything about the LVM logical volume if the volume group is not activated. Since Ubuntu isn't using any of the volumes, it wouldn't activate the volume group.

Whether to use PC partitions or LVM volumes for a Linux installation is often merely a matter of convenience. There are things you can't do with PC partitions, such as spread them on multiple disks, or simply resize them and move them around easily, or create snapshots with them, so an installation over LVM is a lot more flexible. But if you don't need this flexibility, you can install directly onto PC partitions.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • 14
    Note that the Linux device mapper is used for other things besides LVM (such as dm-crypt disk encryption), so files in `/dev/mapper` aren't *necessarily* LVM logical volumes. But these ones look like they are. (They follow the naming convention that LVM uses.) – Wyzard May 20 '15 at 02:06
  • Thanks Gilles for helping me to understand this. I confirmed Ubuntu resides on `/dev/sda5` using `df`. When you say "PC" I automatically think "Windows" - are MBR and GPT somehow more closely related to Windows than nix OSes? – Tosh May 20 '15 at 07:22
  • 1
    Wyzard, okay - so then, is there a way to make sure the two logical volumes `root` and `swap` are indeed from `/dev/sda2` (and not just by looking at how they are named)? – Tosh May 20 '15 at 07:24
  • 2
    @Tosh By “PC” I mean [PC](http://en.wikipedia.org/wiki/Personal_computer), not Windows. MBR and GPT partitions are what the boot firmware ([BIOS](http://en.wikipedia.org/wiki/BIOS) and [UEFI](http://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface)) understand respectively. Windows sticks with PC partition types because it only runs on PC (and a few ARM platforms but they don't have “native” partition types). Some unix systems (e.g. *BSD) use their own partition scheme on PC hardware, others (e.g. Linux) don't care. – Gilles 'SO- stop being evil' May 20 '15 at 11:50
  • 8
    @Tosh You can run `lsblk` to view the storage tree, or `vgs` and `lvs` to list volume groups and logical volumes. – Gilles 'SO- stop being evil' May 20 '15 at 11:51
  • Is it possible to further partition logical volumes inside `/dev/mapper`? – CMCDragonkai Jan 21 '16 at 07:20
  • @CMCDragonkai Not directly. It may be possible via a loop device, but what would be the point? – Gilles 'SO- stop being evil' Jan 21 '16 at 10:04
  • For example having 2 partitions that you want encrypted, but you don't want to have 2 different luks containers (in order to avoid 2x the encryption processing). – CMCDragonkai Jan 21 '16 at 15:31
  • @CMCDragonkai Ah, ok. Yes, you can do this. Expect to do some manual tweaking to your startup scripts however, distributions typically do a single scan of physical volumes so the outer PV would be scanned, then you'd be prompted for the encryption password, and then you need to add something to the boot scripts to rescan for the encrypted PVs that are now visible. It's easier to stick to native partitions containing encrypted/RAID volumes containing LVM volumes containing filesystems. – Gilles 'SO- stop being evil' Jan 21 '16 at 15:41
  • I can tweak the startup scripts. However are you saying you can partition the devices inside `/dev/mapper`? If so, does that mean I can just use `sgdisk` or equivalent on those devices (without the need of a loop device which would add performance overhead)? – CMCDragonkai Jan 22 '16 at 03:25
  • 1
    @Gilles How did you figure out the partition `/dev/sda2` is associated with the `rhel_jackpc` volume group? From the naming convention, perhaps? I guess `lsblk` would confirm this, but you didn't have the `lsblk` output to work with. – flow2k Feb 26 '19 at 00:43
  • 1
    @flow2k `/dev/sda2` is the only LVM physical volume. – Gilles 'SO- stop being evil' Feb 26 '19 at 07:51