Saturday, January 5, 2013

Creating a 3TB Filesystem in Linux

I moved my media drive out of the portable enclosure, and into the chassis, and ran into a problem.

The filesystem was showing as available, but was unable to mount.  Wondering what was going on, I ran :

fdisk -l /dev/sdb

and had a nice, wonderful message about the DOS partition table being unable to handle disks larger than some arbitrary amount.  Note, this is a new drive that I had mkfs.ext2'd on it a week and a half ago (it was a Christmas present - my wife ROCKS!), so it was (in theory) already having data on it.  I still had the original data ready to go, but couldn't get that mounted, and opted to look into doing this properly.

That lead me to actually re-create the filesystem on it, complete with a new partition table.  This time, instead of using fdisk and mkfs.ext2, I opted for ext4 (still want to turn off journalling) and parted (after removing the partition) :

(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) mkpart primary ext2 0% 100%
(parted) quit
Information: You may need to update /etc/fstab.

This allowed me to start to create the filesystem after a quick check :

[root@hostname mnt]# fdisk -l /dev/sdb

WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.

Disk /dev/sdb: 3000.6 GB, 3000592982016 bytes
255 heads, 63 sectors/track, 364801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      267350  2147483647+  ee  GPT
Partition 1 does not start on physical sector boundary.
[root@hostname mnt]#

So, now it's time to create the filesystem :
[root@hostname mnt]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=1 blocks, Stripe width=0 blocks
183148544 inodes, 732566272 blocks
36628313 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
22357 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848, 512000000, 550731776, 644972544

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@hostname mnt]#

So, the filesystem is created.  But, EXT4 filesystems have journalling enabled by default.  I don't like this, so I must disable it :

[root@hostname mnt]# tune2fs -o journal_data_writeback /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
[root@hostname mnt]# tune2fs -O ^has_journal /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
[root@hostname mnt]# dumpe2fs /dev/sdb1 |grep 'Filesystem features'
dumpe2fs 1.41.12 (17-May-2010)
Filesystem features:      ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
[root@hostname mnt]#

As long as you don't see has_journal in the output, journalling has been disabled.  The next step is to get the filesystem's unique ID :

[root@hostname mnt]# blkid /dev/sdb1
/dev/sdb1: UUID="1ec5551c-10eb-4bad-9232-5710613ba4d2" TYPE="ext4"
[root@hostname mnt]#

Next, ensure we have the mount entry in /etc/fstab :

[root@hostname mnt]# cat /etc/fstab |grep 1ec5551c-10eb-4bad-9232-5710613ba4d2
UUID=1ec5551c-10eb-4bad-9232-5710613ba4d2 /home/media   ext4    defaults     1 2
[root@hostname mnt]#

In some cases, it's wise to reboot the machine and make sure you can still mount it up.  I did that since this is the home media server, and everything looks good:

[root@hostname ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
                       50G   17G   31G  35% /
tmpfs                 3.8G     0  3.8G   0% /dev/shm
/dev/sda1             485M   90M  370M  20% /boot
                      400G  347G   33G  92% /home
/dev/sdb1             2.7T   73M  2.6T   1% /home/media
[root@hostname ~]#

That means it's time to rsync things back over.  Hooray!

No comments:

Post a Comment