Linux find boot partition

On which partition is my bootloader installed?

Where sda is the disk you want to check the partitions, one of them should be listed as boot partition, if you have more then 1 disk there can be other partitions marked as boot, the next logical disk is sdb followed by sdc , etc.

If you have more then a disk and more than 1 partition is marked as boot the booting will be determined by the selected boot device in your BIOS.

It depends on what you mean by installed. Grub places some files in the /boot directory, which usually is on the same partition as /. It also embeds its core image to the Master Boot Record of the drive, and the following several sectors that are not part of any partition, so in that sense, it is not installed to any partition, but rather to the whole disk.

You can check the output of df to see what partitions you have mounted where. If there is no entry for /boot, then it is part of the root filesystem.

Here is GUI way of doing it

1- Open Disks

enter image description here

2 — Click on each partition

See the partition type . If the partition is bootable it will be marked as Bootable .

enter image description here

The bootloader

BIOS mode alias CSM alias legacy mode

  • In the old MSDOS partition table with the MBR (Master Boot Record), the bootloader is installed into the first mibibyte of the drive, and the first partition starts behind that ‘unallocated drive space’.
  • In the new GUID partition table, GPT, the bootloader is installed into a small (typically 1 mibibyte) partition with a bios_grub flag and no file system.

UEFI mode

In UEFI mode the bootloader is located in the EFI System Partition, ESP, which is usually a few hundred mibibytes with a FAT file system. The ESP should have a boot flag, and can also have an esp flag. (The UEFI system does not look for a bootloader at the head end of the drive.)

In Ubuntu the ESP is often mounted at the mountpoint /boot/efi and can be identified via the command

Otherwise you can identify the ESP with this parted command

or if there are problems with parted with the following commands

sudo lsblk -o name,fstype,label,mountpoint,partflags,partlabel sudo fdisk -lu 

The grub files

The grub files ( grub.cfg , the hardware drivers etc) belong to the bootloader and are located in the directory /boot (as seen, when booted into the system). You find the partition with the following command line,

See this link for more details,

Источник

How do I tell which partition I booted from?

Is there a way to know which partition you actually booted from? fdisk -l reveals a «Boot» column that I definitely don’t have on my NVME. Is this just legacy information?

Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 1126399 1124352 549M b W95 FAT32 /dev/sda2 1126400 975688107 974561708 464.7G 7 HPFS/NTFS/exFAT /dev/sda3 975689728 976769023 1079296 527M 27 Hidden NTFS WinRE . Device Start End Sectors Size Type /dev/nvme0n1p1 616448 2458216447 2457600000 1.1T Linux filesystem /dev/nvme0n1p2 2458216448 3907024031 1448807584 690.8G Linux filesystem /dev/nvme0n1p3 2048 616447 614400 300M EFI System Partition table entries are not in disk order. 

Considering lsblk shows that /boot/efi is mounted I’m 90% sure that it’s using my nvme drive, I just wanted to confirm that’s true even though there’s no boot indicator from fdisk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 465.8G 0 disk ├─sda1 8:1 0 549M 0 part ├─sda2 8:2 0 464.7G 0 part └─sda3 8:3 0 527M 0 part sdb 8:16 0 1.8T 0 disk ├─sdb1 8:17 0 99M 0 part ├─sdb2 8:18 0 16M 0 part └─sdb3 8:19 0 1.8T 0 part nvme0n1 259:0 0 1.8T 0 disk ├─nvme0n1p1 259:1 0 1.1T 0 part ├─nvme0n1p2 259:2 0 690.8G 0 part / └─nvme0n1p3 259:3 0 300M 0 part /boot/efi 

This quickly shows a lot of info: lsblk -e 7 -o model,name,fstype,size,fsused,label,partlabel,mountpoint,uuid

Читайте также:  Ping in linux machine

Consider that you may not even have been booted from a partition. You may have been booted via PXE, or from a removable device that is no longer there, or even from another running linux system via kexec.

2 Answers 2

Since your system apparently boots in UEFI style, the answer to the titular question is:

Run efibootmgr -v as root, see the four-digit ID on the BootCurrent: line (usually the first line of output), then look at the corresponding BootNNNN line to find both the PARTUUID of the partition to boot from, and the filename containing the actual boot manager/loader used.

Then run lsblk -o +PARTUUID to see the partition-unique UUIDs embedded in the GPT partition table. Find the UUID you saw on the BootNNNN line of the efibootmgr -v output, and you’ll know the partition.

(On MBR-partitioned disks, there is no real partition UUID, and so a shorter combination of a disk signature number and a partition number is displayed in place of a real partition UUID.)

The Disklabel type is definitely a factor here: it indicates your sda uses classic MBR partitioning and boot sequence, while your nvme0n1 uses GPT partitioning and UEFI-style booting.

While the GPT partition table can store a boot flag that is essentially the same as the Boot flag field in the fdisk -l output of a MBR-partitioned disk, booting MBR-style from a GPT-partitioned disk is expected to be a rare corner case, and so fdisk -l will not include it. The native UEFI-style way will not use such a flag at all, since it’s now the system firmware’s job to know both the name of the bootloader file and the PARTUUID of the partition to load it from.

But if such a legacy flag is enabled on a GPT partition, using the i command (= print information about a partition) of a modern Linux fdisk will show it, by the presence of a LegacyBIOSBootable keyword on the Attrs: line of output.

To actually toggle such a flag, you would have to use the experts-only extra commands of a GPT-aware Linux fdisk : first x , then A to toggle the flag.

