What might be a convenient way to stash some hidden data in the "Unusable" area following the last partition, or anywhere outside defined partition boundaries? For example, making it appear as a /dev/___ ready for I/O to my userspace programs.

Let's say I don't care if partitioning programs or bootloaders don't recognize that there might be something important there and step on it; I'd do a structure sanity check & re-create data as needed.

                             cfdisk (util-linux 2.19.1)

                                Disk Drive: /dev/sda
                         Size: 160041885696 bytes, 160.0 GB
               Heads: 255   Sectors per Track: 63   Cylinders: 19457

 Name     Flags     Part Type   FS Type        [Label]        Size (MB) 
 sda1                Primary    vfat           [ACER]         25827.38   
 sda2                Primary    ntfs                          90033.92
                                       Unusable               13193.35
 sda3                Primary    ext4                          16508.14
 sda4     Boot       Primary    ext4                          14476.50
                                       Unusable                   2.62  *

3 Answers 3


You really should just define a partition to contain the space. You also should leave the first 63 sectors of the disk alone or you will break your boot loader ( more troublesome than the boot loader breaking your data ).

You can use losetup to create a loop device and point it to the specific section of the drive if you really want:

losetup -o start --sizelimit size /dev/loop0 /dev/sda

Where start and size are the start offset and size of the area in bytes.

Of course, if you get the values wrong, you'll trash your FS.

  • Now, that's getting closer to a transparent sort of approach I was thinking...didn't realize losetup had that -o start option. Combining that with a quick check at system start where the last partition ends and how many sectors are left on the block device is trivial....Lo and behold, I could then assign a consistent device path to harness that (tmp) space across all my servers with diff disks...nice. To be used for small backups, keep state information, and of course "secret" stuff outliving a possible fs reformat, and "safe" being beyond the reach of partitions. No extra kernel mod needed.
    – Marcos
    Feb 1, 2012 at 2:07
  • Assigning answer for now. I'm looking to turn this into a fuller bootup solution that considers total sector count fdisk -s /dev/sda and boundary of last partition, to safely find that start offset.
    – Marcos
    Feb 26, 2012 at 17:25

I would create a little filesystem in the wasted space. To bootstrap the process:

  1. Create a regular file (using dd) that matches the size of the "unusable" region of the drive.
  2. Use losetup to associate the regular file with a loop device.
  3. Use mkfs to create a filesystem on the loop device.
  4. Use losetup to detach the loop device.
  5. Use dd to copy the regular file to the "unusable" region of the drive.

Every time you want to access the data:

  1. Copy the "unusable" region of the drive (using dd) to a regular file.
  2. Use losetup to associate the file with a loop device.
  3. Use fsck on the loop device to check filesystem integrity. If something has stomped on the filesystem, you'll have to repeat the bootstrapping steps. Nothing should be writing to this area of the disk, so if the filesystem is getting stomped, it likely means you're overwriting part of an active disk partition. (!)
  4. Use mount to mount the loop device as a filesystem.
  5. Access the data.
  6. Use umount to unmount the filesystem.
  7. Use losetup to detach the loop device.
  8. Use dd to copy the regular file back to the "unusable" region of the drive.

You can access the whole drive through the device name without the partition numbers, in your case that's /dev/sda. You'll need to use dd's skip= parameter to read from the drive and seek= to write to it in the correct place. If you get the block seek count wrong when writing to the drive you will overwrite one of your disk partitions.

  • While this is technically possible, it's very error-prone. It would be a lot better to include this space in a partition. philfr's answer explains the problem. Jan 31, 2012 at 23:48
  • He's trying "stash some hidden data," so I don't he wants the space to be in a visible partition. I gave fair warning, so my hands are clean. :)
    – Kyle Jones
    Feb 1, 2012 at 0:41
  • Fair enough, yours is a good solution to a dubious requirement. Feb 1, 2012 at 0:45
  • All this is true though kinda what I had in mind by "inconvenient" :) Plus I'm looking to avoid any fs structure altogether...remember how more storage a 1.44MB floppy used to let us access in "raw" mode?
    – Marcos
    Feb 1, 2012 at 1:45
  • Hmmm. I guess "use dd" would be my answer, then.
    – Kyle Jones
    Feb 1, 2012 at 2:06

The problem with your partition table is that it contains 4 primary partitions that do not fill the disk. That is the reason the remaining space is marked "unusable", because there is no way to add a partition to use it.

If you replace one of your partitions by an "extended" partition, you will be able to create more than 4 partitions and use the whole disk without problem.

  • Right. In my case they're deliberate, and I intend on resizing 2 and 3 around, or merging, so that 13GB void is off limits. Part.tables themselves are so wasteful, like most disk meta data we're used to.
    – Marcos
    Feb 1, 2012 at 1:39
  • @Marcos, you might want to take a look at LVM: wiki.ubuntu.com/Lvm
    – psusi
    Feb 1, 2012 at 2:29
  • 1
    @Psusi LVMs are great. Back in my datacenter days I'd stack them on top of RAID 5 arrays. My goal was to achieve a system in which storage devices could be added/replaced/even removed transparently to a live running OS, perceived only as a capacity change or tmp slowdown. Lustre fs does that, used by China's Tianhe-1A supercomputer among others. Word to the wise, I learned to keep it simple for boot&root drives though :)
    – Marcos
    Feb 1, 2012 at 10:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .