No volunteers appeared, so here are my findings.
I started deliberately with the Ubuntu as-shipped image for the exercise - I know this has been updated:
http://downloadsnewit.co.uk/SD-images/Dreamplug/ex-factory-2011-04-24-Ubuntu-NewIT-fixed/Firstly, as stated by James in another context, dd does not write off the end of the device - the risk is that other processes attempt to, if the structure is erroneous. I have had a mechanical head crash on a Seagate drive due to this, and I suspect a fried USB stick too.
To summarise
- the as-shipped image is exactly the same length as the Kingston internal micro SD
- its partition table and root file system describe a slightly larger space, though the sectors that are 'hanging off the end' were obviously not used
It is possible to
- copy the image to a slightly larger device and correct it using fdisk, fsck and resize2fs
- copy the image to an identical device and correct it by the same means
I urge everyone to do this if they are not using a more recent and correct boot device. The error may not appear for some time. See this topic:
http://www.newit.co.uk/forum/index.php/topic,2291.msg6479.html#msg6479gparted is not happy to manipulate this particular partition table with its errors.
Tip:
- after altering a partition table, ioctl attempts to re-read it. If unsuccessful, the table in the kernel continues to be used, which is no good. kpartx is supposed to fix this, but it hasn't worked for me. A brutal but successful method is to unplug and reconnect the device.
Once again, this method requires the devices to have no faulty locations: I would much prefer the use of tar images which can avoid faulty locations, the method used for the original swap between Ubuntu and Debian.
Note that the Ubuntu system automatically mounts partitions - you shouldn't run fdisk, fsck or resize2fs on mounted partitions.
For interest, here are commented logs of the process with the DreamPlug running Debian Squeeze 30-Aug-11. This system does not have dosfsck.
Correcting partitions on slightly larger stick:** Original Ubuntu image as shipped for internal micro SD: **
root@debian:/mnt/sdd1# ls -l
-rw-r--r-- 1 root root 1967128576 Sep 20 07:09 ex-factory-2011-04-24-microSD.img
** Copy to slightly larger USB stick: **
root@debian:/mnt/sdd1# dd if=ex-factory-2011-04-24-microSD.img of=/dev/sde bs=1M
1876+0 records in
1876+0 records out
1967128576 bytes (2.0 GB) copied, 666.739 s, 3.0 MB/s
** Result: **
root@debian:/mnt/sdd1# fdisk -l /dev/sde
Disk /dev/sde: 2003 MB, 2003828736 bytes
62 heads, 61 sectors/track, 1034 cylinders
Units = cylinders of 3782 * 512 = 1936384 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sde1 1 1016 1920993+ 6 FAT16
/dev/sde2 56 1021 1826706 83 Linux
** End of partition 1 is invalid and type sometimes comes up wrong - this is corrected in the later image **
** Correct it, for this exercise: **
root@debian:/mnt/sdd1# fdisk /dev/sde
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): u
Changing display/entry units to sectors
Command (m for help): u
Changing display/entry units to cylinders
Command (m for help): p
Disk /dev/sde: 2003 MB, 2003828736 bytes
62 heads, 61 sectors/track, 1034 cylinders
Units = cylinders of 3782 * 512 = 1936384 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sde1 1 1016 1920993+ 6 FAT16
/dev/sde2 56 1021 1826706 83 Linux
** Delete both partitions (must NOT be mounted): **
Command (m for help): d
Partition number (1-4): 1
Command (m for help): d
Selected partition 2
** Recreate with same starting cylinder to preserve contents: **
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1034, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-1034, default 1034): 55
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (56-1034, default 56):
Using default value 56
Last cylinder, +cylinders or +size{K,M,G} (56-1034, default 1034):
Using default value 1034
Command (m for help): p
Disk /dev/sde: 2003 MB, 2003828736 bytes
62 heads, 61 sectors/track, 1034 cylinders
Units = cylinders of 3782 * 512 = 1936384 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sde1 1 55 103974+ 83 Linux
/dev/sde2 56 1034 1851289 83 Linux
** Change system type of partition 1 to '6' (FAT16): **
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 6
Command (m for help): p
Disk /dev/sde: 2003 MB, 2003828736 bytes
62 heads, 61 sectors/track, 1034 cylinders
Units = cylinders of 3782 * 512 = 1936384 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sde1 1 55 103974+ 6 FAT16
/dev/sde2 56 1034 1851289 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
sd 4:0:0:0: [sde] Assuming drive cache: write through
sde: sde1 sde2
WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
** Check new root partition. Note: you must run fsck -f first (resize2fs insists if you forget): **
root@debian:/mnt/sdd1# fsck -f /dev/sde2
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
dreamv7_fs: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
dreamv7_fs: 26859/114240 files (0.1% non-contiguous), 185248/456676 blocks
root@debian:/mnt/sdd1# resize2fs /dev/sde2
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/sde2 to 462822 (4k) blocks.
The filesystem on /dev/sde2 is now 462822 blocks long.
Correcting same image on Kingston chip identical to internal one:root@debian:/mnt/sdd1# dd if=ex-factory-2011-04-24-microSD.img of=/dev/sde bs=1M
1876+0 records in
1876+0 records out
1967128576 bytes (2.0 GB) copied, 288.618 s, 6.8 MB/s
** Exact number of bytes copied **
** But partition table is awry **
root@debian:/mnt/sdd1# fdisk -l /dev/sde
Disk /dev/sde: 1967 MB, 1967128576 bytes
62 heads, 61 sectors/track, 1015 cylinders
Units = cylinders of 3782 * 512 = 1936384 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sde1 1 1016 1920993+ 6 FAT16
Partition 1 has different physical/logical endings:
phys=(54, 61, 61) logical=(1015, 54, 24)
/dev/sde2 56 1021 1826706 83 Linux
** So rewrite to feasible values **
root@debian:/mnt/sdd1# fdisk /dev/sde
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): u
Changing display/entry units to sectors
Command (m for help): u
Changing display/entry units to cylinders
Command (m for help): p
Disk /dev/sde: 1967 MB, 1967128576 bytes
62 heads, 61 sectors/track, 1015 cylinders
Units = cylinders of 3782 * 512 = 1936384 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sde1 1 1016 1920993+ 6 FAT16
Partition 1 has different physical/logical endings:
phys=(54, 61, 61) logical=(1015, 54, 24)
/dev/sde2 56 1021 1826706 83 Linux
Command (m for help): d
Partition number (1-4): 1
Command (m for help): d
Selected partition 2
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1015, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1015, default 1015): 55
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (56-1015, default 56):
Using default value 56
Last cylinder, +cylinders or +size{K,M,G} (56-1015, default 1015):
Using default value 1015
Command (m for help): p
Disk /dev/sde: 1967 MB, 1967128576 bytes
62 heads, 61 sectors/track, 1015 cylinders
Units = cylinders of 3782 * 512 = 1936384 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sde1 1 55 103974+ 83 Linux
/dev/sde2 56 1015 1815360 83 Linux
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 6
Changed system type of partition 1 to 6 (FAT16)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
sd 5:0:0:0: [sde] Assuming drive cache: write through
sde: sde1 sde2
WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
** Now we have a file system hanging over the end of the disc. **
** Fortunately the missing sectors contain no data: **
root@debian:/mnt/sdd1# fsck /dev/sde2
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
dreamv7_fs: recovering journal
The filesystem size (according to the superblock) is 456676 blocks
The physical size of the device is 453840 blocks
Either the superblock or the partition table is likely to be corrupt!
Abort<y>? no
dreamv7_fs contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
dreamv7_fs: 26859/114240 files (0.1% non-contiguous), 185248/456676 blocks
** Now resize **
root@debian:/mnt/sdd1# resize2fs /dev/sde2
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/sde2 to 453840 (4k) blocks.
The filesystem on /dev/sde2 is now 453840 blocks long.
root@debian:/mnt/sdd1# fsck -f /dev/sde2
fsck from util-linux-ng 2.17.2
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
dreamv7_fs: 26859/114240 files (0.1% non-contiguous), 185248/453840 blocks
** Now it's OK **