33# Uncomment the following line to get debug info
44# set -x
55
6+ # This is to avoid expanding '*' in fdisk results
7+ set -f
8+
69source /usr/local/lib/utils
710
811SELF=$( basename $0 )
@@ -22,11 +25,6 @@ swap_part=/dev/mmcblk0p${swap_part_num}
2225let share_part_num=${swap_part_num} +1
2326share_part=/dev/mmcblk0p${share_part_num}
2427
25- check_first_boot () {
26- [ -f /.first_boot ] && die 0 " nothing to do"
27- return 0
28- }
29-
3028check_root_id () {
3129 [ $( id -u) -ne 0 ] && die 3 " this script must be run as root, aborting"
3230 return 0
@@ -35,25 +33,30 @@ check_root_id () {
3533resize_rootfs_partition () {
3634
3735 # Check that the last partition is the rootfs partition
38- local last_part_line=$( sgdisk -p /dev/mmcblk0 | tail -n 1)
36+ local last_part_line=$( fdisk -l /dev/mmcblk0 2> /dev/null | tail -n 1)
3937 set ${last_part_line}
40- local last_part=${1}
41- if [ " ${last_part} " != " ${root_part_num} " ]; then
38+ local last_part_num=${1#/ dev/ mmcblk0p}
39+ local part_start=${3}
40+ if [ " ${last_part_num} " != " ${root_part_num} " ]; then
4241 die 4 " rootfs is not the last partition. Don't know how to expand, aborting"
4342 fi
4443
4544 # Remove (temporarily) the rootfs partition
46- sgdisk -d ${root_part_num} /dev/mmcblk0 > /dev/null 2>&1 || die 5 " cannot remove the rootfs partition, aborting"
47-
4845 # Re-create the rootfs partition with a 1GB size
49- sgdisk -n ${root_part_num} :0:+1G -c ${root_part_num} :rootfs /dev/mmcblk0 > /dev/null 2>&1 || die 6 " cannot resize the rootfs partition, aborting"
46+ fdisk /dev/mmcblk0 > /dev/null 2>&1 << EOF
47+ d
48+ ${root_part_num}
49+ n
50+ p
51+ ${root_part_num}
52+ ${part_start}
53+ +1G
54+ w
55+ EOF
5056
5157 # Mark the rootfs partition as bootable
52- sgdisk -A ${root_part_num} :set:2 /dev/mmcblk0 > /dev/null 2>&1 || die 7 " cannot make the rootfs partition bootable, aborting"
58+ sfdisk -A /dev/mmcblk0 ${root_part_num} > /dev/null 2>&1 || die 7 " cannot make the rootfs partition bootable, aborting"
5359
54- # Copy the primary GPT to the end of the disk
55- sgdisk -e /dev/mmcblk0 > /dev/null 2>&1 || die 8 " cannot move the GPT to the end of the disk"
56- sync
5760 return 0
5861}
5962
@@ -74,19 +77,27 @@ create_swap () {
7477 if [ $? -ne 0 ]; then
7578
7679 # Check that the last partition is the rootfs partition
77- local last_part_line=$( sgdisk -p /dev/mmcblk0 2> /dev/null | tail -n 1)
80+ local last_part_line=$( fdisk -l /dev/mmcblk0 2> /dev/null | tail -n 1)
7881 set ${last_part_line}
79- local last_part_num=${1}
82+ local last_part_num=${1#/ dev / mmcblk0p }
8083 if [ " $last_part_num " != " $root_part_num " ]; then
8184 die 11 " rootfs is not the last partition. Don't know how to create the backing store partition"
8285 fi
8386
8487 # Create an additional linux swap partition
8588 let swap_part_num=${last_part_num} +1
8689 swap_part=/dev/mmcblk0p${swap_part_num}
87- sgdisk -n ${swap_part_num} :0:+128M -c ${swap_part_num} :swap -t ${swap_part_num} :8200 /dev/mmcblk0 > /dev/null 2>&1 || die 12 " cannot create the swap partition, aborting"
88- sync
89- partprobe /dev/mmcblk0 > /dev/null 2>&1 || die 13 " cannot reload the partition table, aborting"
90+ fdisk /dev/mmcblk0 > /dev/null 2>&1 << EOF
91+ n
92+ p
93+ ${swap_part_num}
94+
95+ +128M
96+ t
97+ ${wap_part_num}
98+ 82
99+ w
100+ EOF
90101 mkswap ${swap_part} > /dev/null 2>&1
91102 if [ $? -ne 0 ]; then
92103 die 14 " cannot create swap file, aborting"
@@ -105,17 +116,27 @@ create_backing_store_partition () {
105116 if [ $? -ne 0 ]; then
106117
107118 # Check that the last partition is the swap partition
108- local last_part_line=$( sgdisk -p /dev/mmcblk0 2> /dev/null | tail -n 1)
119+ local last_part_line=$( fdisk -l /dev/mmcblk0 2> /dev/null | tail -n 1)
109120 set ${last_part_line}
110- local last_part_num=${1}
121+ local last_part_num=${1#/ dev / mmcblk0p }
111122 if [ " ${last_part_num} " != " ${swap_part_num} " ]; then
112123 die 15 " rootfs is not the last partition. Don't know how to create the backing store partition"
113124 fi
114125
115- # Create an additional Microsoft basic data partition share partition that fills the disk
126+ # Create an additional FAT32 share partition that fills the disk
116127 let share_part_num=${last_part_num} +1
117128 share_part=/dev/mmcblk0p${share_part_num}
118- sgdisk -n ${share_part_num} :0:-0 -c ${share_part_num} :share -t ${share_part_num} :0700 /dev/mmcblk0 > /dev/null 2>&1 || die 16 " cannot create the backing store partition, aborting"
129+ fdisk /dev/mmcblk0 > /dev/null 2>&1 << EOF
130+ n
131+ p
132+ ${share_part_num}
133+
134+
135+ t
136+ ${share_part_num}
137+ c
138+ w
139+ EOF
119140 sync
120141 fi
121142 return 0
@@ -139,7 +160,6 @@ copy_files_to_store_partition () {
139160}
140161
141162check_root_id
142- check_first_boot
143163notif " FIRST BOOT DETECTED"
144164
145165notif " 1/9 RESIZE ROOT PARTITION"
0 commit comments