##// END OF EJS Templates
Added: dphys-swapfile autoresize
drtyhlpr -
r540:958b7908f047
parent child
Show More
@@ -1,68 +1,76
1 logger -t "rc.firstboot" "Expanding root partition"
1 logger -t "rc.firstboot" "Expanding root partition"
2
2
3 # Detect root partition device
3 # Detect root partition device
4 ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
4 ROOT_PART=$(mount | sed -n 's|^/dev/\(.*\) on / .*|\1|p')
5 if [ -z "$ROOT_PART" ] ; then
5 if [ -z "$ROOT_PART" ] ; then
6 log_warning_msg "unable to detect root partition device"
6 log_warning_msg "unable to detect root partition device"
7 return 1
7 return 1
8 fi
8 fi
9
9
10 # Extract root device name
10 # Extract root device name
11 case "${ROOT_PART}" in
11 case "${ROOT_PART}" in
12 mmcblk0*) ROOT_DEV=mmcblk0 ;;
12 mmcblk0*) ROOT_DEV=mmcblk0 ;;
13 sda*) ROOT_DEV=sda ;;
13 sda*) ROOT_DEV=sda ;;
14 esac
14 esac
15
15
16 # Check detected root partition name
16 # Check detected root partition name
17 PART_NUM=$(echo ${ROOT_PART} | grep -o '[1-9][0-9]*$')
17 PART_NUM=$(echo ${ROOT_PART} | grep -o '[1-9][0-9]*$')
18 if [ "$PART_NUM" = "$ROOT_PART" ] ; then
18 if [ "$PART_NUM" = "$ROOT_PART" ] ; then
19 logger -t "rc.firstboot" "$ROOT_PART is not an SD card. Don't know how to expand"
19 logger -t "rc.firstboot" "$ROOT_PART is not an SD card. Don't know how to expand"
20 return 0
20 return 0
21 fi
21 fi
22
22
23 # NOTE: the NOOBS partition layout confuses parted. For now, let's only
23 # NOTE: the NOOBS partition layout confuses parted. For now, let's only
24 # agree to work with a sufficiently simple partition layout
24 # agree to work with a sufficiently simple partition layout
25 if [ "$PART_NUM" -gt 2 ] ; then
25 if [ "$PART_NUM" -gt 2 ] ; then
26 logger -t "rc.firstboot" "Your partition layout is not currently supported by this tool."
26 logger -t "rc.firstboot" "Your partition layout is not currently supported by this tool."
27 return 0
27 return 0
28 fi
28 fi
29
29
30 # Check if last partition number
30 # Check if last partition number
31 LAST_PART_NUM=$(parted /dev/${ROOT_DEV} -ms unit s p | tail -n 1 | cut -f 1 -d:)
31 LAST_PART_NUM=$(parted /dev/${ROOT_DEV} -ms unit s p | tail -n 1 | cut -f 1 -d:)
32 if [ $LAST_PART_NUM -ne $PART_NUM ]; then
32 if [ $LAST_PART_NUM -ne $PART_NUM ]; then
33 logger -t "rc.firstboot" "$ROOT_PART is not the last partition. Don't know how to expand"
33 logger -t "rc.firstboot" "$ROOT_PART is not the last partition. Don't know how to expand"
34 return 0
34 return 0
35 fi
35 fi
36
36
37 # Get the starting offset of the root partition
37 # Get the starting offset of the root partition
38 PART_START=$(parted /dev/${ROOT_DEV} -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
38 PART_START=$(parted /dev/${ROOT_DEV} -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d: | sed 's/[^0-9]//g')
39 if [ -z "$PART_START" ] ; then
39 if [ -z "$PART_START" ] ; then
40 logger -t "rc.firstboot" "${ROOT_DEV} unable to get starting sector of the partition"
40 logger -t "rc.firstboot" "${ROOT_DEV} unable to get starting sector of the partition"
41 return 1
41 return 1
42 fi
42 fi
43
43
44 # Get the possible last sector for the root partition
44 # Get the possible last sector for the root partition
45 PART_LAST=$(fdisk -l /dev/${ROOT_DEV} | grep '^Disk.*sectors' | awk '{ print $7 - 1 }')
45 PART_LAST=$(fdisk -l /dev/${ROOT_DEV} | grep '^Disk.*sectors' | awk '{ print $7 - 1 }')
46 if [ -z "$PART_LAST" ] ; then
46 if [ -z "$PART_LAST" ] ; then
47 logger -t "rc.firstboot" "${ROOT_DEV} unable to get last sector of the partition"
47 logger -t "rc.firstboot" "${ROOT_DEV} unable to get last sector of the partition"
48 return 1
48 return 1
49 fi
49 fi
50
50
51 ### Since rc.local is run with "sh -e", let's add "|| true" to prevent premature exit
51 ### Since rc.local is run with "sh -e", let's add "|| true" to prevent premature exit
52 fdisk /dev/${ROOT_DEV} <<EOF2 || true
52 fdisk /dev/${ROOT_DEV} <<EOF2 || true
53 p
53 p
54 d
54 d
55 $PART_NUM
55 $PART_NUM
56 n
56 n
57 p
57 p
58 $PART_NUM
58 $PART_NUM
59 $PART_START
59 $PART_START
60 $PART_LAST
60 $PART_LAST
61 p
61 p
62 w
62 w
63 EOF2
63 EOF2
64
64
65 # Reload the partition table, resize root filesystem then remove resizing code from this file
65 # Reload the partition table, resize root filesystem then remove resizing code from this file
66 partprobe &&
66 partprobe &&
67 resize2fs /dev/${ROOT_PART} &&
67 resize2fs /dev/${ROOT_PART} &&
68 logger -t "rc.firstboot" "Root partition successfully resized."
68 logger -t "rc.firstboot" "Root partition successfully resized."
69
70 # Restart dphys-swapfile service if it exists
71 if systemctl list-units | grep -q dphys-swapfile ; then
72 if systemctl is-enabled dphys-swapfile ; then
73 logger -t "rc.firstboot" "Restarting dphys-swapfile"
74 systemctl restart dphys-swapfile
75 fi
76 fi
General Comments 0
Vous devez vous connecter pour laisser un commentaire. Se connecter maintenant