Installing OS on USB, where to put bootloader?

Questions about Grub, UEFI,the liveCD and the installer
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
User avatar
overkill22
Level 4
Level 4
Posts: 450
Joined: Fri Jan 16, 2015 6:09 am

Installing OS on USB, where to put bootloader?

Post by overkill22 »

I have a laptop with mint 18.2 installed. Now I want to have another OS on a USB pen drive. So I was thinking to make a USB live with persistence that allow me to save files and install programs even though the system will always run as a live distro. I tried this with Lubuntu 17.10 but it didn't work (not sure if it's not supported anymore after Ubuntu 16.10).
So now I was thinking to install linux mint or lubuntu like if it was a real installation on USB.
What I do is:
1. Start the laptop with USB A with lubuntu live installed.
2. Insert the USB B that is empty and will be the house of the new system.
3. Install lubuntu (or mint, still haven't decided) on the USB B.

Now, the installer see the laptop's HD and the USB B. In the laptop I'm already running linux mint, with bootloader. So I choose USB B. But I still have to choose where to install the bootloader. Since my laptop is already working, I don't want to reinstall the bootloader on the laptop. I could choose USB B, but then how will it works when I want to use the USB B to load the SO?

Any suggestion, link, or comment is really appreciated :)
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Reorx
Level 12
Level 12
Posts: 4044
Joined: Tue Jul 07, 2009 7:14 pm
Location: SE Florida, USA

Re: Installing OS on USB, where to put bootloader?

Post by Reorx »

1) Don't install the bootloader on the HD
2) Do install the bootloader on the USB with the new installation. After the installation, continue working with the OS booted from the boot USB. Then shut down as usual.

Put the USB with the new installation into a USB port and boot the system and see what happens - it should boot the new OS on the newly created bootable USB. If it doesn't, report back.
Full time Linux Mint user since 2011 - Currently running LM21C on multiple Dell laptops - mostly Vostro models.

Image Image Image
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: Installing OS on USB, where to put bootloader?

Post by catweazel »

overkill22 wrote:Now, the installer see the laptop's HD and the USB B. In the laptop I'm already running linux mint, with bootloader. So I choose USB B. But I still have to choose where to install the bootloader. Since my laptop is already working, I don't want to reinstall the bootloader on the laptop. I could choose USB B, but then how will it works when I want to use the USB B to load the SO?
Install the bootloader to the same device you're installing the OS on, in your case USB B. It will run normally.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
User avatar
overkill22
Level 4
Level 4
Posts: 450
Joined: Fri Jan 16, 2015 6:09 am

Re: Installing OS on USB, where to put bootloader?

Post by overkill22 »

Reorx wrote:1) Don't install the bootloader on the HD
2) Do install the bootloader on the USB with the new installation. After the installation, continue working with the OS booted from the boot USB. Then shut down as usual.

Put the USB with the new installation into a USB port and boot the system and see what happens - it should boot the new OS on the newly created bootable USB. If it doesn't, report back.
I've done everything perfectly, selected the sdb for installation and installed bootloader on the sdb.

But it looks like my laptop has been wipe off. Now I start the laptop and can see only the grub bash line.

Any help is much appreciated.
User avatar
overkill22
Level 4
Level 4
Posts: 450
Joined: Fri Jan 16, 2015 6:09 am

Re: Installing OS on USB, where to put bootloader?

Post by overkill22 »

I'm in with the live distro now, and I see my /home directory is still there.
My previous configuration was:
Sda1 fat32 bootloader 40mb
Sda2 ext4 / 10gb
Sda3 ext4 /home 230gb

Now it looks like those partitions are still there,but there is a problem with the bootloader. I have no clue.
User avatar
overkill22
Level 4
Level 4
Posts: 450
Joined: Fri Jan 16, 2015 6:09 am

Re: Installing OS on USB, where to put bootloader?

Post by overkill22 »

So, I've connected the USB B with the newly installed Lubuntu (and bootloader) and somehow I can now access to the grub menu where I can choose the OS.
Linux mint is there and Lubuntu too.

Now, do I have to kind of repair the bootloader on my laptop?
User avatar
catweazel
Level 19
Level 19
Posts: 9763
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: Installing OS on USB, where to put bootloader?

Post by catweazel »

Start a live session and mount your laptop boot drive to /mnt, then

Code: Select all

for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
chroot /mnt
update-initramfs -u
dpkg-reconfigure grub-pc
update-grub
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
User avatar
overkill22
Level 4
Level 4
Posts: 450
Joined: Fri Jan 16, 2015 6:09 am

