[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Grub cannot see my new hard drive



Matthew Campbell wrote:

> Now Debian Linux is running on my new hard drive using /dev/sdb1 as the
> root partition. I need to set up a separate USB flash drive to do all of
> this by default so I don't have to do all of this work every time the
> computer boots up. I also need to install Grub2 on the backup USB flash
> drive so I can use it to boot my system if something goes wrong and the
> first USB flash drive that I just used gets screwed up as well.

you better find out how to install properly grub2. I suggest using UUIDs -
it will save you a lot of troubles - especially on removable devices.

I attach here my notes regarding GPT and removable or not removable disks -
I hope it helps.


This is a step by step how to to install debian on a USB stick and make this stick bootable.
The stick in the example is found under /dev/sdb. Change to fit your setup.

1. Partition the disk. If you want you can use also crypto_LUKS and LVM

	# fdisk -l /dev/sdb

	Disk /dev/sdb: 28.9 GiB, 31051513856 bytes, 60647488 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: 0x93e4092b

	Device     Boot   Start      End  Sectors  Size Id Type
	/dev/sdb1  *       2048  1050623  1048576  512M 83 Linux
	/dev/sdb2       1050624 46679687 45629064 21.8G 83 Linux


   The example here will use plain ext4 on two partitions
	/dev/sdb1	/boot
	/dev/sdb2	/

1.a. USB Formatting with GPT

	Model: Kingston DataTraveler 2.0 (scsi)
	Disk /dev/sdb: 60647488s
	Sector size (logical/physical): 512B/512B
	Partition Table: gpt
	Disk Flags:
	
	Number  Start      End        Size       File system     Name  Flags
	1      2048s      1001471s   999424s    fat32           EFI   boot, esp
	2      1001472s   2050047s   1048576s   ext4
	3      2050048s   10438655s  8388608s   linux-swap(v1)
	4      10438656s  60647454s  50208799s  ext4


Use following setup

	/dev/sdb1 /mnt/target/boot/efi
	/dev/sdb2 /mnt/target/boot/
	/dev/sdb4 /mnt/target/

mount the partitions and chroot (see below)
then install grub (5.2) and do update-grub
this should be done from efi booted system


2. Format the partitions

	# mkfs.ext4 /dev/sdb1
	# mkfs.ext4 /dev/sdb2

3. mount the partitions

	# mkdir /mnt/target
	# mount /dev/sdb2 /mnt/target
	# mkdir /mnt/target/boot
	# mount /dev/sdb1 /mnt/target/boot
	# mount
	/dev/sdb2 on /mnt/target type ext4 (rw,relatime)
	/dev/sdb1 on /mnt/target/boot type ext4 (rw,relatime)

4. Debootstrap Buster to /mnt/target
	https://wiki.debian.org/Debootstrap

	The log can be monitored after starting debootstrap
		tail -1000f  /mnt/target/debootstrap/debootstrap.log

	# debootstrap buster /mnt/target/ http://deb.debian.org/debian/
	I: Retrieving InRelease
	I: Checking Release signature
	I: Valid Release signature (key id 6D33866EDD8FFA41C0143AEDDCC9EFBF77E11517)
	I: Retrieving Packages
	I: Validating Packages
	I: Resolving dependencies of required packages...
	I: Resolving dependencies of base packages...
	I: Found additional required dependencies: adduser debian-archive-keyring fdisk gcc-8-base gpgv libacl1 libapt-pkg5.0 libattr1 libaudit-common libaudit1 libblkid1 libbz2-1.0 libc6 libcap-ng0 libcom-err2 libdb5.3 libdebconfclient0 libext2fs2 libfdisk1 libffi6 libgcc1 libgcrypt20 libgmp10 libgnutls30 libgpg-error0 libhogweed4 libidn2-0 liblz4-1 liblzma5 libmount1 libncursesw6 libnettle6 libp11-kit0 libpam0g libpcre3 libseccomp2 libselinux1 libsemanage-common libsemanage1 libsepol1 libsmartcols1 libss2 libstdc++6 libsystemd0 libtasn1-6 libtinfo6 libudev1 libunistring2 libuuid1 libzstd1 zlib1g
	I: Found additional base dependencies: dmsetup libapparmor1 libapt-inst2.0 libargon2-1 libbsd0 libcap2 libcap2-bin libcryptsetup12 libdevmapper1.02.1 libdns-export1104 libelf1 libestr0 libfastjson4 libidn11 libip4tc0 libip6tc0 libiptc0 libisc-export1100 libjson-c3 libkmod2 liblocale-gettext-perl liblognorm5 libmnl0 libncurses6 libnetfilter-conntrack3 libnewt0.52 libnfnetlink0 libnftnl11 libpopt0 libprocps7 libslang2 libssl1.1 libtext-charwidth-perl libtext-iconv-perl libtext-wrapi18n-perl libxtables12 lsb-base xxd
	I: Checking component main on http://deb.debian.org/debian...
	I: Retrieving libacl1 2.2.53-4
	I: Validating libacl1 2.2.53-4
	I: Retrieving adduser 3.118
	I: Validating adduser 3.118
	I: Retrieving libapparmor1 2.13.2-10
	I: Validating libapparmor1 2.13.2-10
	I: Retrieving apt 1.8.2
	I: Validating apt 1.8.2
	I: Retrieving apt-utils 1.8.2
	I: Validating apt-utils 1.8.2
	[...]
	I: Configuring iptables...
	I: Configuring tasksel-data...
	I: Configuring tasksel...
	I: Configuring libc-bin...
	I: Configuring systemd...
	I: Base system installed successfully.

5. Configure the new system
   When using debootstrap few additional things need to be setup.
   Of course you could have copied your running system or other distribution
   You can skip this step if not using debootstrap

5.1. Chroot

        # mount --make-unbindable -obind /proc/ /mnt/target/proc/ 
        # mount --make-unbindable -obind /dev/ /mnt/target/dev/ 
        # mount --make-unbindable -obind /dev/pts /mnt/target/dev/pts 
        # mount --make-unbindable -obind /run /mnt/target/run 
        # mount --make-unbindable -obind /sys /mnt/target/sys/ 
	# chroot /mnt/target/

5.2. Edit /etc/fstab

	prepare the UUIDs of boot and root

	# blkid /dev/sdb1
	/dev/sdb1: UUID="7e953b17-5f57-4001-b326-70cabdf48abe" TYPE="ext4" PARTUUID="93e4092b-01"
	# blkid /dev/sdb2
	/dev/sdb2: UUID="0d189f21-dc54-416d-8d85-0bb9df8c8f4c" TYPE="ext4" PARTUUID="93e4092b-02"

	vi /etc/fstab

	UUID=0d189f21-dc54-416d-8d85-0bb9df8c8f4c       /       ext4    defaults        0       1
	UUID=7e953b17-5f57-4001-b326-70cabdf48abe       /boot   ext4    defaults        0       2

5.3 Install linux kernel

	# apt-get install linux-image-amd64
	Reading package lists... Done
	Building dependency tree... Done
	The following additional packages will be installed:
	[...]
	Processing triggers for libc-bin (2.28-10) ...
	Processing triggers for initramfs-tools (0.133+deb10u1) ...
	update-initramfs: Generating /boot/initrd.img-4.19.0-6-amd64

5.4 Install grub2

	# apt-get install grub2
	Reading package lists... Done
	Building dependency tree
	Reading state information... Done
	The following additional packages will be installed:
	[...]

	 â?? GRUB install devices:  				â??
 	 â??							â??
 	 â??    [ ] /dev/dm-0 (499836 MB; sdb2_crypt)		â??
 	 â??    [ ] /dev/sda (500107 MB; WDC_WDS500G1B0A-00H9H0)	â??
 	 â??    [*] /dev/sdb (31051 MB; DataTraveler_2.0) 	â??
 	 â??    [ ] - /dev/sdb1 (536 MB; /boot)			â??
	 â??    [ ] - /dev/sdb2 (23362 MB; /)			â??
	Installing for i386-pc platform.
	Installation finished. No error reported.
	Generating grub configuration file ...
	Found linux image: /boot/vmlinuz-4.19.0-6-amd64
	Found initrd image: /boot/initrd.img-4.19.0-6-amd64
	done

5.5 Check the initramfs for usb modules

	# cd boot && lsinitramfs initrd.img-4.19.0-6-amd64 | grep usb

5.6 Check for the root partition in grub.cfg

	You should find in the file the UUID

	# less /boot/grub/grub.cfg

	[...]
	set root='hd1,msdos2'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275/          (null)/sas/disk@0,msdos2' --hint-bios=hd1,msdos2 --hint-efi=hd1,msdos2 --hint-baremetal=ahci1,msdos2  0d189f21-dc54-416d-8d85-0bb9df8c8f4c
	else
	  search --no-floppy --fs-uuid --set=root 0d189f21-dc54-416d-8d85-0bb9df8c8f4c
	fi
	[...]

	Note: 	if the BIOS can not find the partition, change hd1 to hd0 and ahci1 to ahci0.
		Some computers assign the lowest number to the booting device

	[...]
	set root='hd0,msdos2'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275/          (null)/sas/disk@0,msdos2' --hint-bios=hd0,msdos2 --hint-efi=hd0,msdos2 --hint-baremetal=ahci0,msdos2  0d189f21-dc54-416d-8d85-0bb9df8c8f4c
	else
	  search --no-floppy --fs-uuid --set=root 0d189f21-dc54-416d-8d85-0bb9df8c8f4c
	fi
	[...]

5.7.	Set root password

	root@fujitsu:~# passwd root
	New password:
	Retype new password:
	passwd: password updated successfully

5.8.	Set hostname
	# vi /etc/hostname

5.9.	Install additional software
		- WLAN drivers
		- applications and desktop
		- others

	# vi /etc/apt/sources.list
	deb http://deb.debian.org/debian buster main contrib non-free

	# apt-get update
	# apt-get install ............

5.10.	Exit and umount the chroot

	# umount /mnt/target/proc/
	# umount /mnt/target/dev/pts
	# umount /mnt/target/dev/
	# umount /mnt/target/run/
	# umount /mnt/target/sys/
	# umount /mnt/target/boot/
	# umount /mnt/target/

==========
if not using debootstrap
==========


6.1.	Install grub2 if not using debootstrap
	https://www.gnu.org/software/grub/manual/grub/html_node/Installing-GRUB-using-grub_002dinstall.html#Installing-GRUB-using-grub_002dinstall

	grub2-install --removable --boot-directory=/mnt/target/boot /dev/sdb

6.2.	Inspect grub.conf if needed apply from 5.6

	# vi /mnt/target/boot/grub.conf

6.3.	Set hostname
	# vi /mnt/target/etc/hostname

Reply to: