2

I have been using the following bash script on Ubuntu 14.04.5 LTS to create a bootable USB disk for an embedded system, which worked fine:

# Partition disk.
/usr/bin/sudo /bin/umount /dev/sdc1 /dev/sdc2
/usr/bin/sudo /sbin/parted -s -- /dev/sdc mklabel msdos
/usr/bin/sudo /sbin/parted -s -- /dev/sdc mkpart primary 2048s 5244928s
/usr/bin/sudo /sbin/parted -s -- /dev/sdc set 1 boot on
/usr/bin/sudo /sbin/parted -s -- /dev/sdc mkpart primary 5246976s -977920s
/usr/bin/sudo /sbin/parted -s -- /dev/sdc quit
/usr/bin/sudo /sbin/partprobe /dev/sdc
/usr/bin/sudo /bin/umount /dev/sdc1 /dev/sdc2
/usr/bin/sudo /sbin/mkfs.ext4 -L rootfs /dev/sdc1
/usr/bin/sudo /sbin/mkfs.ext4 -L var /dev/sdc2
/usr/bin/sudo /sbin/partprobe /dev/sdc
/bin/sync

# Copy filesystem.
/usr/bin/udisksctl mount -b /dev/sdc1
/usr/bin/sudo /bin/cp -a ${ROOTFS_DIR}/. ${ROOTFS_MOUNTPOINT}
/usr/bin/udisksctl mount -b /dev/sdc2
/usr/bin/sudo /bin/cp -a ${VAR_DIR}/. ${VAR_MOUNTPOINT}
/bin/sync

# Upload bootloader.
/usr/bin/udisksctl mount -b /dev/sdc1
/usr/bin/sudo /usr/sbin/grub-install --no-floppy --directory=${ROOTFS_MOUNTPOINT}/usr/lib/grub/i386-pc --locale-directory=${ROOTFS_MOUNTPOINT}/usr/share/locale --boot-directory=${ROOTFS_MOUNTPOINT}/boot /dev/sdc
/bin/sync
/usr/bin/sudo /usr/bin/eject /dev/sdc

The output of fdisk for the generated USB disk is:

Disk /dev/sdc: 14.9 GiB, 16022241280 bytes, 31293440 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: 0x22953b4d

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sdc1  *       2048  5244928  5242881  2.5G 83 Linux
/dev/sdc2       5246976 30315520 25068545   12G 83 Linux

Recently, I switched to Ubuntu 18.04, but now, grub loads the linux kernel and initramfs, though afterwards booting fails with the following output, and it drops to emergency shell:

mount: wrong fs type, bad option, bad superblock on /dev/sdb1,
missing codepage or helper program, or other error

In the emergency shell, blkid command shows the partitions as expected, which matches the UUIDs in /boot/grub/grub.cfg and /etc/fstab:

/dev/sdb1: LABEL="rootfs" UUID="5556accb-3244-47d0-8042-aaad74dd3950" TYPE="ext4" PARTUUID="22953b4d-01"
/dev/sdb2: LABEL="var" UUID="6ee3b764-77dB-481d-9564-fbfabb590933" TYPE="ext4" PARTUUID="22953b4d-02"

Since I have already experienced some other problems in Ubuntu 18.04, such as different behavior from losetup, different output format for fdisk, etc. should I provide further command options for mkfs.ext4 or grub-install commands in the script? grub-install command is from Ubuntu with version 2.02-2ubuntu8.13, but its options use directories from the embedded filesystem which has grub 2.02.beta2-4, so, can there be some inconsistencies due to this?

Fatih Erol
  • 31
  • 2

1 Answers1

1

It turns out mkfs.ext4 was the reason, since the command is newer on Ubuntu 18.04 than the mounter on the embedded system, causing the following error during boot:

EXT4-fs (mmcblk1p2): couldn't mount RDWR because of unsupported optional features (400)

Based on this thread and this information, I disabled the metadata_csum feature with the following option while creating the filesystem, and the system booted normally:

/usr/bin/sudo /sbin/mkfs.ext4 -O ^metadata_csum -L 'rootfs' /dev/sdc1
Fatih Erol
  • 31
  • 2