mirror of
				https://github.com/linuxkit/linuxkit.git
				synced 2025-10-31 05:12:03 +00:00 
			
		
		
		
	Create swap file only if absent
Signed-off-by: Guillaume Rose <guillaume.rose@docker.com>
This commit is contained in:
		| @@ -115,23 +115,27 @@ done | |||||||
| ### Required? exit 1 | ### Required? exit 1 | ||||||
| ### Else? exit 0 | ### Else? exit 0 | ||||||
|  |  | ||||||
|  |  | ||||||
| ## Allocate the file |  | ||||||
| dd if=/dev/zero of=$path bs=1024 count=$(disksize_to_count 1024 $size) |  | ||||||
| chmod 0600 $path |  | ||||||
|  |  | ||||||
| ## was it encrypted? use cryptsetup and get the mapped device |  | ||||||
| if [ "$ENCRYPT" == "true" ]; then | if [ "$ENCRYPT" == "true" ]; then | ||||||
| 	# might need |  | ||||||
| 	#loop=$(losetup -f) |  | ||||||
| 	#losetup ${loop} ${path} |  | ||||||
|  |  | ||||||
| 	cryptsetup open --type plain --key-file /dev/urandom --key-size=256 --cipher=aes-cbc-essiv:sha256 --offset=0  ${path} swapfile |  | ||||||
| 	SWAPDEV=/dev/mapper/swapfile | 	SWAPDEV=/dev/mapper/swapfile | ||||||
| else | else | ||||||
| 	SWAPDEV=$path | 	SWAPDEV=$path | ||||||
| fi | fi | ||||||
|  |  | ||||||
| ## mkswap and swapon the device | if [ ! -f $path ] || ! [ $(stat -c "%s" $path) == $(disksize_to_count 1 $size) ]; then | ||||||
| /sbin/mkswap $SWAPDEV | 	## Allocate the file | ||||||
|  | 	dd if=/dev/zero of=$path bs=1024 count=$(disksize_to_count 1024 $size) | ||||||
|  | 	chmod 0600 $path | ||||||
|  |  | ||||||
|  | 	## was it encrypted? use cryptsetup and get the mapped device | ||||||
|  | 	if [ "$ENCRYPT" == "true" ]; then | ||||||
|  | 		# might need | ||||||
|  | 		#loop=$(losetup -f) | ||||||
|  | 		#losetup ${loop} ${path} | ||||||
|  |  | ||||||
|  | 		cryptsetup open --type plain --key-file /dev/urandom --key-size=256 --cipher=aes-cbc-essiv:sha256 --offset=0  ${path} swapfile | ||||||
|  | 	fi | ||||||
|  |  | ||||||
|  | 	/sbin/mkswap $SWAPDEV | ||||||
|  | fi | ||||||
|  |  | ||||||
| /sbin/swapon $SWAPDEV | /sbin/swapon $SWAPDEV | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user