# research all these options
# tune2fs -I 256 -O sparse_super,filetype,resize_inode,dir_index,ext_attr,has_journal,\
# extents,huge_file,flex_bg,uninit_bg,dir_nlink,extra_isize
if [ "$USER" != "root" ] ; then
echo "Must run as USER=root instead of USER=$USER"
exit 1
fi
mount $fsdev $mount_point -o $mount_opts 2>/dev/null
filecount=$(find $mount_point -type f 2>/dev/null | wc -l)
if [ "$filecount" -gt 0 ] ; then
echo "Operation will destroy all data on $mount_point"
echo "Remove all files from $mount_point before proceeding"
exit 1
fi
umount $fsdev 2>/dev/null
set -x
umount $fsdev 2>/dev/null
mkdir -p $mount_point
parted -s $dev mklabel gpt
# must use <1M as parted (through version 1.8.8.1.159-1e0e) has a bug
# where 1M is either converted to 0M or rounded down to nearest block
# using kB units seems to circumvent this problem well
###parted -s $dev mkpart primary 0 1.1M
###parted -s $dev mkpart swap 1.1M 8G
# tell Grub 2 MBR is big enough to use without blocklists as
# using blocklists seems to create a vast array of instabilities
parted -s $dev set 1 bios_grub on
The following script can be used from a LiveCD to initially structure a GPT disk properly.
There still seems to be some problem where update-grub is never run when a new kernel is installed, even when correct GPT structure is in place.
Be sure to run update-grub after any kernel update for grub.cfg to contain the new kernel.
Best to try this script on a victim disk and be sure to change $dev, $fsdev and $mount_point to match your system.
Use this test script carefully to avoid data loss on a live disk.
_______
david@home1:~/bin$ cat gpt-setup-example
#!/bin/bash
# research all these options super,filetype, resize_ inode,dir_ index,ext_ attr,has_ journal, \ huge_file, flex_bg, uninit_ bg,dir_ nlink,extra_ isize
# tune2fs -I 256 -O sparse_
# extents,
if [ "$USER" != "root" ] ; then
echo "Must run as USER=root instead of USER=$USER"
exit 1
fi
dev=/dev/sdb 'extents, uninit_ bg,dir_ index,journal_ data_writeback' 'noatime, data=writeback, barrier= 0,nobh, errors= remount- ro'
fsdev=/dev/sdb3
tune_opts=
mount_opts=
mount_point=/data
mount $fsdev $mount_point -o $mount_opts 2>/dev/null
filecount=$(find $mount_point -type f 2>/dev/null | wc -l)
if [ "$filecount" -gt 0 ] ; then
echo "Operation will destroy all data on $mount_point"
echo "Remove all files from $mount_point before proceeding"
exit 1
fi
umount $fsdev 2>/dev/null
set -x
umount $fsdev 2>/dev/null
mkdir -p $mount_point
parted -s $dev mklabel gpt
# must use <1M as parted (through version 1.8.8.1.159-1e0e) has a bug
# where 1M is either converted to 0M or rounded down to nearest block
# using kB units seems to circumvent this problem well
###parted -s $dev mkpart primary 0 1.1M
###parted -s $dev mkpart swap 1.1M 8G
parted -s $dev mkpart primary 0 1100kB
parted -s $dev mkpart swap 1100kB 8G
parted -s $dev mkpart primary 8G 28G
# tell Grub 2 MBR is big enough to use without blocklists as
# using blocklists seems to create a vast array of instabilities
parted -s $dev set 1 bios_grub on
parted -s $dev unit kB p
mkfs.ext4 $fsdev
tune2fs -L disk2 -m 1 -o $tune_opts $fsdev
e2fsck -pfD $fsdev
mount $fsdev $mount_point -o $mount_opts
mount -l | grep $fsdev