3

How to mount second partition on the same USB disk where Live Ubuntu was installed?

I was using dd to create a live USB.

I have created second VFAT partition using fdisk and formatted it using mkfs.ext2.

When I try to run "sudo mount /dev/sda2 /mnt" I get an error: /dev/sda2 already mounted or /mnt is busy.

It might be because /dev/sda (whole drive, not partition) is already mounted on /cdrom with type iso9660.

How do I overcome this, I need to be able to permanenty store some files on second partition.

kometonja
  • 155
  • If you are running in UEFI mode, you can also use a very simple extraction method manually according to these links, https://help.ubuntu.com/community/Installation/iso2usb and https://help.ubuntu.com/community/Installation/iso2usb/diy , 'do it yourself'. – sudodus Dec 06 '17 at 21:22

2 Answers2

4

The problem is that /dev/sda contains /dev/sda2. This would be a severe obstacle if both should be mounted as read-write filesystems. But in your case the ISO 9660 in /dev/sda (also in /dev/sda1) is read-only. So there will be no fighting of filesystems.

The normally correct way to have both filesystems mounted would be to umount /dev/sda and to mount /dev/sda1 instead. It does not overlap with /dev/sda2. So mount(8) will perceive no problem

But if the running system depends on files in the ISO 9660 filesystem, it might not be possible to umount it. In this case there remains the backdoor of using a loop device like /dev/loop0. Such a device is based on a data file or block device file. It acts as block device. See man losetup(8) for details.

mount(8) offers the convenience option "loop". So this should work although /dev/sda is already mounted:

mount -o loop /dev/sda2 /your/mount/directory

Luckily mount(8) is too stupid to recognize the overlapping although it then lists the partition device as mounted rather than the loop device.


/dev/sdc on /mnt/iso type iso9660 (ro,relatime)
/dev/sdc2 on /mnt/fat type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=utf8,shortname=mixed,errors=remount-ro)

So this trick might cease to work in future ... :( (But maybe it also gets smart enough to recognize that the overlapping is harmless.)

  • +1 This is a good solution, that works on drives with cloned systems from iso files. (I tested it with Ubuntu 17.10 and and an extra partition with the ext4 file system. It works well for storage, but I could not make the live system use it for persistence.) – sudodus Dec 07 '17 at 18:52
1

I have not had success modifying partitions on a ISO 9660 drive that was made using Startup Disk Creator or Rufus.

However if you use mkusb to make the drive you will get a small FAT32 boot partition, an ISO 9660 OS partition, a ext4 casper-rw persistence partition and a NTFS data partition, (if requested).

You can then delete the casper-rw partition, if you don't need persistence, and expand or reformat the NTFS partition to suit your needs.

C.S.Cameron
  • 19,519
  • Will try it when get back from work. If I understood correctly, mkusb would write my custom ISO file to a USB drive and make NTFS data partition "mountable"? I have no trouble creating new partition by hand, it looks to me the problem is Ubuntu mounting enter device /dev/sda instead of one partition /dev/sda1 – kometonja Dec 06 '17 at 13:52
  • 1
    Solved it easily by mounting it as a loop device, please have a look at my answer. – kometonja Dec 07 '17 at 17:13