Re: Installing OS on USB, where to put bootloader?

Post by overkill22 »

deleted
Last edited by overkill22 on Wed Oct 25, 2017 2:37 am, edited 1 time in total.
User avatar
overkill22
Level 4
Level 4
Posts: 450
Joined: Fri Jan 16, 2015 6:09 am

Re: Installing OS on USB, where to put bootloader?

Post by overkill22 »

catweazel wrote:Start a live session and mount your laptop boot drive to /mnt, then

Code: Select all

for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
chroot /mnt
update-initramfs -u
dpkg-reconfigure grub-pc
update-grub
I've read now this comment. I just tried with boot repair. Now starting the laptop and see how it goes.
User avatar
overkill22
Level 4
Level 4
Posts: 450
Joined: Fri Jan 16, 2015 6:09 am

Re: Installing OS on USB, where to put bootloader?

Post by overkill22 »

Nope.
I boot in grub with a list of OS and a list of these files to choose :

/EFI/ubuntu/grub.cfg
/EFI/BOOT/bkpbootx64.efi
/EFI/BOOT/bootx64.efi
/EFI/BOOT/fbx64.efi
/EFI/ubuntu/fbx64.efi
/EFI/ubuntu/fwupx64.efi
/EFI/ubuntu/grubx64.efi
/EFI/ubuntu/mmx64.efi
/EFI/ubuntu/shimx64.efi

Will try your suggestion
User avatar
overkill22
Level 4
Level 4
Posts: 450
Joined: Fri Jan 16, 2015 6:09 am

Re: Installing OS on USB, where to put bootloader?

Post by overkill22 »

catweazel wrote:Start a live session and mount your laptop boot drive to /mnt, then

Code: Select all

for i in /dev /dev/pts /proc /sys; do sudo mount -B $i /mnt$i; done
chroot /mnt
update-initramfs -u
dpkg-reconfigure grub-pc
update-grub
So I'm in the live session.
Mounted my drive where the boot is (Sda1) in /mnt.
In the /mnt folder now I have a /EFI with two subfolders:
BOOT
ubuntu


Tried to run your commands but don't work. It says mount point does not exist.
User avatar
overkill22
Level 4
Level 4
Posts: 450
Joined: Fri Jan 16, 2015 6:09 am

Re: Installing OS on USB, where to put bootloader?

Post by overkill22 »

now my sda1 (EFI) is full of files and folders that I don't knwo what they are.
Can I just simply format that folder, and then install grub there? If yes, how?
fabien85
Level 7
Level 7
Posts: 1877
Joined: Tue Mar 11, 2014 4:30 pm

Re: Installing OS on USB, where to put bootloader?

Post by fabien85 »

So I'm in the live session.
Mounted my drive where the boot is (Sda1) in /mnt.
In the /mnt folder now I have a /EFI with two subfolders:
BOOT
ubuntu

Tried to run your commands but don't work. It says mount point does not exist.
sda1 is your EFI partition, not the / partition, that's why you get the error message about the mount point.

I believe that if you use the entry "/EFI/ubuntu/grub.cfg" that you mentioned in a previous post, you should get your usual grub menu where you can boot the installed Mint.
After booting, open a terminal and issue

Code: Select all

apt-get install --reinstall grub-efi-amd64
sudo update-grub
For the USB, that's a whole other thing. I believe what happened is that you didnt have an EFI partition on it, and/or you didnt specify this EFI partition as the place where to put the bootloader. Or also sometimes the installer disregards where you tell him to put grub, and just puts it on the first ESP hard drive. Furthermore, even if you had grub installed on the USB, the USB would most probably not be bootable on another computer, because grub would not be at the fallback location /EFI/BOOT/bootx64.efi. For all those reasons, I personally prefer to make an install without bootloader (launching the installer with ubiquity -b), and then manually install a bootloader to the fallback location, and take the occasion to install a better thing : refind.

Edit : corrected code tags
User avatar
overkill22
Level 4
Level 4
Posts: 450
Joined: Fri Jan 16, 2015 6:09 am

Re: Installing OS on USB, where to put bootloader?

Post by overkill22 »

fabien85 wrote:
So I'm in the live session.
Mounted my drive where the boot is (Sda1) in /mnt.
In the /mnt folder now I have a /EFI with two subfolders:
BOOT
ubuntu

Tried to run your commands but don't work. It says mount point does not exist.
sda1 is your EFI partition, not the / partition, that's why you get the error message about the mount point.

