Slicing an ext3 disk for Time Machine
Filed under tips & tricks, hacks, hardware on may 27, 2010
Since a while I wanted to upgrade my Mac to OSX 10.6 Snow Leopard, but I never got around to do it because I needed disk space for my backup first. I have a 1TB USB2 disk containing data, but I didn’t want to wipe the disk contents. There was about 400GB of data on the device:
# df -h /mnt Filesystem Size Used Avail Use% Mounted on /dev/sdf1 925G 390G 535G 47% /mnt
Resizing the disk
1. run fsck
First, we need to make sure the disk is clean, so force a disk check using fsck. This can take a while!
# fsck.ext3 -f /dev/sdf1 e2fsck 1.41.11 (14-Mar-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 usb2: 374137/61054976 files (2.1% non-contiguous), 89863648/244190000 blocks
2. run resize2fs
Next, we run resize2fs to scale the volume to the requested size. As I used less than 400GB, I found this a good value. This took a few hours on my system:
# resize2fs /dev/sdf1 400G resize2fs 1.41.11 (14-Mar-2010) Resizing the filesystem on /dev/sdf1 to 104857600 (4k) blocks. The filesystem on /dev/sdf1 is now 104857600 blocks long.
3. run fsck
To make sure everything is OK, we have to re-run fsck, again, this takes some time:
# fsck.ext3 -f /dev/sdf1 e2fsck 1.41.11 (14-Mar-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 usb2: 374137/61054976 files (2.1% non-contiguous), 89863648/244190000 blocks
4. partition
Now I used fdisk to remove all partitions, and resize the first one. After that I created a HFS+ file system on the remainder of the disk:
# fdisk /dev/sdf
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): p
Disk /dev/sdf: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x53038aec
Device Boot Start End Blocks Id System
/dev/sdf1 1 121601 976760001 83 Linux
Command (m for help): d
Selected partition 1
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-121601, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-121601, default 121601): +400G
Command (m for help): p
Disk /dev/sdf: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x53038aec
Device Boot Start End Blocks Id System
/dev/sdf1 1 52218 419441053+ 83 Linux
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (52219-121601, default 52219):
Using default value 52219
Last cylinder, +cylinders or +size{K,M,G} (52219-121601, default 121601):
Command (m for help): p
Disk /dev/sdf: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x53038aec
Device Boot Start End Blocks Id System
/dev/sdf1 1 52218 419441053+ 83 Linux
/dev/sdf2 52219 121601 557318947+ 83 Linux
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): af
Changed system type of partition 2 to af (HFS / HFS+)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
# hformat -l Backup /dev/sdf2
Volume name is "Backup"
Volume was created on Thu May 27 08:28:53 2010
Volume was last modified on Thu May 27 08:28:53 2010
Volume has 2113961984 bytes free
Now, I created a HFS volume, but it did not work! I tried converting it to HFS+ using Apple’s Disk Utility, but no luck here either:
May 27 08:29:29 blade Disk Utility[22152]: newfs_hfs: /dev/rdisk2s2: partition size not a multiple of 4K.
5. MBR to GPT
MBR partition tables use a pre-defined block size of (heads * cylinders), which doesn’t align with 4K blocks. With GPT you can manually allocate the number of sectors allowing you to choose proper 4K blocks. Back to Linux I installed the gdisk utilitity which can do the conversion for you. Firstly, remove the HFS partition:
# fdisk /dev/sdf
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): p
Disk /dev/sdf: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x53038aec
Device Boot Start End Blocks Id System
/dev/sdf1 1 52218 419441053+ 83 Linux
/dev/sdf2 52219 121600 557310915 af HFS / HFS+
Command (m for help): d
Partition number (1-4): 2
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Now we can use gdisk to convert the partitioning header:
# gdisk /dev/sdf GPT fdisk (gdisk) version 0.5.1 Partition table scan: MBR: MBR only BSD: not present APM: not present GPT: not present *************************************************************** Found invalid GPT and valid MBR; converting MBR to GPT format. THIS OPERATON IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if you don't want to convert your MBR partitions to GPT format! *************************************************************** ommand (? for help): p Disk /dev/sdf: 1953525168 sectors, 931.5 GiB Disk identifier (GUID): 6B9DAEFC-F7AE-0F1A-7028-A497B320B10C Partition table holds up to 128 entries First usable sector is 34, last usable sector is 1953525134 Total free space is 1114642994 sectors (531.5 GiB) Number Start (sector) End (sector) Size Code Name 1 63 838882169 400.0 GiB 0700 Linux/Windows data Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING MBR PARTITIONS!! THIS PROGRAM IS BETA QUALITY AT BEST. IF YOU LOSE ALL YOUR DATA, YOU HAVE ONLY YOURSELF TO BLAME IF YOU ANSWER 'Y' BELOW! Do you want to proceed, possibly destroying your data? (Y/N) y OK; writing new GPT partition table. The operation has completed successfully.
Now we can create a nice 4k-block partition. As you can see there are 1114642994 free sectors. To convert this to a 4k-block partition, you can use a simple calculation:
# python Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> divmod(1114642994, 4096) (272129, 2610) >>> 4096 * 272129 1114640384
So our new partition size will be 1114640384 sectors:
# gdisk /dev/sdf
GPT fdisk (gdisk) version 0.5.1
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): p
Disk /dev/sdf: 1953525168 sectors, 931.5 GiB
Disk identifier (GUID): 6B9DAEFC-F7AE-0F1A-7028-A497B320B10C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Total free space is 1114642994 sectors (531.5 GiB)
Number Start (sector) End (sector) Size Code Name
1 63 838882169 400.0 GiB 0700 Linux/Windows data
Command (? for help): n
Partition number (2-128, default 2): 2
First sector (34-1953525134, default = 838882170) or {+-}size{KMGT}:
Last sector (838882170-1953525134, default = 1953525134) or {+-}size{KMGT}: 1953521664
Current type is 'Unused entry'
Hex code (L to show codes, 0 to enter raw code): af00
Changed system type of partition to 'Apple HFS/HFS+'
Command (? for help): p
Disk /dev/sdf: 1953525168 sectors, 931.5 GiB
Disk identifier (GUID): 6B9DAEFC-F7AE-0F1A-7028-A497B320B10C
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Total free space is 3499 sectors (1.7 MiB)
Number Start (sector) End (sector) Size Code Name
1 63 838882169 400.0 GiB 0700 Linux/Windows data
2 838882170 1953521664 531.5 GiB AF00 Apple HFS/HFS+
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
MBR PARTITIONS!! THIS PROGRAM IS BETA QUALITY AT BEST. IF YOU LOSE ALL YOUR
DATA, YOU HAVE ONLY YOURSELF TO BLAME IF YOU ANSWER 'Y' BELOW!
Do you want to proceed, possibly destroying your data? (Y/N) y
OK; writing new GPT partition table.
The operation has completed successfully.
6. round up
Now plug the disk into your Mac and use Disk Utility to erase the partition using HFS+ with journaling. This created a workable HFS+ partition in a few seconds.
Also, just to be sure, I ran fsck on my Linux partition again, the disk mounted cleanly after this and all data was still available after the transition.
Post your feedback
You can use this form to leave your feedback. Your insights are always appreciated.