Change Hard Disk Boot order without using BIOS settings

8,736

Yes there is for EFI: efibootmgr

$ efibootmgr
BootCurrent: 0000
Timeout: 0 seconds
BootOrder: 0000,0044,004E,004F
Boot0000* ubuntu
Boot0044* UEFI OS
Boot004E* ubuntu
Boot004F* CD/DVD Drive 

... shows the current boot order. efibootmgr -v (more details, including GUID) to list them:

BootCurrent: 0000
Timeout: 0 seconds
BootOrder: 0000
Boot0000* ubuntu    HD(1,GPT,066aad32-119e-407c-af62-64ce08918c66,0x800,0x17800)/File(\EFI\ubuntu\shimx64.efi)
Boot0044* UEFI OS   HD(1,GPT,066aad32-119e-407c-af62-64ce08918c66,0x800,0x17800)/File(\EFI\BOOT\BOOTX64.EFI)
Boot004E* ubuntu    HD(1,GPT,066aad32-119e-407c-af62-64ce08918c66,0x800,0x17800)/File(\EFI\Ubuntu\grubx64.efi)
Boot004F* CD/DVD Drive  BBS(CDROM,,0x0)..GO..NO........o.M.A.T.S.H.I.T.A.D.V.D.-.R.A.M. .U.J.8.G.6....................A...........................>..Gd-.;.A..MQ..L.0.H.2.9. . .7.7.7.6.7.4. . . . . . . . ........BO

The -o option lets you change the bootorder:

-o | --bootorder XXXX,YYYY,ZZZZ              
Explicitly set BootOrder (hex).  Any value from 0 to FFFF 
is accepted so long as it corresponds to an existing 
Boot#### variable, and zero padding is not required.

Example:

sudo efibootmgr -o 0
[sudo] password for rinzwind: 
BootCurrent: 0000
Timeout: 0 seconds
BootOrder: 0000
Boot0000* ubuntu
Boot0044* UEFI OS
Boot004E* ubuntu
Boot004F* CD/DVD Drive 

and

 sudo efibootmgr -o 4F
BootCurrent: 0000
Timeout: 0 seconds
BootOrder: 004F
Boot0000* ubuntu
Boot0044* UEFI OS
Boot004E* ubuntu
Boot004F* CD/DVD Drive 

1 small issue: not all bios are correctly storing this so if yours faulty too it might reset to the previous; in that case you would need to redo the command every time.

Share:
8,736

Related videos on Youtube

Prateek Agrawal
Author by

Prateek Agrawal

Website Hi, I'm Prateek Agrawal. Engineer, full stack web developer, working on something new. I enjoy self-learning. I love experiments and working with new things. Routine: Wakeup, open laptop and do experiments, work on projects and coding whole day, and sleep Interests: Break software and then fix them Coding Play break and crash the Operating systems (Doesn't matter what will be the result) Lost in computer

Updated on September 18, 2022

Comments

  • Prateek Agrawal
    Prateek Agrawal over 1 year

    Sorry for the duplicate question but I have read these links:

    But none of above links solved my problem.

    Actually, the question is same, but the meaning is different. I want to change disk boot order on my computer (which disk will boot first, second and third. like CD-ROM -> Hard-Disk -> USB- Drive). I can do it using BIOS settings, but I want to change disk boot order using Ubuntu.

    When I type sudo fdisk -l on the terminal, I get the following result.

    Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 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
    Disklabel type: gpt
    Disk identifier: E7225B99-3850-4E61-8D35-D3D269A42F1A
    
    Device          Start        End   Sectors   Size Type
    /dev/sda1        2048  421529599 421527552   201G Microsoft basic data
    /dev/sda2   421529600  840959999 419430400   200G Microsoft basic data
    /dev/sda3   840960000  841881599    921600   450M Windows recovery environment
    /dev/sda4   841881600  842086399    204800   100M EFI System
    /dev/sda5   842086400  842119167     32768    16M Microsoft reserved
    /dev/sda6   843057152  864028671  20971520    10G Microsoft basic data
    /dev/sda7   864028672 1015023615 150994944    72G Linux filesystem
    /dev/sda8  1015023616 1224738815 209715200   100G Microsoft basic data
    /dev/sda9  1226835968 1436551167 209715200   100G Microsoft basic data
    /dev/sda10 1438648320 1635380309 196731990  93.8G Microsoft basic data
    /dev/sda11 1635381248 1710135295  74754048  35.7G Linux filesystem
    /dev/sda12 1710135296 1953523711 243388416 116.1G Linux filesystem
    
    
    
    
    Disk /dev/sdb: 14.9 GiB, 16005464064 bytes, 31260672 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: 0x05fec185
    
    Device     Boot Start      End  Sectors  Size Id Type
    /dev/sdb1  *     2048 31260671 31258624 14.9G  c W95 FAT32 (LBA)
    

    Here, currently, I have two disks One internal HDD (1 TB) and second external USB Drive (14.9 GB).

    Is there any command in Linux?

    • ravery
      ravery over 6 years
      since boot is done by the firmware/bios not Ubuntu, you can only change boot order from the firmware/bios.
  • Prateek Agrawal
    Prateek Agrawal over 6 years
    Will it work for UEFI and Legacy both??
  • Panther
    Panther over 6 years
    @PrateekAgrawal id depends on your UEFI. As Rinzwind stated "not all bios are correctly storing this " IMO I would advise against legacy boot. It was perhaps necessary at one point, but no longer.
  • Rinzwind
    Rinzwind over 6 years
    @PrateekAgrawal not on legacy. efi only.