If you just want a list the partition table with the UEFI partition flags included, you can use fdisk -x /dev/nvme0n1 . Be advised that the output is quite a bit wider than the traditional fdisk -l output.

Читайте также:  Linux аналог диспетчера устройств

If you are booting using the classic MBR/BIOS style, then the answer to the title question is «you don’t, really.» There is no ubiquitous standard way for BIOS-style firmware to tell the OS which device was actually used to boot the system. This was a long-standing problem on all OSs and OS installers on systems using legacy BIOS-style boot.

If the /sys/firmware/edd directory exists, it may contain information that allows the identification of the boot disk, by identifying the order in which BIOS saw the disks in. By convention, the current boot disk is moved to the first hard disk position (also known as «disk 0x80») in the BIOS disk list, and most BIOS-based bootloaders rely on this fact.

So if /sys/firmware/edd/int13_dev80 exists, and the bootloader has not switched the BIOS int13 IDs of the disks around (GRUB can do so, if you have a custom dual/multi-boot configuration that requires swapping disk IDs), then the information within may be useful to identify the actual boot disk used by the firmware.

Unfortunately the BIOS extension required to have this information available was not as widespread as it could have been, and not always completely and correctly implemented even when it was present. I’ve seen a lot of systems with no EDD info available, some systems with incomplete EDD info, and even one system in which querying the EDD info caused the boot to hang.

(Apparently the EDD info interface was designed by Dell, so if you mostly work with Dell systems, you may have better luck than me.)

Источник

Linux, how to know the current boot disk

I’ve a Linux Centos (5.0) machine with 2 disks. I was changing the SATA cable to one of the disk when I realized that depending on what SATA slot I’m using, the OS starts from sda or sdb. The problem is that I have daily backups from sda to sdb (merely copies), if by accident someone change the SATA cable, I will screw up and overwrite new data with old data. The only thing that I know is, that current boot disk is the good one. How I can certainly know which disk is the current boot disk (sda or sdb)? Additional info: I’ve no physical access to the machine.

grawity is absolutely right, once you solve this you should switch to using UUIDs instead, which prevents this sort of problem.

Like grawity said. Those names sda and sdb are dependent on the order they are found at boot time. Usually the lower numbered port is sda. So they will change if you swap the cables. sda will then be called sdb, and vice versa. So you can’t go by that name to identify them. They need a unique name.

BTW, since you have two disks you might want to just make them RAID 1, and let the OS do the sync/copy operation for you. Then you won’t have to deal with it.

5 Answers 5

First, use disk UUIDs like @grawity said.

If you want to know the UUIDs of everything that looks like a block device to Linux, use the blkid command. I think you can do something like blkid /dev/sda to find out the UUID of sda as well.

Читайте также:  Linux mint qemu kvm

Another thing you can do is use the symlinks in /dev/disk/by-id which are created for each disk based on the bus it’s connected to and its reported model and serial number.

Technically, Linux doesn’t know or care about the device it was loaded from, because

  • that’s the bootloader’s job — which runs before the kernel is running — to load the kernel into memory.
  • anything that’s not in the kernel needed at boot is in the initramfs (initrd), such as drivers, early userland utilities — loading this is also the bootloader’s job.

Now, after Linux loads, boot scripts or whatever other mechanism running under the kernel tries to mount a root file system so you have other things to run besides the kernel, as well as swap, etc. Basically all the stuff in your /etc/fstab . This is what you really care about and that file will have the information you need. You can use UUIDs in /etc/fstab (and I believe most distributions already use them) — so with a couple grep ‘s and cut ‘s you can get UUIDs out of here that you want.

Example (this probably can be done better): cat /etc/fstab | grep «/ » | cut -f 1 -d » «

And you can use the output of that for blkid to find the UUID of your root file system or whatever other partition.

Источник

How can I see which is my boot partition?

I want to see which partition ( /dev/sdaX ) is my boot partition. I’m using Ubuntu Server, so I need a command line solution I tried this, but the output was ambiguous as two partitions were shown:

sudo fdisk -l | grep 'Linux' | cut -d' ' -f1 2>&1 

3 Answers 3

Boot partition

In order to find the boot partition I would use the command df /boot for an installed Ubuntu system (standard Ubuntu, Ubuntu Server and the community flavours Kubuntu, Lubuntu . Xubuntu),

$ df /boot Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda8 103162996 30558020 67341528 32% / 

or if you want a clean output with only the partition,

$ df /boot | grep -Eo '/dev/[^ ]+' /dev/sda8 

Boot partition and EFI partition in UEFI mode

In order to find the boot partition and the EFI partition in an Ubuntu system booted in UEFI mode (both are use during boot),

$ test -d /sys/firmware/efi/ && echo efi || echo bios efi $ df /boot Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 303017780 3281532 284320780 2% / 

You can use fdisk (as you have been trying) or parted to find the EFI partition,

$ sudo fdisk -lu|grep -i efi /dev/sda1 65535 1048559 983025 480M EFI System $ sudo parted -ls|grep -i efi 1 33.6MB 537MB 503MB fat32 EFI System Partition boot, esp 

Parted does not provide the drive letter on the same line as the partition number, but you can use the full information and your eyes,

$ sudo parted -ls Model: WDC WD32 00BEKT-00PVMT0 (scsi) Disk /dev/sda: 320GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 33.6MB 537MB 503MB fat32 EFI System Partition boot, esp 2 537MB 316GB 315GB ext4 3 316GB 320GB 4161MB linux-swap(v1) 

Источник

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