Ubuntu – Live USB, mount second partition on same device

ddlive-cdlive-usbmountpartitioning

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.

Best Answer

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.)

Related Question