I believe that if you use the entry "/EFI/ubuntu/grub.cfg" that you mentioned in a previous post, you should get your usual grub menu where you can boot the installed Mint.
After booting, open a terminal and issue

Code: Select all

apt-get install --reinstall grub-efi-amd64
sudo update-grub
For the USB, that's a whole other thing. I believe what happened is that you didnt have an EFI partition on it, and/or you didnt specify this EFI partition as the place where to put the bootloader. Or also sometimes the installer disregards where you tell him to put grub, and just puts it on the first ESP hard drive. Furthermore, even if you had grub installed on the USB, the USB would most probably not be bootable on another computer, because grub would not be at the fallback location /EFI/BOOT/bootx64.efi. For all those reasons, I personally prefer to make an install without bootloader (launching the installer with ubiquity -b), and then manually install a bootloader to the fallback location, and take the occasion to install a better thing : refind.

Edit : corrected code tags

Thank you for the info.
In the meantime I ended up reinstalling linux mint on my laptop. Since I partitioned the HD in a way that if something happen I can quickly reinstall everything without loosing data, I have the HD partitioned in the following way:
sda1 - EFI - bootloader
sda2 - /
sda3 - /home

I reinstalled mint preformatting the EFI partition with gparted, and then installing mint with the live cd. After choosing manual installation, I then selected the two folders I wanted to reinstall, EFI and /.
The installer didn't let me format the EFI partition (that's why I used gparted), while I selected the / partition to be formatted. I then selected the /home partition as before, but unchecking box for the formatting.
Then I selected sda1 as the place to install the bootloader.

The installation when ok, and it saved all my data in the /home folder. Unfortunately all the programs and most of the settings I had previously (themes, and etc) were deleted. That makes useless to have the HD partitioned since I still have to waste hours to reinstall all the programs I use and go through all the settings.

Now, since I will be at the starting point again, I'd like to do the things properly. I couldn't find any information with google, and all the mess I did it was because I wasn't able to find info : I need to have an OS installed on a USB pendrive that could work if inserted to any laptop. How can I do that?
User avatar
Moem
Level 22
Level 22
Posts: 16226
Joined: Tue Nov 17, 2015 9:14 am
Location: The Netherlands
Contact:

Re: Installing OS on USB, where to put bootloader?

Post by Moem »

overkill22 wrote:The installation when ok, and it saved all my data in the /home folder. Unfortunately all the programs and most of the settings I had previously (themes, and etc) were deleted. That makes useless to have the HD partitioned since I still have to waste hours to reinstall all the programs I use and go through all the settings.
Since most of the settings are kept in your /home, most of them will be back as soon as you reinstall the programs that the settings are for.
Image

If your issue is solved, kindly indicate that by editing the first post in the topic, and adding [SOLVED] to the title. Thanks!
fabien85
Level 7
Level 7
Posts: 1877
Joined: Tue Mar 11, 2014 4:30 pm

Re: Installing OS on USB, where to put bootloader?

Post by fabien85 »

So I understand that the laptop now works, at least that's good progress.
Indeed of course the not-default programs got wiped through the reinstall, since the binaries are located in the / partition. But as Moem said, the settings are still there, because they are in /home. For instance the thunderbird settings (and all the emails) are in /home/username/.thunderbird/. So you now have to reinstall all programs, but that shouldnt take hours if you have a good internet connection. If you have a list of the programs, then it's just a question to pipe that list to apt install and take a cup of coffee. For future, Mint has this nice tool : Menu > Administration > Backup Tool, which can save your software selection into a text file, and then you can restore the selection on any computer with the same tool. Especially useful for these reinstall cases.

For the USB, as I said, make an install without bootloader with ubiquity -b, and setting up manually partitions on the USB, including an EFI partition (~200MB, FAT32, with the flags boot and esp in gparted, preferably the first partition on the drive). Then install the bootloader manually at the fallback location.
For the last point I suggested refind. Once you downloaded it and uncompressed it, you would need to find what's the device of the target USB, eg using gparted. I will assume the target USB is /dev/sdc and the EFI partition there is sdc1, then install refind with

Code: Select all

./refind-install --alldrivers --usedefault /dev/sdc1
Then you will be able to boot the USB on any UEFI computer. It will boot directly if USB is first in the boot order, otherwise you will need to get to the computer's boot menu to select the USB.

