/dev/mapper in fdisk

118,839

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.

Share:
118,839

Related videos on Youtube

Tosh
Author by

Tosh

Updated on September 18, 2022

Comments

  • Tosh
    Tosh over 1 year

    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
    
  • Wyzard
    Wyzard about 9 years
    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.)
  • Tosh
    Tosh about 9 years
    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
    Tosh about 9 years
    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)?
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' about 9 years
    @Tosh By “PC” I mean PC, not Windows. MBR and GPT partitions are what the boot firmware (BIOS and UEFI) 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'
    Gilles 'SO- stop being evil' about 9 years
    @Tosh You can run lsblk to view the storage tree, or vgs and lvs to list volume groups and logical volumes.
  • CMCDragonkai
    CMCDragonkai over 8 years
    Is it possible to further partition logical volumes inside /dev/mapper?
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 8 years
    @CMCDragonkai Not directly. It may be possible via a loop device, but what would be the point?
  • CMCDragonkai
    CMCDragonkai over 8 years
    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).
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 8 years
    @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.
  • CMCDragonkai
    CMCDragonkai over 8 years
    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)?
  • flow2k
    flow2k about 5 years
    @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.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' about 5 years
    @flow2k /dev/sda2 is the only LVM physical volume.