@@ -35,7 +35,9 @@ cd "$(dirname "$0")" || fail
3535
3636BIN=" $( pwd) "
3737ROOTFS_DIR=" $( pwd) /rootfs"
38+ SWAP_IMG=" $( pwd) /swap"
3839ROOTFS_IMG=" $( pwd) /rootfs.img"
40+ SWAP_LOCK=" /tmp/kUaL_lInUx_sWaP_mOuNtEd"
3941ROOTFS_LOCK=" /tmp/kUaL_lInUx_mOuNtEd"
4042INNER_TMP=" /tmp/kUaL_lInUx"
4143ROOTFS_TYPE=unknown
4951 fail " This kernel doesn't support ext4 and ext3."
5052fi
5153
54+ baseus (){
55+ echo " $* " | sed ' s|^/mnt/us/|/mnt/base-us/|'
56+ }
57+
5258copy_etc_files (){
5359 [ -f " $ROOTFS_LOCK " ] || fail " rootfs is not mounted."
5460 cp /etc/hostname /etc/hostname /etc/hosts /etc/resolv.conf " $ROOTFS_DIR /etc"
5561}
5662
63+ mount_swap (){
64+ if [ ! -f " $SWAP_LOCK " ] && [ -f " $SWAP_IMG " ]; then
65+ touch " $SWAP_LOCK " || fail
66+ mkswap " $( baseus " $SWAP_IMG " ) " || fail " cannot mount swap."
67+ swapon " $( baseus " $SWAP_IMG " ) " || fail " cannot mount swap."
68+ fi
69+ }
5770mount_rootfs_base (){
5871 [ -f " $ROOTFS_LOCK " ] && fail " rootfs mounted."
5972 touch " $ROOTFS_LOCK " || fail
@@ -70,20 +83,43 @@ mount_rootfs_all(){
7083 for d in /dev /dev/pts /proc /sys; do
7184 mount -o bind " /$d " " $ROOTFS_DIR /$d " || fail " cannot bind $d "
7285 done
86+ mount_swap
7387}
7488
89+ umount_swap (){
90+ if [ -f " $SWAP_LOCK " ] ; then
91+ swapoff " $( baseus " $SWAP_IMG " ) " || fail " cannot unmount swap."
92+ rm " $SWAP_LOCK " || fail
93+ fi
94+ }
7595umount_rootfs_all (){
7696 [ -f " $ROOTFS_LOCK " ] || fail " rootfs is not mounted."
7797 for d in /dev/pts /dev /proc /sys /tmp; do
7898 umount " $ROOTFS_DIR /$d " 2> /dev/null
7999 done
80100 umount " $ROOTFS_DIR " || fail " cannot unmount rootfs."
81101 rm " $ROOTFS_LOCK " || fail
102+ umount_swap
82103}
83104
105+ remove_swap (){
106+ [ -f " $SWAP_LOCK " ] && umount_swap
107+ rm -f " $SWAP_IMG " || fail
108+ }
109+ make_swap_interactive (){
110+ remove_swap
111+ cp rootfs." $ROOTFS_TYPE " .base " $SWAP_IMG " || fail
112+ echo " Please enter the size of swap file and press Enter (e.g. 1000M):"
113+ local SWAP_SIZE
114+ read SWAP_SIZE || fail " cannot read input."
115+ " $BIN " /resize2fs " $SWAP_IMG " " $SWAP_SIZE " || fail " cannot resize."
116+ mkswap " $SWAP_IMG "
117+ mount_swap
118+ }
84119resize_rootfs_interactive (){
85120 [ -f " $ROOTFS_LOCK " ] && fail " rootfs mounted."
86121 echo " Please enter the rootfs size and press Enter (e.g. 1000M):"
122+ local ROOTFS_SIZE
87123 read ROOTFS_SIZE || fail " cannot read input."
88124 " $BIN " /resize2fs " $ROOTFS_IMG " " $ROOTFS_SIZE " || fail " cannot resize."
89125}
0 commit comments