Edit : corrected a small typo in the refind-install command line
pbear
Level 16
Level 16
Posts: 6569
Joined: Wed Jun 21, 2017 12:25 pm
Location: San Francisco

Re: Installing OS on USB, where to put bootloader?

Post by pbear »

fabien85 wrote:For the USB, that's a whole other thing. I believe what happened is that you didnt have an EFI partition on it, and/or you didnt specify this EFI partition as the place where to put the bootloader. Or also sometimes the installer disregards where you tell him to put grub, and just puts it on the first ESP hard drive. Furthermore, even if you had grub installed on the USB, the USB would most probably not be bootable on another computer, because grub would not be at the fallback location /EFI/BOOT/bootx64.efi. For all those reasons, I personally prefer to make an install without bootloader (launching the installer with ubiquity -b), and then manually install a bootloader to the fallback location, and take the occasion to install a better thing : refind.
This. According to all sources I've seen, if the installer is run in UEFI, it will not put the bootloader in the designated place on a USB drive. It works in BIOS (or legacy boot, CRM, etc.), but not UEFI. Your solution looks interesting. Another I've seen is this one from the Ubuntu forum. Yet a third, which I've used successfully (also found originally on the Ubuntu forum), entails running Ubiquity in BIOS then installing the UEFI bootloader from terminal.
User avatar
overkill22
Level 4
Level 4
Posts: 450
Joined: Fri Jan 16, 2015 6:09 am

Re: Installing OS on USB, where to put bootloader?

Post by overkill22 »

fabien85 wrote:So I understand that the laptop now works, at least that's good progress.
Indeed of course the not-default programs got wiped through the reinstall, since the binaries are located in the / partition. But as Moem said, the settings are still there, because they are in /home. For instance the thunderbird settings (and all the emails) are in /home/username/.thunderbird/. So you now have to reinstall all programs, but that shouldnt take hours if you have a good internet connection. If you have a list of the programs, then it's just a question to pipe that list to apt install and take a cup of coffee. For future, Mint has this nice tool : Menu > Administration > Backup Tool, which can save your software selection into a text file, and then you can restore the selection on any computer with the same tool. Especially useful for these reinstall cases.
This is amazing! I have txt file which is a list of software I use, but I've never thought about a backup tool! This will save me sooo much time next time! Thank you!!
fabien85 wrote: For the USB, as I said, make an install without bootloader with ubiquity -b, and setting up manually partitions on the USB, including an EFI partition (~200MB, FAT32, with the flags boot and esp in gparted, preferably the first partition on the drive). Then install the bootloader manually at the fallback location.
For the last point I suggested refind. Once you downloaded it and uncompressed it, you would need to find what's the device of the target USB, eg using gparted. I will assume the target USB is /dev/sdc and the EFI partition there is sdc1, then install refind with

Code: Select all

./refind-install --alldrivers --usedefault /dev/sdc1
Then you will be able to boot the USB on any UEFI computer. It will boot directly if USB is first in the boot order, otherwise you will need to get to the computer's boot menu to select the USB.

Edit : corrected a small typo in the refind-install command line
I'm sure your guide here is good and easy, but I still unsure which steps to take. I'm not very confident with the command line and don't want to mess with my laptop again...

So, I have a USB with live Lubuntu. I have a USB B that I want to use as OS. I have a laptop with Linux Mint. What are the steps to take?
As I understood I should:

step 1. Partition my USB B using gparted, one fat32 partition of ~200MB (why so much?) for the mount point /EFI with flags boot and esp, one EXT4 for the mount point /.

step 2. Boot the laptop using a live USB (in my case lubuntu), then insert the USB B and install the live OS instead of on the laptop, on the USB B, but without the bootloader. Using manual installation I'll use the partition I created before. So here first question: how do I install without bootloader? How do I use ubiquity -b and when and where I can give this command?

step 3. Run my usual OS (linx mint), install on linux mint the program refind. Using this program, install on the USB B the bootloader, using the command

Code: Select all

./refind-install --alldrivers --usedefault /dev/sdXY
where XY is the EFI partition on my USB B.

Please let me know if I did some mistakes and let me know what is missing.. thank you very much for your help.
pbear wrote:This. According to all sources I've seen, if the installer is run in UEFI, it will not put the bootloader in the designated place on a USB drive. It works in BIOS (or legacy boot, CRM, etc.), but not UEFI. Your solution looks interesting. Another I've seen is this one from the Ubuntu forum. Yet a third, which I've used successfully (also found originally on the Ubuntu forum), entails running Ubiquity in BIOS then installing the UEFI bootloader from terminal.
I'm reading the first guide you mentioned. I actually would like to have a LIVE CD on a USB with persistence, ONLY IF this mean I can install one program, install few libraries, and the live cd will save my preferences. I couldn't find any info about this and I tried to use unetbooting to get the persistence and while I had a partition where I could save the files, I couldn't install any program or save preferences on the live os.
fabien85
Level 7
Level 7
Posts: 1877
Joined: Tue Mar 11, 2014 4:30 pm

Re: Installing OS on USB, where to put bootloader?

Post by fabien85 »

pbear wrote:This. According to all sources I've seen, if the installer is run in UEFI, it will not put the bootloader in the designated place on a USB drive. It works in BIOS (or legacy boot, CRM, etc.), but not UEFI. Your solution looks interesting. Another I've seen is this one from the Ubuntu forum. Yet a third, which I've used successfully (also found originally on the Ubuntu forum), entails running Ubiquity in BIOS then installing the UEFI bootloader from terminal.
Yes it's an ubiquity bug/feature, apparently the reasoning behind is that the program knows better than most users who are unfamiliar with UEFI... :roll:
The method in the Ubuntu forum appears too convoluted to me. Your method on the other hand is nice, especially because you can then also boot the USB on a BIOS/Legacy computer ; I bookmarked it for future ref.
fabien85
Level 7
Level 7
Posts: 1877
Joined: Tue Mar 11, 2014 4:30 pm

Re: Installing OS on USB, where to put bootloader?

Post by fabien85 »

@overkill22
I wouldnt look at the Ubuntu forum solution, as I said in my previous post it's complicated and there are simpler solutions : the one by pbear, with a full thread explaining it, or mine.
It's true that live USB with persistence appears at first like the thing you want. But I understand that for Mint, this broke somewhere around LM17.2 or 17.3. At the time there were posts trying to get this back to work, but that was at best difficult. Nowadays, I think it's not worth going for persistence, because USB are large enough to carry a full system (except for the point that you have more read/write operations to the drive, compared to the live case where the system is in RAM, but I'm no expert on this). Also with persistence, you cannot update kernel nor core programs in general, which can be a security issue. By default with persistence you also cannot install programs, just keep files (I hear there are ways to circumvent that, but I dont know how). In summary, if your USB is large enough to carry a system (32GB is more than enough, probably doable already on 16GB) I advise a full install instead of live+persistence.

For full install, have a look at pbear's method and choose which one you prefer.
For reference, I explain in larger details my method below, it's basically what you said.
1 ) Partition the target USB with gparted.
200MB is the typical/default size of an EFI System Partition (ESP), but indeed you can go smaller if you feel so. For instance my ESP weighs 6MB (and contains both grub refind and an EFI shell. grub alone is 3.5MB, refind alone is 1.5MB).
Do not define any mount point for the partitions at this moment.
2 ) Boot the live USB indeed. Open a terminal and issue

Code: Select all

ubiquity -b
this will launch the installer, looking exactly as the one you would get by double-clicking the icon on the desktop, the only difference is that the installer will not install a bootloader, everything else will be as you are used to.
3 ) Use the "something else" option to manually specify the location of the install. In fact you could do all the partition setup of step 1) at this point with the installer instead of gparted. Personally I prefer to use gparted for partition setup, because the interface is clearer, you separate the tasks and can more easily check what you did etc.
It seems you are familiar with installs, so I dont need to detail this step
4 ) Installing the bootloader.
You dont need to get back to your usual OS, you can do when still booted on the live USB (saves a few minutes)
For refind, you go to the download page, chosse binary zip file, download the zip somewhere and uncompress it, then open a terminal and change to the decompressed directory, e.g.

Code: Select all

cd Downloads/refind-bin-0.11.2/
where you will have the following content

Code: Select all

$ ls
banners      docs   LICENSE.txt  mvrefind    refind
COPYING.txt  fonts  mkrlconf     NEWS.txt    refind-install
CREDITS.txt  keys   mountesp     README.txt  refind-mkdefault
then indeed you issue the command

Code: Select all

./refind-install --alldrivers --usedefault /dev/sdXY
5 ) Shutdown, unplug the live USB, boot and get to the boot menu of your computer (tapping a machine-specific key, usually Esc or F8) and select the USB. You should get to refind which will provide different entries, one for each of the OS installed on your hard drive, and one for the OS installed on the USB drive.
Locked

Return to “Installation & Boot”